hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r526466 - in /jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn: DefaultClientConnection.java Wire.java
Date Sat, 07 Apr 2007 18:16:02 GMT
Author: olegk
Date: Sat Apr  7 11:16:01 2007
New Revision: 526466

URL: http://svn.apache.org/viewvc?view=rev&rev=526466
Log:
Added HTTP headers log

Modified:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/DefaultClientConnection.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/Wire.java

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/DefaultClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/DefaultClientConnection.java?view=diff&rev=526466&r1=526465&r2=526466
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/DefaultClientConnection.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/DefaultClientConnection.java
Sat Apr  7 11:16:01 2007
@@ -35,7 +35,13 @@
 import java.io.IOException;
 import java.net.Socket;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.Header;
+import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
 import org.apache.http.params.HttpParams;
 import org.apache.http.impl.SocketHttpClientConnection;
 import org.apache.http.io.HttpDataReceiver;
@@ -58,6 +64,9 @@
 public class DefaultClientConnection extends SocketHttpClientConnection
     implements OperatedClientConnection {
 
+    private static final Log HEADERS_LOG = LogFactory.getLog("org.apache.http.conn.headers");
+    private static final Log WIRE_LOG = LogFactory.getLog("org.apache.http.conn.wire");
+    
     /** The unconnected socket between announce and open. */
     private volatile Socket announcedSocket;
 
@@ -122,8 +131,8 @@
     protected HttpDataReceiver createHttpDataReceiver(
             final HttpParams params) throws IOException {
         HttpDataReceiver receiver = super.createHttpDataReceiver(params);
-        if (Wire.WIRE_LOG.enabled()) {
-            receiver = new LoggingHttpDataReceiverDecorator(receiver, Wire.WIRE_LOG);
+        if (WIRE_LOG.isDebugEnabled()) {
+            receiver = new LoggingHttpDataReceiverDecorator(receiver, new Wire(WIRE_LOG));
         }
         return receiver;
     }
@@ -132,8 +141,8 @@
     protected HttpDataTransmitter createHttpDataTransmitter(
             final HttpParams params) throws IOException {
         HttpDataTransmitter transmitter = super.createHttpDataTransmitter(params);
-        if (Wire.WIRE_LOG.enabled()) {
-            transmitter = new LoggingHttpDataTransmitterDecorator(transmitter, Wire.WIRE_LOG);
+        if (WIRE_LOG.isDebugEnabled()) {
+            transmitter = new LoggingHttpDataTransmitterDecorator(transmitter, new Wire(WIRE_LOG));
         }
         return transmitter;
     }
@@ -190,5 +199,30 @@
 
     } // update
 
+
+    public HttpResponse receiveResponseHeader(
+            final HttpParams params) throws HttpException, IOException {
+        HttpResponse response = super.receiveResponseHeader(params);
+        if (HEADERS_LOG.isDebugEnabled()) {
+            HEADERS_LOG.debug(">> " + response.getStatusLine().toString());
+            Header[] headers = response.getAllHeaders();
+            for (int i = 0; i < headers.length; i++) {
+                HEADERS_LOG.debug(">> " + headers[i].toString());
+            }
+        }
+        return response;
+    }
+
+
+    public void sendRequestHeader(HttpRequest request) throws HttpException, IOException
{
+        super.sendRequestHeader(request);
+        if (HEADERS_LOG.isDebugEnabled()) {
+            HEADERS_LOG.debug("<< " + request.getRequestLine().toString());
+            Header[] headers = request.getAllHeaders();
+            for (int i = 0; i < headers.length; i++) {
+                HEADERS_LOG.debug("<< " + headers[i].toString());
+            }
+        }
+    }
 
 } // class DefaultClientConnection

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/Wire.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/Wire.java?view=diff&rev=526466&r1=526465&r2=526466
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/Wire.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/Wire.java Sat
Apr  7 11:16:01 2007
@@ -34,7 +34,6 @@
 import java.io.InputStream;
 import java.io.ByteArrayInputStream;
 import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * Logs data to the wire LOG.
@@ -45,12 +44,9 @@
  */
 class Wire {
 
-    public static Wire WIRE_LOG = new Wire(LogFactory.getLog("org.apache.http.wire"));
-    
-    /** Log for any wire messages. */
     private Log log;
     
-    private Wire(Log log) {
+    public Wire(Log log) {
         this.log = log;
     }
     



Mime
View raw message