mbecke 2004/06/24 20:27:40
Modified: httpclient/src/java/org/apache/commons/httpclient Tag:
HTTPCLIENT_2_0_BRANCH ConnectMethod.java
WireLogInputStream.java HttpMethodBase.java
HttpConnection.java WireLogOutputStream.java
Wire.java
Log:
Split wire log into header and body parts.
PR: 29549
Submitted by: Michael Becke
Reviewed by: Oleg Kalnichevski
Revision Changes Path
No revision
No revision
1.18.2.3 +7 -7
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java
Index: ConnectMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java,v
retrieving revision 1.18.2.2
retrieving revision 1.18.2.3
diff -u -r1.18.2.2 -r1.18.2.3
--- ConnectMethod.java 22 Feb 2004 18:21:13 -0000 1.18.2.2
+++ ConnectMethod.java 25 Jun 2004 03:27:40 -0000 1.18.2.3
@@ -39,7 +39,7 @@
/**
* <p>Wraps another method to tunnel through a proxy.</p>
*
- * @author Ortwin Gl�ck
+ * @author Ortwin Gl�ck
* @author dIon Gillard
* @author <a href="mailto:[EMAIL PROTECTED]">Mike Bowler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Oleg Kalnichevski</a>
@@ -230,8 +230,8 @@
buffer.append(" HTTP/1.1");
String line = buffer.toString();
conn.printLine(line);
- if (Wire.enabled()) {
- Wire.output(line);
+ if (Wire.HEADER_WIRE.enabled()) {
+ Wire.HEADER_WIRE.output(line);
}
}
1.12.2.2 +14 -9
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java
Index: WireLogInputStream.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java,v
retrieving revision 1.12.2.1
retrieving revision 1.12.2.2
diff -u -r1.12.2.1 -r1.12.2.2
--- WireLogInputStream.java 22 Feb 2004 18:21:13 -0000 1.12.2.1
+++ WireLogInputStream.java 25 Jun 2004 03:27:40 -0000 1.12.2.2
@@ -38,7 +38,7 @@
/**
* Logs all data read to the wire LOG.
*
- * @author Ortwin Gl�ck
+ * @author Ortwin Gl�ck
* @author <a href="mailto:[EMAIL PROTECTED]">Mike Bowler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Oleg Kalnichevski</a>
*
@@ -48,15 +48,20 @@
class WireLogInputStream extends FilterInputStream {
/** Original input stream. */
- private InputStream in;
+ private InputStream in;
+ /** The wire log to use for writing. */
+ private Wire wire;
+
/**
* Create an instance that wraps the specified input stream.
* @param in The input stream.
+ * @param wire The wire log to use.
*/
- public WireLogInputStream(InputStream in) {
+ public WireLogInputStream(InputStream in, Wire wire) {
super(in);
this.in = in;
+ this.wire = wire;
}
/**
*
@@ -65,7 +70,7 @@
public int read(byte[] b, int off, int len) throws IOException {
int l = this.in.read(b, off, len);
if (l > 0) {
- Wire.input(b, off, l);
+ wire.input(b, off, l);
}
return l;
}
@@ -77,7 +82,7 @@
public int read() throws IOException {
int l = this.in.read();
if (l > 0) {
- Wire.input(l);
+ wire.input(l);
}
return l;
}
@@ -89,7 +94,7 @@
public int read(byte[] b) throws IOException {
int l = this.in.read(b);
if (l > 0) {
- Wire.input(b, 0, l);
+ wire.input(b, 0, l);
}
return l;
}
1.159.2.29 +18 -18
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
Index: HttpMethodBase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.159.2.28
retrieving revision 1.159.2.29
diff -u -r1.159.2.28 -r1.159.2.29
--- HttpMethodBase.java 13 Jun 2004 20:24:48 -0000 1.159.2.28
+++ HttpMethodBase.java 25 Jun 2004 03:27:40 -0000 1.159.2.29
@@ -2012,8 +2012,8 @@
responseBody = null; // is this desired?
InputStream is = conn.getResponseInputStream();
- if (Wire.traceEnabled()) {
- is = new WireLogInputStream(is);
+ if (Wire.CONTENT_WIRE.enabled()) {
+ is = new WireLogInputStream(is, Wire.CONTENT_WIRE);
}
InputStream result = null;
Header transferEncodingHeader =
responseHeaders.getFirstHeader("Transfer-Encoding");
@@ -2125,9 +2125,9 @@
getResponseHeaderGroup().clear();
Header[] headers = HttpParser.parseHeaders(conn.getResponseInputStream());
- if (Wire.enabled()) {
+ if (Wire.HEADER_WIRE.enabled()) {
for (int i = 0; i < headers.length; i++) {
- Wire.input(headers[i].toExternalForm());
+ Wire.HEADER_WIRE.input(headers[i].toExternalForm());
}
}
getResponseHeaderGroup().setHeaders(headers);
@@ -2162,8 +2162,8 @@
//read out the HTTP status string
String s = conn.readLine();
while ((s != null) && !StatusLine.startsWithHTTP(s)) {
- if (Wire.enabled()) {
- Wire.input(s + "\r\n");
+ if (Wire.HEADER_WIRE.enabled()) {
+ Wire.HEADER_WIRE.input(s + "\r\n");
}
s = conn.readLine();
}
@@ -2174,8 +2174,8 @@
+ " line from the response: unable to find line starting with"
+ " \"HTTP\"");
}
- if (Wire.enabled()) {
- Wire.input(s + "\r\n");
+ if (Wire.HEADER_WIRE.enabled()) {
+ Wire.HEADER_WIRE.input(s + "\r\n");
}
//create the status line from the status string
statusLine = new StatusLine(s);
@@ -2250,8 +2250,8 @@
conn.writeLine(); // close head
// make sure the status line and headers have been sent
conn.flushRequestOutputStream();
- if (Wire.enabled()) {
- Wire.output("\r\n");
+ if (Wire.HEADER_WIRE.enabled()) {
+ Wire.HEADER_WIRE.output("\r\n");
}
Header expectheader = getRequestHeader("Expect");
@@ -2364,8 +2364,8 @@
Header[] headers = getRequestHeaders();
for (int i = 0; i < headers.length; i++) {
String s = headers[i].toExternalForm();
- if (Wire.enabled()) {
- Wire.output(s);
+ if (Wire.HEADER_WIRE.enabled()) {
+ Wire.HEADER_WIRE.output(s);
}
conn.print(s);
}
@@ -2396,8 +2396,8 @@
LOG.trace(
"enter HttpMethodBase.writeRequestLine(HttpState, HttpConnection)");
String requestLine = getRequestLine(conn);
- if (Wire.enabled()) {
- Wire.output(requestLine);
+ if (Wire.HEADER_WIRE.enabled()) {
+ Wire.HEADER_WIRE.output(requestLine);
}
conn.print(requestLine);
}
1.67.2.11 +6 -6
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
Index: HttpConnection.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
retrieving revision 1.67.2.10
retrieving revision 1.67.2.11
diff -u -r1.67.2.10 -r1.67.2.11
--- HttpConnection.java 1 Jun 2004 00:52:12 -0000 1.67.2.10
+++ HttpConnection.java 25 Jun 2004 03:27:40 -0000 1.67.2.11
@@ -779,8 +779,8 @@
LOG.trace("enter HttpConnection.getRequestOutputStream()");
assertOpen();
OutputStream out = this.outputStream;
- if (Wire.traceEnabled()) {
- out = new WireLogOutputStream(out);
+ if (Wire.CONTENT_WIRE.enabled()) {
+ out = new WireLogOutputStream(out, Wire.CONTENT_WIRE);
}
return out;
}
1.4.2.2 +13 -8
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogOutputStream.java
Index: WireLogOutputStream.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogOutputStream.java,v
retrieving revision 1.4.2.1
retrieving revision 1.4.2.2
diff -u -r1.4.2.1 -r1.4.2.2
--- WireLogOutputStream.java 22 Feb 2004 18:21:13 -0000 1.4.2.1
+++ WireLogOutputStream.java 25 Jun 2004 03:27:40 -0000 1.4.2.2
@@ -46,15 +46,20 @@
class WireLogOutputStream extends FilterOutputStream {
/** Original input stream. */
- private OutputStream out;
+ private OutputStream out;
+
+ /** The wire log to use. */
+ private Wire wire;
/**
* Create an instance that wraps the specified output stream.
* @param out The output stream.
+ * @param wire The Wire log to use.
*/
- public WireLogOutputStream(OutputStream out) {
+ public WireLogOutputStream(OutputStream out, Wire wire) {
super(out);
this.out = out;
+ this.wire = wire;
}
/**
@@ -63,7 +68,7 @@
*/
public void write(byte[] b, int off, int len) throws IOException {
this.out.write(b, off, len);
- Wire.output(b, off, len);
+ wire.output(b, off, len);
}
/**
@@ -72,7 +77,7 @@
*/
public void write(int b) throws IOException {
this.out.write(b);
- Wire.output(b);
+ wire.output(b);
}
/**
@@ -81,6 +86,6 @@
*/
public void write(byte[] b) throws IOException {
this.out.write(b);
- Wire.output(b);
+ wire.output(b);
}
}
1.4.2.4 +27 -24
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Wire.java
Index: Wire.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Wire.java,v
retrieving revision 1.4.2.3
retrieving revision 1.4.2.4
diff -u -r1.4.2.3 -r1.4.2.4
--- Wire.java 13 Apr 2004 18:24:04 -0000 1.4.2.3
+++ Wire.java 25 Jun 2004 03:27:40 -0000 1.4.2.4
@@ -47,10 +47,17 @@
class Wire {
- /** Log for any wire messages. */
- private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire");
+ public static Wire HEADER_WIRE = new
Wire(LogFactory.getLog("httpclient.wire.header"));
- private static void wire(String header, InputStream instream)
+ public static Wire CONTENT_WIRE = new
Wire(LogFactory.getLog("httpclient.wire.content"));
+
+ private Log log;
+
+ private Wire(Log log) {
+ this.log = log;
+ }
+
+ private void wire(String header, InputStream instream)
throws IOException {
StringBuffer buffer = new StringBuffer();
int ch;
@@ -61,7 +68,7 @@
buffer.append("[\\n]\"");
buffer.insert(0, "\"");
buffer.insert(0, header);
- WIRE_LOG.debug(buffer.toString());
+ log.debug(buffer.toString());
buffer.setLength(0);
} else if ((ch < 32) || (ch > 127)) {
buffer.append("[0x");
@@ -75,20 +82,16 @@
buffer.append("\"");
buffer.insert(0, "\"");
buffer.insert(0, header);
- WIRE_LOG.debug(buffer.toString());
+ log.debug(buffer.toString());
}
}
- public static final boolean enabled() {
- return WIRE_LOG.isDebugEnabled();
- }
-
- public static final boolean traceEnabled() {
- return WIRE_LOG.isTraceEnabled();
+ public boolean enabled() {
+ return log.isDebugEnabled();
}
- public static final void output(InputStream outstream)
+ public void output(InputStream outstream)
throws IOException {
if (outstream == null) {
throw new IllegalArgumentException("Output may not be null");
@@ -96,7 +99,7 @@
wire(">> ", outstream);
}
- public static final void input(InputStream instream)
+ public void input(InputStream instream)
throws IOException {
if (instream == null) {
throw new IllegalArgumentException("Input may not be null");
@@ -104,7 +107,7 @@
wire("<< ", instream);
}
- public static final void output(byte[] b, int off, int len)
+ public void output(byte[] b, int off, int len)
throws IOException {
if (b == null) {
throw new IllegalArgumentException("Output may not be null");
@@ -112,7 +115,7 @@
wire(">> ", new ByteArrayInputStream(b, off, len));
}
- public static final void input(byte[] b, int off, int len)
+ public void input(byte[] b, int off, int len)
throws IOException {
if (b == null) {
throw new IllegalArgumentException("Input may not be null");
@@ -120,7 +123,7 @@
wire("<< ", new ByteArrayInputStream(b, off, len));
}
- public static final void output(byte[] b)
+ public void output(byte[] b)
throws IOException {
if (b == null) {
throw new IllegalArgumentException("Output may not be null");
@@ -128,7 +131,7 @@
wire(">> ", new ByteArrayInputStream(b));
}
- public static final void input(byte[] b)
+ public void input(byte[] b)
throws IOException {
if (b == null) {
throw new IllegalArgumentException("Input may not be null");
@@ -136,17 +139,17 @@
wire("<< ", new ByteArrayInputStream(b));
}
- public static final void output(int b)
+ public void output(int b)
throws IOException {
output(new byte[] {(byte) b});
}
- public static final void input(int b)
+ public void input(int b)
throws IOException {
input(new byte[] {(byte) b});
}
- public static final void output(final String s)
+ public void output(final String s)
throws IOException {
if (s == null) {
throw new IllegalArgumentException("Output may not be null");
@@ -154,7 +157,7 @@
output(s.getBytes());
}
- public static final void input(final String s)
+ public void input(final String s)
throws IOException {
if (s == null) {
throw new IllegalArgumentException("Input may not be null");
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]