hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r660234 - in /httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging: LoggingClientIOEventDispatch.java LoggingNHttpClientIOTarget.java LoggingNHttpServerIOTarget.java LoggingServerIOEventDispatch.java
Date Mon, 26 May 2008 17:19:57 GMT
Author: olegk
Date: Mon May 26 10:19:55 2008
New Revision: 660234

URL: http://svn.apache.org/viewvc?rev=660234&view=rev
Log:
Unfortunately, logging decorators for client and server I/O target do not quite work as I
initially thought. Logging has to be added through subclassing, not decoration

Modified:
    httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
    httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java
    httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerIOTarget.java
    httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java

Modified: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java?rev=660234&r1=660233&r2=660234&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
(original)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
Mon May 26 10:19:55 2008
@@ -48,7 +48,10 @@
     @Override
     protected NHttpClientIOTarget createConnection(final IOSession session) {
         return new LoggingNHttpClientIOTarget(
-                super.createConnection(new LoggingIOSession(session, "client")));
+            new LoggingIOSession(session, "client"),
+            createHttpResponseFactory(),
+            this.allocator,
+            this.params);
     }
     
 }

Modified: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java?rev=660234&r1=660233&r2=660234&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java
(original)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java
Mon May 26 10:19:55 2008
@@ -32,113 +32,49 @@
 package org.apache.http.contrib.logging;
 
 import java.io.IOException;
-import java.net.InetAddress;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.Header;
-import org.apache.http.HttpConnectionMetrics;
 import org.apache.http.HttpException;
-import org.apache.http.HttpInetConnection;
 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.NHttpClientHandler;
-import org.apache.http.nio.NHttpClientIOTarget;
-import org.apache.http.protocol.HttpContext;
+import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.params.HttpParams;
 
-public class LoggingNHttpClientIOTarget 
-    implements NHttpClientIOTarget, HttpInetConnection {
+public class LoggingNHttpClientIOTarget extends DefaultNHttpClientConnection {
 
-    private final NHttpClientIOTarget target;
     private final Log log;
     private final Log headerlog;
     
-    public LoggingNHttpClientIOTarget(final NHttpClientIOTarget target) {
-        super();
-        this.target = target;
-        this.log = LogFactory.getLog(target.getClass());
+    public LoggingNHttpClientIOTarget(
+        final IOSession session,
+        final HttpResponseFactory responseFactory,
+        final ByteBufferAllocator allocator,
+        final HttpParams params) {
+        super(session, responseFactory, allocator, params);
+        this.log = LogFactory.getLog(getClass());
         this.headerlog = LogFactory.getLog("org.apache.http.headers");
     }
 
-    public void requestInput() {
-        this.target.requestInput();
-    }
-
-    public void requestOutput() {
-        this.target.requestOutput();
-    }
-
-    public void suspendInput() {
-        this.target.suspendInput();
-    }
-
-    public void suspendOutput() {
-        this.target.suspendOutput();
-    }
-
     public void close() throws IOException {
         this.log.debug("Close connection");        
-        this.target.close();
-    }
-
-    public HttpConnectionMetrics getMetrics() {
-        return this.target.getMetrics();
-    }
-
-    public int getSocketTimeout() {
-        return this.target.getSocketTimeout();
-    }
-
-    public boolean isOpen() {
-        return this.target.isOpen();
-    }
-
-    public boolean isStale() {
-        return this.target.isStale();
-    }
-
-    public void setSocketTimeout(int timeout) {
-        this.target.setSocketTimeout(timeout);
+        super.close();
     }
 
     public void shutdown() throws IOException {
         this.log.debug("Shutdown connection");        
-        this.target.shutdown();
-    }
-
-    public HttpContext getContext() {
-        return this.target.getContext();
-    }
-
-    public HttpRequest getHttpRequest() {
-        return this.target.getHttpRequest();
-    }
-
-    public HttpResponse getHttpResponse() {
-        return this.target.getHttpResponse();
-    }
-
-    public int getStatus() {
-        return this.target.getStatus();
-    }
-
-    public boolean isRequestSubmitted() {
-        return this.target.isRequestSubmitted();
-    }
-
-    public void resetInput() {
-        this.target.resetInput();
-    }
-
-    public void resetOutput() {
-        this.target.resetOutput();
+        super.shutdown();
     }
 
     public void submitRequest(final HttpRequest request) throws IOException, HttpException
{
         if (this.log.isDebugEnabled()) {
             this.log.debug("HTTP connection " + this + ": "  + request.getRequestLine().toString());
         }
-        this.target.submitRequest(request);
+        super.submitRequest(request);
         if (this.headerlog.isDebugEnabled()) {
             this.headerlog.debug(">> " + request.getRequestLine().toString());
             Header[] headers = request.getAllHeaders();
@@ -150,49 +86,12 @@
 
     public void consumeInput(final NHttpClientHandler handler) {
         this.log.debug("Consume input");        
-        this.target.consumeInput(handler);
+        super.consumeInput(handler);
     }
 
     public void produceOutput(final NHttpClientHandler handler) {
         this.log.debug("Produce output");        
-        this.target.produceOutput(handler);
+        super.produceOutput(handler);
     }
     
-    public InetAddress getLocalAddress() {
-      if (this.target instanceof HttpInetConnection) {
-          return ((HttpInetConnection) this.target).getLocalAddress();
-      } else {
-          return null;
-      }
-  }
-
-  public int getLocalPort() {
-      if (this.target instanceof HttpInetConnection) {
-          return ((HttpInetConnection) this.target).getLocalPort();
-      } else {
-          return -1;
-      }
-  }
-
-  public InetAddress getRemoteAddress() {
-      if (this.target instanceof HttpInetConnection) {
-          return ((HttpInetConnection) this.target).getRemoteAddress();
-      } else {
-          return null;
-      }
-  }
-
-  public int getRemotePort() {
-      if (this.target instanceof HttpInetConnection) {
-          return ((HttpInetConnection) this.target).getRemotePort();
-      } else {
-          return -1;
-      }
-  }
-  
-  @Override
-  public String toString() {
-      return this.target.toString();
-  }
-  
 }
\ No newline at end of file

Modified: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerIOTarget.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerIOTarget.java?rev=660234&r1=660233&r2=660234&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerIOTarget.java
(original)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerIOTarget.java
Mon May 26 10:19:55 2008
@@ -32,112 +32,49 @@
 package org.apache.http.contrib.logging;
 
 import java.io.IOException;
-import java.net.InetAddress;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.Header;
-import org.apache.http.HttpConnectionMetrics;
 import org.apache.http.HttpException;
-import org.apache.http.HttpInetConnection;
-import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestFactory;
 import org.apache.http.HttpResponse;
-import org.apache.http.nio.NHttpServerIOTarget;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
 import org.apache.http.nio.NHttpServiceHandler;
-import org.apache.http.protocol.HttpContext;
+import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.params.HttpParams;
 
-public class LoggingNHttpServerIOTarget 
-    implements NHttpServerIOTarget, HttpInetConnection {
+public class LoggingNHttpServerIOTarget extends DefaultNHttpServerConnection {
 
-    private final NHttpServerIOTarget target;
     private final Log log;
     private final Log headerlog;
     
-    public LoggingNHttpServerIOTarget(final NHttpServerIOTarget target) {
-        this.target = target;
-        this.log = LogFactory.getLog(target.getClass());
+    public LoggingNHttpServerIOTarget(
+        final IOSession session,
+        final HttpRequestFactory requestFactory,
+        final ByteBufferAllocator allocator,
+        final HttpParams params) {
+        super(session, requestFactory, allocator, params);
+        this.log = LogFactory.getLog(getClass());
         this.headerlog = LogFactory.getLog("org.apache.http.headers");
     }
 
-    public void requestInput() {
-        this.target.requestInput();
-    }
-
-    public void requestOutput() {
-        this.target.requestOutput();
-    }
-
-    public void suspendInput() {
-        this.target.suspendInput();
-    }
-
-    public void suspendOutput() {
-        this.target.suspendOutput();
-    }
-
     public void close() throws IOException {
         this.log.debug("Close connection");        
-        this.target.close();
-    }
-
-    public HttpConnectionMetrics getMetrics() {
-        return this.target.getMetrics();
-    }
-
-    public int getSocketTimeout() {
-        return this.target.getSocketTimeout();
-    }
-
-    public boolean isOpen() {
-        return this.target.isOpen();
-    }
-
-    public boolean isStale() {
-        return this.target.isStale();
-    }
-
-    public void setSocketTimeout(int timeout) {
-        this.target.setSocketTimeout(timeout);
+        super.close();
     }
 
     public void shutdown() throws IOException {
         this.log.debug("Shutdown connection");        
-        this.target.shutdown();
+        super.shutdown();
     }
     
-    public HttpContext getContext() {
-        return this.target.getContext();
-    }
-
-    public HttpRequest getHttpRequest() {
-        return this.target.getHttpRequest();
-    }
-
-    public HttpResponse getHttpResponse() {
-        return this.target.getHttpResponse();
-    }
-
-    public int getStatus() {
-        return this.target.getStatus();
-    }
-
-    public boolean isResponseSubmitted() {
-        return this.target.isResponseSubmitted();
-    }
-
-    public void resetInput() {
-        this.target.requestInput();
-    }
-
-    public void resetOutput() {
-        this.target.requestOutput();
-    }
-
     public void submitResponse(final HttpResponse response) throws IOException, HttpException
{
         if (this.log.isDebugEnabled()) {
             this.log.debug("HTTP connection " + this + ": "  + response.getStatusLine().toString());
         }
-        this.target.submitResponse(response);
+        super.submitResponse(response);
         if (this.headerlog.isDebugEnabled()) {
             this.headerlog.debug("<< " + response.getStatusLine().toString());
             Header[] headers = response.getAllHeaders();
@@ -149,49 +86,12 @@
 
     public void consumeInput(final NHttpServiceHandler handler) {
         this.log.debug("Consume input");        
-        this.target.consumeInput(handler);
+        super.consumeInput(handler);
     }
 
     public void produceOutput(final NHttpServiceHandler handler) {
         this.log.debug("Produce output");        
-        this.target.produceOutput(handler);
+        super.produceOutput(handler);
     }
     
-    public InetAddress getLocalAddress() {
-      if (this.target instanceof HttpInetConnection) {
-          return ((HttpInetConnection) this.target).getLocalAddress();
-      } else {
-          return null;
-      }
-  }
-
-  public int getLocalPort() {
-      if (this.target instanceof HttpInetConnection) {
-          return ((HttpInetConnection) this.target).getLocalPort();
-      } else {
-          return -1;
-      }
-  }
-
-  public InetAddress getRemoteAddress() {
-      if (this.target instanceof HttpInetConnection) {
-          return ((HttpInetConnection) this.target).getRemoteAddress();
-      } else {
-          return null;
-      }
-  }
-
-  public int getRemotePort() {
-      if (this.target instanceof HttpInetConnection) {
-          return ((HttpInetConnection) this.target).getRemotePort();
-      } else {
-          return -1;
-      }
-  }
-  
-  @Override
-  public String toString() {
-      return this.target.toString();
-  }
-  
 }
\ No newline at end of file

Modified: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java?rev=660234&r1=660233&r2=660234&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
(original)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
Mon May 26 10:19:55 2008
@@ -47,8 +47,11 @@
 
     @Override
     protected NHttpServerIOTarget createConnection(final IOSession session) {
-        return new LoggingNHttpServerIOTarget(
-                super.createConnection(new LoggingIOSession(session, "server")));
+        return new LoggingNHttpServerIOTarget(            
+            new LoggingIOSession(session, "server"),
+            createHttpRequestFactory(),
+            this.allocator,
+            this.params);
     }
     
 }



Mime
View raw message