synapse-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r638538 - /synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/
Date Tue, 18 Mar 2008 19:52:10 GMT
Author: olegk
Date: Tue Mar 18 12:52:06 2008
New Revision: 638538

URL: http://svn.apache.org/viewvc?rev=638538&view=rev
Log:
* Eliminated code duplication with HttpCore NIO
* I/O sessions, connections and protocol handlers get decorated with logging capabilities
_only_ if their respective log appenders are active. This should _slightly_ improve performance
of the NHttp transport when debug logging is off 

Added:
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientIOTarget.java
  (with props)
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServerIOTarget.java
  (with props)
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingUtils.java
  (with props)
Removed:
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientConnection.java
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServerConnection.java
Modified:
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingIOSession.java
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientHandler.java
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServiceHandler.java
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/PlainClientIOEventDispatch.java
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/PlainServerIOEventDispatch.java
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/SSLClientIOEventDispatch.java
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/SSLServerIOEventDispatch.java

Modified: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingIOSession.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingIOSession.java?rev=638538&r1=638537&r2=638538&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingIOSession.java
(original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingIOSession.java
Tue Mar 18 12:52:06 2008
@@ -23,6 +23,7 @@
 import java.nio.ByteBuffer;
 import java.nio.channels.ByteChannel;
 import java.nio.channels.SelectionKey;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -35,22 +36,26 @@
  */
 public class LoggingIOSession implements IOSession {
 
-    private static int COUNT = 0;
+    private static AtomicLong COUNT = new AtomicLong(0);
     
     private final Log log;
     private final IOSession session;
     private final ByteChannel channel;
-    private final int id;
+    private final String id;
     
-    public LoggingIOSession(final IOSession session) {
+    public LoggingIOSession(final Log log, final IOSession session, final String id) {
         super();
         if (session == null) {
             throw new IllegalArgumentException("I/O session may not be null");
         }
         this.session = session;
         this.channel = new LoggingByteChannel();
-        this.id = ++COUNT;
-        this.log = LogFactory.getLog(session.getClass());
+        this.id = id + "-" + COUNT.incrementAndGet();
+        if (log != null) {
+            this.log = log;
+        } else {
+            this.log = LogFactory.getLog(session.getClass());
+        }
     }
 
     public int getStatus() {

Modified: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientHandler.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientHandler.java?rev=638538&r1=638537&r2=638538&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientHandler.java
(original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientHandler.java
Tue Mar 18 12:52:06 2008
@@ -40,14 +40,25 @@
     private final Log headerlog;
     private final NHttpClientHandler handler;
     
-    public LoggingNHttpClientHandler(final NHttpClientHandler handler) {
+    public LoggingNHttpClientHandler(
+            final Log log, 
+            final Log headerlog, 
+            final NHttpClientHandler handler) {
         super();
         if (handler == null) {
             throw new IllegalArgumentException("HTTP client handler may not be null");
         }
         this.handler = handler;
-        this.log = LogFactory.getLog(handler.getClass());
-        this.headerlog = LogFactory.getLog("org.apache.synapse.transport.nhttp.headers");
+        if (log != null) {
+            this.log = log;
+        } else {
+            this.log = LogFactory.getLog(handler.getClass());
+        }
+        if (log != null) {
+            this.headerlog = headerlog;
+        } else {
+            this.headerlog = LogFactory.getLog(LoggingUtils.HEADER_LOG_ID);
+        }
     }
     
     public void connected(final NHttpClientConnection conn, final Object attachment) {

Added: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientIOTarget.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientIOTarget.java?rev=638538&view=auto
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientIOTarget.java
(added)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientIOTarget.java
Tue Mar 18 12:52:06 2008
@@ -0,0 +1,200 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.transport.nhttp;
+
+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.nio.NHttpClientHandler;
+import org.apache.http.nio.NHttpClientIOTarget;
+import org.apache.http.protocol.HttpContext;
+
+public class LoggingNHttpClientIOTarget 
+    implements NHttpClientIOTarget, HttpInetConnection {
+
+    private final NHttpClientIOTarget target;
+    private final Log log;
+    private final Log headerlog;
+    
+    public LoggingNHttpClientIOTarget(
+            final Log log, 
+            final Log headerlog, 
+            final NHttpClientIOTarget target) {
+        super();
+        if (target == null) {
+            throw new IllegalArgumentException("IO target may not be null");
+        }
+        this.target = target;
+        if (log != null) {
+            this.log = log;
+        } else {
+            this.log = LogFactory.getLog(target.getClass());
+        }
+        if (log != null) {
+            this.headerlog = headerlog;
+        } else {
+            this.headerlog = LogFactory.getLog(LoggingUtils.HEADER_LOG_ID);
+        }
+    }
+
+    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);
+    }
+
+    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();
+    }
+
+    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);
+        if (this.headerlog.isDebugEnabled()) {
+            this.headerlog.debug(">> " + request.getRequestLine().toString());
+            Header[] headers = request.getAllHeaders();
+            for (int i = 0; i < headers.length; i++) {
+                this.headerlog.debug(">> " + headers[i].toString());
+            }
+        }
+    }
+
+    public void consumeInput(final NHttpClientHandler handler) {
+        this.log.debug("Consume input");        
+        this.target.consumeInput(handler);
+    }
+
+    public void produceOutput(final NHttpClientHandler handler) {
+        this.log.debug("Produce output");        
+        this.target.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

Propchange: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientIOTarget.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientIOTarget.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpClientIOTarget.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServerIOTarget.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServerIOTarget.java?rev=638538&view=auto
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServerIOTarget.java
(added)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServerIOTarget.java
Tue Mar 18 12:52:06 2008
@@ -0,0 +1,199 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.transport.nhttp;
+
+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.nio.NHttpServerIOTarget;
+import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.protocol.HttpContext;
+
+public class LoggingNHttpServerIOTarget 
+    implements NHttpServerIOTarget, HttpInetConnection {
+
+    private final NHttpServerIOTarget target;
+    private final Log log;
+    private final Log headerlog;
+    
+    public LoggingNHttpServerIOTarget(
+            final Log log, 
+            final Log headerlog, 
+            final NHttpServerIOTarget target) {
+        if (target == null) {
+            throw new IllegalArgumentException("IO target may not be null");
+        }
+        this.target = target;
+        if (log != null) {
+            this.log = log;
+        } else {
+            this.log = LogFactory.getLog(target.getClass());
+        }
+        if (log != null) {
+            this.headerlog = headerlog;
+        } else {
+            this.headerlog = LogFactory.getLog(LoggingUtils.HEADER_LOG_ID);
+        }
+    }
+
+    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);
+    }
+
+    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 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);
+        if (this.headerlog.isDebugEnabled()) {
+            this.headerlog.debug("<< " + response.getStatusLine().toString());
+            Header[] headers = response.getAllHeaders();
+            for (int i = 0; i < headers.length; i++) {
+                this.headerlog.debug("<< " + headers[i].toString());
+            }
+        }
+    }
+
+    public void consumeInput(final NHttpServiceHandler handler) {
+        this.log.debug("Consume input");        
+        this.target.consumeInput(handler);
+    }
+
+    public void produceOutput(final NHttpServiceHandler handler) {
+        this.log.debug("Produce output");        
+        this.target.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

Propchange: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServerIOTarget.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServerIOTarget.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServerIOTarget.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServiceHandler.java?rev=638538&r1=638537&r2=638538&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServiceHandler.java
(original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingNHttpServiceHandler.java
Tue Mar 18 12:52:06 2008
@@ -41,14 +41,25 @@
     private final Log headerlog;
     private final NHttpServiceHandler handler;
     
-    public LoggingNHttpServiceHandler(final NHttpServiceHandler handler) {
+    public LoggingNHttpServiceHandler(
+            final Log log, 
+            final Log headerlog, 
+            final NHttpServiceHandler handler) {
         super();
         if (handler == null) {
             throw new IllegalArgumentException("HTTP service handler may not be null");
         }
         this.handler = handler;
-        this.log = LogFactory.getLog(handler.getClass());
-        this.headerlog = LogFactory.getLog("org.apache.synapse.transport.nhttp.headers");
+        if (log != null) {
+            this.log = log;
+        } else {
+            this.log = LogFactory.getLog(handler.getClass());
+        }
+        if (log != null) {
+            this.headerlog = headerlog;
+        } else {
+            this.headerlog = LogFactory.getLog(LoggingUtils.HEADER_LOG_ID);
+        }
     }
     
     public void connected(final NHttpServerConnection conn) {

Added: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingUtils.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingUtils.java?rev=638538&view=auto
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingUtils.java
(added)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingUtils.java
Tue Mar 18 12:52:06 2008
@@ -0,0 +1,78 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.transport.nhttp;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.nio.NHttpClientIOTarget;
+import org.apache.http.nio.NHttpServerIOTarget;
+import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.nio.reactor.IOSession;
+
+public class LoggingUtils {
+    
+    public static String HEADER_LOG_ID = "org.apache.synapse.transport.nhttp.headers"; 
+
+    public static IOSession decorate(IOSession session, final String id) {
+        Log log = LogFactory.getLog(session.getClass());
+        if (log.isDebugEnabled()) {
+            session = new LoggingIOSession(log, session, id);
+        }
+        return session;
+    }
+    
+    public static NHttpClientIOTarget decorate(NHttpClientIOTarget target) {
+        Log log = LogFactory.getLog(target.getClass());
+        Log headerlog = LogFactory.getLog(HEADER_LOG_ID);
+        if (log.isDebugEnabled() || headerlog.isDebugEnabled()) {
+            target = new LoggingNHttpClientIOTarget(log, headerlog, target);
+        }
+        return target;
+    }
+
+    public static NHttpServerIOTarget decorate(NHttpServerIOTarget target) {
+        Log log = LogFactory.getLog(target.getClass());
+        Log headerlog = LogFactory.getLog(HEADER_LOG_ID);
+        if (log.isDebugEnabled() || headerlog.isDebugEnabled()) {
+            target = new LoggingNHttpServerIOTarget(log, headerlog, target);
+        }
+        return target;
+    }
+
+    public static NHttpClientHandler decorate(NHttpClientHandler handler) {
+        Log log = LogFactory.getLog(handler.getClass());
+        Log headerlog = LogFactory.getLog(HEADER_LOG_ID);
+        if (log.isDebugEnabled() || headerlog.isDebugEnabled()) {
+            handler = new LoggingNHttpClientHandler(log, headerlog, handler);
+        }
+        return handler;
+    }
+
+    public static NHttpServiceHandler decorate(NHttpServiceHandler handler) {
+        Log log = LogFactory.getLog(handler.getClass());
+        Log headerlog = LogFactory.getLog(HEADER_LOG_ID);
+        if (log.isDebugEnabled() || headerlog.isDebugEnabled()) {
+            handler = new LoggingNHttpServiceHandler(log, headerlog, handler);
+        }
+        return handler;
+    }
+
+}
\ No newline at end of file

Propchange: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/LoggingUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/PlainClientIOEventDispatch.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/PlainClientIOEventDispatch.java?rev=638538&r1=638537&r2=638538&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/PlainClientIOEventDispatch.java
(original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/PlainClientIOEventDispatch.java
Tue Mar 18 12:52:06 2008
@@ -18,69 +18,22 @@
  */
 package org.apache.synapse.transport.nhttp;
 
-import org.apache.http.impl.DefaultHttpResponseFactory;
-import org.apache.http.impl.nio.DefaultNHttpClientConnection;
+import org.apache.http.impl.nio.DefaultClientIOEventDispatch;
 import org.apache.http.nio.NHttpClientHandler;
-import org.apache.http.nio.reactor.IOEventDispatch;
+import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.reactor.IOSession;
-import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
-public class PlainClientIOEventDispatch implements IOEventDispatch {
+public class PlainClientIOEventDispatch extends DefaultClientIOEventDispatch {
 
-    private static final String NHTTP_CONN = "SYNAPSE.NHTTP_CONN";
-    
-    private final NHttpClientHandler handler;
-    private final HttpParams params;
-    
     public PlainClientIOEventDispatch(final NHttpClientHandler handler, final HttpParams
params) {
-        super();
-        if (handler == null) {
-            throw new IllegalArgumentException("HTTP client handler may not be null");
-        }
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
-        }
-        // Decorate client handler with logging capabilities
-        this.handler = new LoggingNHttpClientHandler(handler);
-        this.params = params;
+        super(LoggingUtils.decorate(handler), params);
     }
     
-    public void connected(final IOSession session) {
-        // Decorate I/O session with logging capabilities
-        LoggingNHttpClientConnection conn = new LoggingNHttpClientConnection(
-                new LoggingIOSession(session), 
-                new DefaultHttpResponseFactory(),
-                new HeapByteBufferAllocator(),
-                this.params); 
-        session.setAttribute(NHTTP_CONN, conn);
-        
-        Object attachment = session.getAttribute(IOSession.ATTACHMENT_KEY);
-        this.handler.connected(conn, attachment);
-    }
-
-    public void disconnected(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
-        this.handler.closed(conn);
-    }
-
-    public void inputReady(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
-        conn.consumeInput(this.handler);
+    @Override
+    protected NHttpClientIOTarget createConnection(IOSession session) {
+        return LoggingUtils.decorate(
+                super.createConnection(LoggingUtils.decorate(session, "client")));
     }
-
-    public void outputReady(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
-        conn.produceOutput(this.handler);
-    }
-
-    public void timeout(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
-        this.handler.timeout(conn);
-    }
-
+    
 }

Modified: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/PlainServerIOEventDispatch.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/PlainServerIOEventDispatch.java?rev=638538&r1=638537&r2=638538&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/PlainServerIOEventDispatch.java
(original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/PlainServerIOEventDispatch.java
Tue Mar 18 12:52:06 2008
@@ -18,67 +18,22 @@
  */
 package org.apache.synapse.transport.nhttp;
 
-import org.apache.http.impl.DefaultHttpRequestFactory;
-import org.apache.http.impl.nio.DefaultNHttpServerConnection;
+import org.apache.http.impl.nio.DefaultServerIOEventDispatch;
+import org.apache.http.nio.NHttpServerIOTarget;
 import org.apache.http.nio.NHttpServiceHandler;
-import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
-import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
-public class PlainServerIOEventDispatch implements IOEventDispatch {
+public class PlainServerIOEventDispatch extends DefaultServerIOEventDispatch {
 
-    private static final String NHTTP_CONN = "SYNAPSE.NHTTP_CONN";
-    
-    private final NHttpServiceHandler handler;
-    private final HttpParams params;
-    
     public PlainServerIOEventDispatch(final NHttpServiceHandler handler, final HttpParams
params) {
-        super();
-        if (handler == null) {
-            throw new IllegalArgumentException("HTTP service handler may not be null");
-        }
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
-        }
-        // Decorate service handler with logging capabilities
-        this.handler = new LoggingNHttpServiceHandler(handler);
-        this.params = params;
+        super(LoggingUtils.decorate(handler), params);
     }
     
-    public void connected(final IOSession session) {
-        // Decorate I/O session with logging capabilities
-        LoggingNHttpServerConnection conn = new LoggingNHttpServerConnection(
-                new LoggingIOSession(session), 
-                new DefaultHttpRequestFactory(),
-                new HeapByteBufferAllocator(),
-                this.params); 
-        session.setAttribute(NHTTP_CONN, conn);
-        this.handler.connected(conn);
-    }
-
-    public void disconnected(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
-        this.handler.closed(conn);
-    }
-
-    public void inputReady(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
-        conn.consumeInput(this.handler);
+    @Override
+    protected NHttpServerIOTarget createConnection(final IOSession session) {
+        return LoggingUtils.decorate(
+                super.createConnection(LoggingUtils.decorate(session, "server")));
     }
-
-    public void outputReady(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
-        conn.produceOutput(this.handler);
-    }
-
-    public void timeout(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
-        this.handler.timeout(conn);
-    }
-
+    
 }

Modified: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/SSLClientIOEventDispatch.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/SSLClientIOEventDispatch.java?rev=638538&r1=638537&r2=638538&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/SSLClientIOEventDispatch.java
(original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/SSLClientIOEventDispatch.java
Tue Mar 18 12:52:06 2008
@@ -18,51 +18,23 @@
  */
 package org.apache.synapse.transport.nhttp;
 
-import java.io.IOException;
-
 import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLException;
 
-import org.apache.http.impl.DefaultHttpResponseFactory;
-import org.apache.http.impl.nio.DefaultNHttpClientConnection;
-import org.apache.http.impl.nio.reactor.SSLIOSession;
 import org.apache.http.impl.nio.reactor.SSLIOSessionHandler;
-import org.apache.http.impl.nio.reactor.SSLMode;
 import org.apache.http.nio.NHttpClientHandler;
-import org.apache.http.nio.reactor.IOEventDispatch;
+import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.reactor.IOSession;
-import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
-public class SSLClientIOEventDispatch implements IOEventDispatch {
+public class SSLClientIOEventDispatch 
+    extends org.apache.http.impl.nio.SSLClientIOEventDispatch {
 
-    private static final String NHTTP_CONN = "SYNAPSE.NHTTP_CONN";
-    private static final String SSL_SESSION = "SYNAPSE.SSL_SESSION";
-    
-    private final NHttpClientHandler handler;
-    private final HttpParams params;
-    private final SSLContext sslcontext;
-    private final SSLIOSessionHandler sslHandler;
-    
     public SSLClientIOEventDispatch(
             final NHttpClientHandler handler,
             final SSLContext sslcontext,
             final SSLIOSessionHandler sslHandler,
             final HttpParams params) {
-        super();
-        if (handler == null) {
-            throw new IllegalArgumentException("HTTP client handler may not be null");
-        }
-        if (sslcontext == null) {
-            throw new IllegalArgumentException("SSL context may not be null");
-        }
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
-        }
-        this.handler = new LoggingNHttpClientHandler(handler);
-        this.params = params;
-        this.sslcontext = sslcontext;
-        this.sslHandler = sslHandler;
+        super(LoggingUtils.decorate(handler), sslcontext, sslHandler, params);
     }
     
     public SSLClientIOEventDispatch(
@@ -72,88 +44,10 @@
         this(handler, sslcontext, null, params);
     }
     
-    public void connected(final IOSession session) {
-
-        SSLIOSession sslSession = new SSLIOSession(
-                session, 
-                this.sslcontext,
-                this.sslHandler); 
-        
-        DefaultNHttpClientConnection conn = new DefaultNHttpClientConnection(
-                new LoggingIOSession(sslSession), 
-                new DefaultHttpResponseFactory(),
-                new HeapByteBufferAllocator(),
-                this.params); 
-        
-        session.setAttribute(NHTTP_CONN, conn);
-        session.setAttribute(SSL_SESSION, sslSession);
-        
-        Object attachment = session.getAttribute(IOSession.ATTACHMENT_KEY);
-        this.handler.connected(conn, attachment);
-
-        try {
-            sslSession.bind(SSLMode.CLIENT, this.params);
-        } catch (SSLException ex) {
-            this.handler.exception(conn, ex);
-            sslSession.shutdown();
-        }
-    }
-
-    public void disconnected(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
-        
-        this.handler.closed(conn);
-    }
-
-    public void inputReady(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
-        SSLIOSession sslSession = (SSLIOSession) session.getAttribute(
-                SSL_SESSION);
-        try {
-            synchronized (sslSession) {
-                while (sslSession.isAppInputReady()) {
-                    conn.consumeInput(this.handler);
-                }
-                sslSession.inboundTransport();
-            }
-        } catch (IOException ex) {
-            this.handler.exception(conn, ex);
-            sslSession.shutdown();
-        }
-    }
-
-    public void outputReady(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
-        SSLIOSession sslSession = (SSLIOSession) session.getAttribute(
-                SSL_SESSION);
-        try {
-            synchronized (sslSession) {
-                if (sslSession.isAppOutputReady()) {
-                    conn.produceOutput(this.handler);
-                }
-                sslSession.outboundTransport();
-            }
-        } catch (IOException ex) {
-            this.handler.exception(conn, ex);
-            sslSession.shutdown();
-        }
-    }
-
-    public void timeout(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
-        SSLIOSession sslSession = (SSLIOSession) session.getAttribute(
-                SSL_SESSION);
-        this.handler.timeout(conn);
-        synchronized (sslSession) {
-            if (sslSession.isOutboundDone() && !sslSession.isInboundDone()) {
-                // The session failed to terminate cleanly 
-                sslSession.shutdown();
-            }
-        }
+    @Override
+    protected NHttpClientIOTarget createConnection(IOSession session) {
+        return LoggingUtils.decorate(
+                super.createConnection(LoggingUtils.decorate(session, "sslclient")));
     }
 
 }

Modified: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/SSLServerIOEventDispatch.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/SSLServerIOEventDispatch.java?rev=638538&r1=638537&r2=638538&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/SSLServerIOEventDispatch.java
(original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/SSLServerIOEventDispatch.java
Tue Mar 18 12:52:06 2008
@@ -18,51 +18,23 @@
  */
 package org.apache.synapse.transport.nhttp;
 
-import java.io.IOException;
-
 import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLException;
 
-import org.apache.http.impl.DefaultHttpRequestFactory;
-import org.apache.http.impl.nio.DefaultNHttpServerConnection;
-import org.apache.http.impl.nio.reactor.SSLIOSession;
 import org.apache.http.impl.nio.reactor.SSLIOSessionHandler;
-import org.apache.http.impl.nio.reactor.SSLMode;
+import org.apache.http.nio.NHttpServerIOTarget;
 import org.apache.http.nio.NHttpServiceHandler;
-import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
-import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
-public class SSLServerIOEventDispatch implements IOEventDispatch {
+public class SSLServerIOEventDispatch 
+    extends org.apache.http.impl.nio.SSLServerIOEventDispatch {
 
-    private static final String NHTTP_CONN = "SYNAPSE.NHTTP_CONN";
-    private static final String SSL_SESSION = "SYNAPSE.SSL_SESSION";
-   
-    private final NHttpServiceHandler handler;
-    private final SSLContext sslcontext;
-    private final SSLIOSessionHandler sslHandler;
-    private final HttpParams params;
-    
     public SSLServerIOEventDispatch(
             final NHttpServiceHandler handler,
             final SSLContext sslcontext,
             final SSLIOSessionHandler sslHandler,
             final HttpParams params) {
-        super();
-        if (handler == null) {
-            throw new IllegalArgumentException("HTTP service handler may not be null");
-        }
-        if (sslcontext == null) {
-            throw new IllegalArgumentException("SSL context may not be null");
-        }
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
-        }
-        this.handler = new LoggingNHttpServiceHandler(handler);
-        this.params = params;
-        this.sslcontext = sslcontext;
-        this.sslHandler = sslHandler;
+        super(LoggingUtils.decorate(handler), sslcontext, sslHandler, params);
     }
     
     public SSLServerIOEventDispatch(
@@ -72,86 +44,10 @@
         this(handler, sslcontext, null, params);
     }
     
-    public void connected(final IOSession session) {
-
-        SSLIOSession sslSession = new SSLIOSession(
-                session, 
-                this.sslcontext,
-                this.sslHandler); 
-        
-        DefaultNHttpServerConnection conn = new DefaultNHttpServerConnection(
-                new LoggingIOSession(sslSession), 
-                new DefaultHttpRequestFactory(),
-                new HeapByteBufferAllocator(),
-                this.params); 
-        
-        session.setAttribute(NHTTP_CONN, conn);
-        session.setAttribute(SSL_SESSION, sslSession);
-
-        this.handler.connected(conn);
-
-        try {
-            sslSession.bind(SSLMode.SERVER, this.params);
-        } catch (SSLException ex) {
-            this.handler.exception(conn, ex);
-            sslSession.shutdown();
-        }
-    }
-
-    public void disconnected(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
-        this.handler.closed(conn);
+    @Override
+    protected NHttpServerIOTarget createConnection(final IOSession session) {
+        return LoggingUtils.decorate(
+                super.createConnection(LoggingUtils.decorate(session, "sslserver")));
     }
-
-    public void inputReady(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
-        SSLIOSession sslSession = (SSLIOSession) session.getAttribute(
-                SSL_SESSION);
-        try {
-            synchronized (sslSession) {
-                if (sslSession.isAppInputReady()) {
-                    conn.consumeInput(this.handler);
-                }
-                sslSession.inboundTransport();
-            }
-        } catch (IOException ex) {
-            this.handler.exception(conn, ex);
-            sslSession.shutdown();
-        }
-    }
-
-    public void outputReady(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
-        SSLIOSession sslSession = (SSLIOSession) session.getAttribute(
-                SSL_SESSION);
-        try {
-            synchronized (sslSession) {
-                if (sslSession.isAppOutputReady()) {
-                    conn.produceOutput(this.handler);
-                }
-                sslSession.outboundTransport();
-            }
-        } catch (IOException ex) {
-            this.handler.exception(conn, ex);
-            sslSession.shutdown();
-        }
-    }
-
-    public void timeout(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
-        SSLIOSession sslSession = (SSLIOSession) session.getAttribute(
-                SSL_SESSION);
-        this.handler.timeout(conn);
-        synchronized (sslSession) {
-            if (sslSession.isOutboundDone() && !sslSession.isInboundDone()) {
-                // The session failed to terminate cleanly 
-                sslSession.shutdown();
-            }
-        }
-    }
-
+    
 }



Mime
View raw message