You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Geir H. Pettersen" <ge...@cellus.no> on 2004/03/31 10:57:06 UTC
The httpclient.wire log.
Hi,
I have been using the commons httpclient successfully since rc1. Great work
guys! This is the best client that I ever have used in java.
The httpclient.wire log is fantastic, but there is something there that
bothers me a bit. Before the characters are written to log, they are decoded
with "US-ASCII" (or the default character set if that fails).
The problem with this is if you try to debug http traces with special
character you will actually lose information on what is actually sent.
My example is: I am having some encoding problems with my client, and I want
to check exactly what bytes I am sending. I am sending the three Norwegian
characters (1)� (2)� and (3)�. (ae together, o with a slash and a with a
ring over).
(1) is encoded in UTF-8 as 0xc3 0xa6
(2) is encoded in UTF-8 as 0xc3 0xb8
(3) is encodes in UTF-8 as 0xc3 0xa5
The problem is when I try to POST these three characters. It is logged as:
"[0xfffd][0xfffd][0xfffd][0xfffd][0xfffd][0xfffd]" (but actually that is not
what is sent)
I want the log to be: "[0xc3][0xa6][0xc3][0xb8][0xc3][0xa5]"
A fix for this would be to remove the encoded reader from: Wire.java :
-----------------
�
// Reader reader = null;
// try {
// reader = new InputStreamReader(instream, "US-ASCII");
// } catch (UnsupportedEncodingException e) {
// reader = new InputStreamReader(instream);
// }
StringBuffer buffer = new StringBuffer();
int ch;
// while ((ch = reader.read()) != -1) {
while ((ch = instream.read()) != -1) {
�
-----------------
Notice that the method now no longer throws an IOException.
Attached is my suggested changes in Wire.java. I did not remove the "throws
IOException" from the method signature, since this may have other
consequences.
Regards,
Geir H. Pettersen
Cellus/Masp Technology AS
RE: The httpclient.wire log.
Posted by "Geir H. Pettersen" <ge...@cellus.no>.
Hi again.
> >
> > I want the log to be: "[0xc3][0xa6][0xc3][0xb8][0xc3][0xa5]"
> I think, just using the default platform encoding is as bad as using
> US-ASCII because it does not reflect was is *really* sent over the wire.
If you look closely, you will see that this is _not:_ the default character
encoding. This actually what *really* is sent over the wire.
Of course I can see the advantage of a full hex dump, but this would more be
an addition to the functionality, but my fix would be more like a bug-fix.
To demonstrate I have made a small code snipplet derived from the Wire.java.
This code should be runnable and print out the log: :
--------------
public class EncodingTest {
public static void main(String[] args) throws IOException {
// Setup:
byte[] b = new byte[]{(byte) 0xc3, (byte) 0xa6, (byte) 0xc3, (byte)
0xb8,
(byte) 0xc3, (byte) 0xa5};
ByteArrayInputStream instream = new ByteArrayInputStream(b);
//------
// ------ Old code: -------
// Reader reader = null;
// try {
// reader = new InputStreamReader(instream, "US-ASCII");
// } catch (UnsupportedEncodingException e) {
// reader = new InputStreamReader(instream);
// }
// ------------------------
StringBuffer buffer = new StringBuffer();
int ch;
// ------ Old code: -------
// while ((ch = reader.read()) != -1) {
// ------ Old code: -------
// ------ New code: -------
while ((ch = instream.read()) != -1) {
// ------------------------
if (ch == 13) {
buffer.append("[\\r]");
} else if (ch == 10) {
buffer.append("[\\n]\"");
buffer.insert(0, "\"");
System.out.println(buffer.toString());
buffer.setLength(0);
} else if ((ch < 32) || (ch > 127)) {
buffer.append("[0x");
buffer.append(Integer.toHexString(ch));
buffer.append("]");
} else {
buffer.append((char) ch);
}
}
if (buffer.length() > 0) {
buffer.append("\"");
buffer.insert(0, "\"");
System.out.println(buffer.toString());
}
}
}
-----Original Message-----
From: Ortwin Glück [mailto:ortwin.glueck@nose.ch]
Sent: 31. mars 2004 11:14
To: Commons HttpClient Project
Subject: Re: The httpclient.wire log.
Geir H. Pettersen wrote:
> Hi,
>
> I have been using the commons httpclient successfully since rc1. Great
work
> guys! This is the best client that I ever have used in java.
Thanks for the flowers, Geir!
> The httpclient.wire log is fantastic, but there is something there that
> bothers me a bit. Before the characters are written to log, they are
decoded
> with "US-ASCII" (or the default character set if that fails).
>
> The problem with this is if you try to debug http traces with special
> character you will actually lose information on what is actually sent.
>
> My example is: I am having some encoding problems with my client, and I
want
> to check exactly what bytes I am sending. I am sending the three Norwegian
> characters (1)æ (2)ø and (3)å. (ae together, o with a slash and a with a
> ring over).
>
> (1) is encoded in UTF-8 as 0xc3 0xa6
> (2) is encoded in UTF-8 as 0xc3 0xb8
> (3) is encodes in UTF-8 as 0xc3 0xa5
>
> The problem is when I try to POST these three characters. It is logged as:
> "[0xfffd][0xfffd][0xfffd][0xfffd][0xfffd][0xfffd]" (but actually that is
not
> what is sent)
>
> I want the log to be: "[0xc3][0xa6][0xc3][0xb8][0xc3][0xa5]"
I think, just using the default platform encoding is as bad as using
US-ASCII because it does not reflect was is *really* sent over the wire.
Actually the wirelog should ideally provide all bytes in hexadecimal
representation along with their supposed interpretation as characters in
some encoding (such as default platform encoding). A presentation
similar to hexdumps would me nice IMHO. However this might imply a small
buffering (16 bytes per line) to make a nice layout.
Sample output (hex values do not match text):
DE AD BE EF DE AD BE EF DE AD BE EF DE AD BE EF GET /index.htm H
DE AD BE EF DE AD BE EF DE AD BE EF DE AD BE EF TTP/1.1..Host:ww
---------------------------------------------------------------------
To unsubscribe, e-mail:
commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail:
commons-httpclient-dev-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: The httpclient.wire log.
Posted by Ortwin Glück <or...@nose.ch>.
Geir H. Pettersen wrote:
> Hi,
>
> I have been using the commons httpclient successfully since rc1. Great work
> guys! This is the best client that I ever have used in java.
Thanks for the flowers, Geir!
> The httpclient.wire log is fantastic, but there is something there that
> bothers me a bit. Before the characters are written to log, they are decoded
> with "US-ASCII" (or the default character set if that fails).
>
> The problem with this is if you try to debug http traces with special
> character you will actually lose information on what is actually sent.
>
> My example is: I am having some encoding problems with my client, and I want
> to check exactly what bytes I am sending. I am sending the three Norwegian
> characters (1)æ (2)ø and (3)å. (ae together, o with a slash and a with a
> ring over).
>
> (1) is encoded in UTF-8 as 0xc3 0xa6
> (2) is encoded in UTF-8 as 0xc3 0xb8
> (3) is encodes in UTF-8 as 0xc3 0xa5
>
> The problem is when I try to POST these three characters. It is logged as:
> "[0xfffd][0xfffd][0xfffd][0xfffd][0xfffd][0xfffd]" (but actually that is not
> what is sent)
>
> I want the log to be: "[0xc3][0xa6][0xc3][0xb8][0xc3][0xa5]"
I think, just using the default platform encoding is as bad as using
US-ASCII because it does not reflect was is *really* sent over the wire.
Actually the wirelog should ideally provide all bytes in hexadecimal
representation along with their supposed interpretation as characters in
some encoding (such as default platform encoding). A presentation
similar to hexdumps would me nice IMHO. However this might imply a small
buffering (16 bytes per line) to make a nice layout.
Sample output (hex values do not match text):
DE AD BE EF DE AD BE EF DE AD BE EF DE AD BE EF GET /index.htm H
DE AD BE EF DE AD BE EF DE AD BE EF DE AD BE EF TTP/1.1..Host:ww
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org