hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1242390 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio: client/LoggingAsyncRequestExecutor.java conn/DefaultAsyncClientConnection.java
Date Thu, 09 Feb 2012 16:43:35 GMT
Author: olegk
Date: Thu Feb  9 16:43:35 2012
New Revision: 1242390

URL: http://svn.apache.org/viewvc?rev=1242390&view=rev
Log:
Intermediate fix for header logging issue (message parser and formatter no longer get overridden)

Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/DefaultAsyncClientConnection.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java?rev=1242390&r1=1242389&r2=1242390&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
Thu Feb  9 16:43:35 2012
@@ -31,7 +31,10 @@ import java.io.IOException;
 
 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.HttpResponse;
+import org.apache.http.impl.nio.conn.DefaultAsyncClientConnection;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.NHttpClientConnection;
@@ -39,6 +42,7 @@ import org.apache.http.nio.protocol.Http
 
 class LoggingAsyncRequestExecutor extends HttpAsyncRequestExecutor {
 
+    private final Log headerlog = LogFactory.getLog("org.apache.http.headers");
     private final Log log = LogFactory.getLog(HttpAsyncRequestExecutor.class);
 
     public LoggingAsyncRequestExecutor() {
@@ -111,6 +115,26 @@ class LoggingAsyncRequestExecutor extend
         if (this.log.isDebugEnabled()) {
             this.log.debug(conn + " Response received");
         }
+        
+        // TODO: move header logging back to DefaultAsyncClientConnection
+        // once DefaultNHttpClientConnection#onResponseReceived method
+        // becomes available.
+        if (this.headerlog.isDebugEnabled()) {
+            HttpResponse response = conn.getHttpResponse();
+            String id;
+            if (conn instanceof DefaultAsyncClientConnection) {
+                id = ((DefaultAsyncClientConnection) conn).getId();
+            } else {
+                id = conn.toString();
+            }
+            if (response != null && this.headerlog.isDebugEnabled()) {
+                this.headerlog.debug(id + " << " + response.getStatusLine().toString());
+                Header[] headers = response.getAllHeaders();
+                for (int i = 0; i < headers.length; i++) {
+                    this.headerlog.debug(id + " << " + headers[i].toString());
+                }
+            }
+        }
         super.responseReceived(conn);
     }
 

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/DefaultAsyncClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/DefaultAsyncClientConnection.java?rev=1242390&r1=1242389&r2=1242390&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/DefaultAsyncClientConnection.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/DefaultAsyncClientConnection.java
Thu Feb  9 16:43:35 2012
@@ -27,22 +27,16 @@
 package org.apache.http.impl.nio.conn;
 
 import java.io.IOException;
-import java.nio.channels.ReadableByteChannel;
 
 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.HttpRequest;
-import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseFactory;
 import org.apache.http.impl.nio.DefaultNHttpClientConnection;
-import org.apache.http.nio.NHttpMessageParser;
-import org.apache.http.nio.NHttpMessageWriter;
 import org.apache.http.nio.conn.OperatedAsyncClientConnection;
 import org.apache.http.nio.reactor.IOSession;
-import org.apache.http.nio.reactor.SessionInputBuffer;
-import org.apache.http.nio.reactor.SessionOutputBuffer;
 import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
@@ -85,21 +79,20 @@ public class DefaultAsyncClientConnectio
         return this.original;
     }
 
-    @Override
-    protected NHttpMessageWriter<HttpRequest> createRequestWriter(
-            final SessionOutputBuffer buffer,
-            final HttpParams params) {
-        return new LoggingNHttpMessageWriter(
-                super.createRequestWriter(buffer, params));
+    public String getId() {
+        return this.id;
     }
-
+    
     @Override
-    protected NHttpMessageParser<HttpResponse> createResponseParser(
-            final SessionInputBuffer buffer,
-            final HttpResponseFactory responseFactory,
-            final HttpParams params) {
-        return new LoggingNHttpMessageParser(
-                super.createResponseParser(buffer, responseFactory, params));
+    public void submitRequest(final HttpRequest request) throws IOException, HttpException
{
+        if (request != null && this.headerlog.isDebugEnabled()) {
+            this.headerlog.debug(this.id + " >> " + request.getRequestLine().toString());
+            Header[] headers = request.getAllHeaders();
+            for (int i = 0; i < headers.length; i++) {
+                this.headerlog.debug(this.id + " >> " + headers[i].toString());
+            }
+        }
+        super.submitRequest(request);
     }
 
     @Override
@@ -122,63 +115,4 @@ public class DefaultAsyncClientConnectio
         return buf.toString();
     }
 
-    class LoggingNHttpMessageWriter implements NHttpMessageWriter<HttpRequest> {
-
-        private final NHttpMessageWriter<HttpRequest> writer;
-
-        public LoggingNHttpMessageWriter(final NHttpMessageWriter<HttpRequest> writer)
{
-            super();
-            this.writer = writer;
-        }
-
-        public void reset() {
-            this.writer.reset();
-        }
-
-        public void write(final HttpRequest request) throws IOException, HttpException {
-            if (request != null && headerlog.isDebugEnabled()) {
-                headerlog.debug(id + " >> " + request.getRequestLine().toString());
-                Header[] headers = request.getAllHeaders();
-                for (int i = 0; i < headers.length; i++) {
-                    headerlog.debug(id + " >> " + headers[i].toString());
-                }
-            }
-            this.writer.write(request);
-        }
-
-    }
-
-    class LoggingNHttpMessageParser implements NHttpMessageParser<HttpResponse> {
-
-        private final NHttpMessageParser<HttpResponse> parser;
-
-        public LoggingNHttpMessageParser(final NHttpMessageParser<HttpResponse> parser)
{
-            super();
-            this.parser = parser;
-        }
-
-        public void reset() {
-            this.parser.reset();
-        }
-
-        public int fillBuffer(final ReadableByteChannel channel) throws IOException {
-            return this.parser.fillBuffer(channel);
-        }
-
-        public HttpResponse parse() throws IOException, HttpException {
-            HttpResponse response = this.parser.parse();
-            if (headerlog.isDebugEnabled()) {
-                if (response != null && headerlog.isDebugEnabled()) {
-                    headerlog.debug(id + " << " + response.getStatusLine().toString());
-                    Header[] headers = response.getAllHeaders();
-                    for (int i = 0; i < headers.length; i++) {
-                        headerlog.debug(id + " << " + headers[i].toString());
-                    }
-                }
-            }
-            return response;
-        }
-
-    }
-
 }



Mime
View raw message