rwaldhoff 01/08/02 15:08:31
Modified: httpclient/src/java/org/apache/commons/httpclient
HttpClient.java
httpclient/src/conf log4j.properties.sample
simplelog.properties.sample
httpclient/src/java/org/apache/commons/httpclient/methods
PutMethod.java
Log:
added a new log category - httpclient.wire - that echos all of the httpclient
network communication
Revision Changes Path
1.23 +22 -19
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java
Index: HttpClient.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- HttpClient.java 2001/08/02 16:27:06 1.22
+++ HttpClient.java 2001/08/02 22:08:31 1.23
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
1.22 2001/08/02 16:27:06 rwaldhoff Exp $
- * $Revision: 1.22 $
- * $Date: 2001/08/02 16:27:06 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
1.23 2001/08/02 22:08:31 rwaldhoff Exp $
+ * $Revision: 1.23 $
+ * $Date: 2001/08/02 22:08:31 $
*
* ====================================================================
*
@@ -105,6 +105,7 @@
// -------------------------------------------------------------- Constants
static private final Log log =
LogSource.getInstance("org.apache.commons.httpclient.HttpClient");
+ static private final Log wireLog = LogSource.getInstance("httpclient.wire");
/**
* HTTP Date format pattern (RFC 2068, 822, 1123).
@@ -877,7 +878,7 @@
Enumeration headersList = method.getHeaders();
// Sending request line
- log.debug(requestLine);
+ wireLog.info(">> \"" + requestLine + "\"");
output.write(requestLine.getBytes());
// Sending headers
@@ -888,16 +889,16 @@
queryStr = new String();
query = queryStr.getBytes("UTF8");
if (method.needContentLength()) {
- log.debug("Content-Length: "
- + query.length + "\r\n");
- output.write(("Content-Length: "
- + query.length + "\r\n").getBytes());
+ String contentLengthHeader = "Content-Length: " + query.length +
"\r\n";
+ wireLog.info(">> \"" + contentLengthHeader + "\"");
+ output.write(contentLengthHeader.getBytes());
}
} else {
// Chunking
if ((http11) && (method.getHeader("Content-Length") == null)) {
- log.debug("Transfer-Encoding: chunked\r\n");
- output.write(("Transfer-Encoding: chunked\r\n").getBytes());
+ String transferEncodingHeader = "Transfer-Encoding: chunked\r\n";
+ wireLog.info(">> \"" + transferEncodingHeader + "\"");
+ output.write(transferEncodingHeader.getBytes());
}
}
@@ -906,10 +907,9 @@
String challengeResponse = Authenticator.challengeResponse
(state, credentials);
if (challengeResponse != null) {
- log.debug("Authorization: "
- + challengeResponse + "\r\n");
- output.write(("Authorization: "
- + challengeResponse + "\r\n").getBytes());
+ String authorizationHeader = "Authorization: " + challengeResponse
+ "\r\n";
+ wireLog.info(">> \"" + authorizationHeader + "\"");
+ output.write(authorizationHeader.getBytes());
if (connectionInterceptor != null) {
connectionInterceptor.authenticate();
}
@@ -919,28 +919,30 @@
// Send expectation header
if (method.needExpectation()) {
- output.write(("Expect: 100-continue\r\n").getBytes());
+ String expectHeader = "Expect: 100-continue\r\n";
+ wireLog.info(">> \"" + expectHeader + "\"");
+ output.write(expectHeader.getBytes());
}
// Writing HTTP headers
while (headersList.hasMoreElements()) {
Header header = (Header) headersList.nextElement();
- log.debug(header.toString());
+ wireLog.info(">> \"" + header.toString() + "\"");
output.write(header.toString().getBytes());
}
+ wireLog.info(">> \\r\\n (closing head)");
output.write("\r\n".getBytes());
return query;
-
}
/**
- * Send a WebDAV request.
+ * Send a request.
*
- * @param method WebDAV method to execute
+ * @param method method to execute
*/
protected void sendRequestBody(HttpMethod method, byte[] query)
throws IOException, HttpException {
@@ -996,6 +998,7 @@
}
sb.append((char) ch);
}
+ wireLog.info("<< \"" + sb.toString() + "\"");
return (sb.toString());
}
1.3 +4 -0 jakarta-commons/httpclient/src/conf/log4j.properties.sample
Index: log4j.properties.sample
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/conf/log4j.properties.sample,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- log4j.properties.sample 2001/08/02 16:27:06 1.2
+++ log4j.properties.sample 2001/08/02 22:08:31 1.3
@@ -8,6 +8,10 @@
#log4j.category.org.apache.commons.httpclient.HeaderElement=DEBUG
#log4j.category.org.apache.commons.httpclient.HttpClient=DEBUG
+# the httpclient.wire category provides a trace of all of
+# httpclient's network communictation
+#log4j.category.httpclient.wire=INFO
+
# Create an appender that prints to the console
log4j.appender.consoleAppender=org.apache.log4j.FileAppender
log4j.appender.consoleAppender.File=System.out
1.2 +5 -0 jakarta-commons/httpclient/src/conf/simplelog.properties.sample
Index: simplelog.properties.sample
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/conf/simplelog.properties.sample,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- simplelog.properties.sample 2001/08/02 16:27:06 1.1
+++ simplelog.properties.sample 2001/08/02 22:08:31 1.2
@@ -28,3 +28,8 @@
#httpclient.simplelog.log.org.apache.commons.httpclient.HttpClient=DEBUG
#httpclient.simplelog.log.org.apache.commons.httpclient.HeaderElement=DEBUG
#httpclient.simplelog.log.org.apache.commons.httpclient.Base64=DEBUG
+
+# the httpclient.wire category provides a trace of all of
+# httpclient's network communictation
+#httpclient.simplelog.log.httpclient.wire=INFO
+
1.2 +52 -48
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java
Index: PutMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PutMethod.java 2001/04/25 18:42:52 1.1
+++ PutMethod.java 2001/08/02 22:08:31 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v
1.1 2001/04/25 18:42:52 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/25 18:42:52 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v
1.2 2001/08/02 22:08:31 rwaldhoff Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/08/02 22:08:31 $
*
* ====================================================================
*
@@ -60,7 +60,7 @@
* [Additional notices, if required by prior licensing conditions]
*
*/
-
+
package org.apache.commons.httpclient.methods;
import java.io.IOException;
@@ -75,6 +75,8 @@
import org.apache.commons.httpclient.State;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.log.Log;
+import org.apache.commons.httpclient.log.LogSource;
/**
@@ -84,19 +86,19 @@
*/
public class PutMethod
extends HttpMethodBase {
-
-
+
+
// ----------------------------------------------------------- Constructors
-
-
+
+
/**
* Method constructor.
*/
public PutMethod() {
name = "PUT";
}
-
-
+
+
/**
* Method constructor.
*/
@@ -104,32 +106,32 @@
super(path);
name = "PUT";
}
-
-
+
+
// ------------------------------------------------------- Instance Methods
-
-
+
+
/**
* Send byte buffer.
*/
private byte[] data = null;
-
-
+
+
/**
* Send file contents.
*/
private File file = null;
-
-
+
+
/**
* Set content from URL.
*/
private URL url = null;
-
-
+
+
// --------------------------------------------------------- Public Methods
-
-
+
+
/**
* Send the contents of a file.
*/
@@ -138,8 +140,8 @@
checkNotUsed();
this.file = file;
}
-
-
+
+
/**
* Send the contents of the resource at the specified URL.
*/
@@ -148,8 +150,8 @@
checkNotUsed();
this.url = url;
}
-
-
+
+
/**
* Send the contents of a byte array.
*/
@@ -157,8 +159,8 @@
checkNotUsed();
this.data = data;
}
-
-
+
+
/**
* Send the contents of a string.
*/
@@ -166,8 +168,8 @@
checkNotUsed();
sendData(data.getBytes());
}
-
-
+
+
/**
* Send the contents of an input stream. The contents will be buffered into
* memory. To upload large entities, it is recommended to first buffer the
@@ -187,11 +189,11 @@
}
data = os.toByteArray();
}
-
-
+
+
// ----------------------------------------------------- HttpMethod Methods
-
-
+
+
/**
* Is the query body submitted through an InputStream of with a String.
* If an InputStream is available, it's used.
@@ -201,8 +203,8 @@
public boolean isStreamedQuery() {
return ((file != null) || (url != null));
}
-
-
+
+
/**
* Recycle the method object, so that it can be reused again. Any attempt
* to reuse an object without recycling it will throw a WebdavException.
@@ -213,8 +215,8 @@
url = null;
file = null;
}
-
-
+
+
/**
* Generate the query body.
*
@@ -230,36 +232,37 @@
return new String(data);
}
}
-
-
+
+
/**
* Stream the body of the query. This function should be used to send large
* request bodies.
*/
public void streamQuery(OutputStream out)
throws IOException {
-
+
InputStream inputStream = null;
if (file != null) {
inputStream = new FileInputStream(file);
} else if (url != null) {
inputStream = url.openConnection().getInputStream();
}
-
+
byte[] buffer = new byte[4096];
int nb = 0;
while (true) {
nb = inputStream.read(buffer);
if (nb == -1)
break;
+ wireLog.info(">> \"" + new String(buffer) + "\"");
out.write(buffer, 0, nb);
}
-
+
inputStream.close();
-
+
}
-
-
+
+
/**
* Parse response.
*
@@ -268,11 +271,11 @@
public void parseResponse(InputStream is)
throws IOException {
}
-
-
+
+
/**
* Return true if the method should ask for an expectation.
- *
+ *
* @return true if an expectation will be sent
*/
public boolean needExpectation() {
@@ -280,4 +283,5 @@
}
+ static protected final Log wireLog = LogSource.getInstance("httpclient.wire");
}