hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1164033 - in /httpcomponents/httpcore/trunk/httpcore-nio/src: examples/org/apache/http/examples/nio/ main/java/org/apache/http/impl/nio/ main/java/org/apache/http/impl/nio/pool/ main/java/org/apache/http/impl/nio/ssl/ main/java/org/apache/...
Date Thu, 01 Sep 2011 12:18:50 GMT
Author: olegk
Date: Thu Sep  1 12:18:49 2011
New Revision: 1164033

URL: http://svn.apache.org/viewvc?rev=1164033&view=rev
Log:
BasicNIOConnPool to return fully initialized HTTP connection objects instead of raw IO sessions; refactored default and SSL IO event dispatchers

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpClient.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpSSLClient.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLClientIOEventDispatch.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLServerIOEventDispatch.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpClient.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpClient.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpClient.java Thu Sep  1 12:18:49 2011
@@ -28,7 +28,6 @@ package org.apache.http.examples.nio;
 
 import java.io.IOException;
 import java.io.InterruptedIOException;
-import java.nio.channels.SelectionKey;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -43,11 +42,11 @@ import org.apache.http.impl.nio.pool.Bas
 import org.apache.http.impl.nio.pool.BasicNIOPoolEntry;
 import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
 import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.nio.NHttpClientConnection;
 import org.apache.http.nio.protocol.BufferingHttpClientHandler;
 import org.apache.http.nio.protocol.HttpRequestExecutionHandler;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOEventDispatch;
-import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.params.HttpParams;
@@ -167,9 +166,9 @@ public class NHttpClient {
 
         public void completed(final BasicNIOPoolEntry entry) {
             this.poolEntry = entry;
-            IOSession session = entry.getConnection();
-            session.setAttribute("executor", this);
-            session.setEvent(SelectionKey.OP_WRITE);
+            NHttpClientConnection conn = entry.getConnection();
+            conn.getContext().setAttribute("executor", this);
+            conn.requestOutput();
             System.out.println(this.poolEntry.getRoute() + ": obtained connection from the pool");
         }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpSSLClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpSSLClient.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpSSLClient.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpSSLClient.java Thu Sep  1 12:18:49 2011
@@ -28,7 +28,6 @@ package org.apache.http.examples.nio;
 
 import java.io.IOException;
 import java.io.InterruptedIOException;
-import java.nio.channels.SelectionKey;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -45,11 +44,11 @@ import org.apache.http.impl.nio.pool.Bas
 import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
 import org.apache.http.impl.nio.ssl.SSLClientIOEventDispatch;
 import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.nio.NHttpClientConnection;
 import org.apache.http.nio.protocol.BufferingHttpClientHandler;
 import org.apache.http.nio.protocol.HttpRequestExecutionHandler;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOEventDispatch;
-import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.params.HttpParams;
@@ -176,9 +175,9 @@ public class NHttpSSLClient {
 
         public void completed(final BasicNIOPoolEntry entry) {
             this.poolEntry = entry;
-            IOSession session = entry.getConnection();
-            session.setAttribute("executor", this);
-            session.setEvent(SelectionKey.OP_WRITE);
+            NHttpClientConnection conn = entry.getConnection();
+            conn.getContext().setAttribute("executor", this);
+            conn.requestOutput();
             System.out.println(this.poolEntry.getRoute() + ": obtained connection from the pool");
         }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java Thu Sep  1 12:18:49 2011
@@ -27,10 +27,13 @@
 
 package org.apache.http.impl.nio;
 
+import java.io.IOException;
+
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseFactory;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.nio.reactor.SSLIOSession;
 import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;
@@ -60,8 +63,8 @@ import org.apache.http.protocol.Executio
 @Immutable // provided injected dependencies are immutable
 public class DefaultClientIOEventDispatch implements IOEventDispatch {
 
-    protected final ByteBufferAllocator allocator;
     protected final NHttpClientHandler handler;
+    protected final ByteBufferAllocator allocator;
     protected final HttpParams params;
 
     /**
@@ -124,27 +127,25 @@ public class DefaultClientIOEventDispatc
      * @return newly created HTTP connection.
      */
     protected NHttpClientIOTarget createConnection(final IOSession session) {
-        try {
-            return new DefaultNHttpClientConnection(
-                    session,
-                    createHttpResponseFactory(),
-                    this.allocator,
-                    this.params);
-        } catch (RuntimeException ex) {
-            session.shutdown();
-            throw ex;
-        }
+        return new DefaultNHttpClientConnection(
+                session,
+                createHttpResponseFactory(),
+                this.allocator,
+                this.params);
     }
 
     public void connected(final IOSession session) {
         try {
-            NHttpClientIOTarget conn = createConnection(session);
-            Object attachment = session.getAttribute(IOSession.ATTACHMENT_KEY);
-            session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
-
+            NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
+                    ExecutionContext.HTTP_CONNECTION);
+            if (conn == null) {
+                conn = createConnection(session);
+                session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+            }
             int timeout = HttpConnectionParams.getSoTimeout(this.params);
             conn.setSocketTimeout(timeout);
 
+            Object attachment = session.getAttribute(IOSession.ATTACHMENT_KEY);
             this.handler.connected(conn, attachment);
         } catch (RuntimeException ex) {
             session.shutdown();
@@ -171,7 +172,21 @@ public class DefaultClientIOEventDispatc
             NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
                     ExecutionContext.HTTP_CONNECTION);
             ensureNotNull(conn);
-            conn.consumeInput(this.handler);
+            SSLIOSession ssliosession = (SSLIOSession) session.getAttribute(
+                    IOSession.SSL_SESSION_KEY);
+            if (ssliosession == null) {
+                conn.consumeInput(this.handler);
+            } else {
+                try {
+                    if (ssliosession.isAppInputReady()) {
+                        conn.consumeInput(this.handler);
+                    }
+                    ssliosession.inboundTransport();
+                } catch (IOException ex) {
+                    this.handler.exception(conn, ex);
+                    ssliosession.shutdown();
+                }
+            }
         } catch (RuntimeException ex) {
             session.shutdown();
             throw ex;
@@ -183,7 +198,21 @@ public class DefaultClientIOEventDispatc
             NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
                     ExecutionContext.HTTP_CONNECTION);
             ensureNotNull(conn);
-            conn.produceOutput(this.handler);
+            SSLIOSession ssliosession = (SSLIOSession) session.getAttribute(
+                    IOSession.SSL_SESSION_KEY);
+            if (ssliosession == null) {
+                conn.produceOutput(this.handler);
+            } else {
+                try {
+                    if (ssliosession.isAppOutputReady()) {
+                        conn.produceOutput(this.handler);
+                    }
+                    ssliosession.outboundTransport();
+                } catch (IOException ex) {
+                    this.handler.exception(conn, ex);
+                    ssliosession.shutdown();
+                }
+            }
         } catch (RuntimeException ex) {
             session.shutdown();
             throw ex;
@@ -194,8 +223,20 @@ public class DefaultClientIOEventDispatc
         try {
             NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
                     ExecutionContext.HTTP_CONNECTION);
+            SSLIOSession ssliosession = (SSLIOSession) session.getAttribute(
+                    IOSession.SSL_SESSION_KEY);
             ensureNotNull(conn);
-            this.handler.timeout(conn);
+            if (ssliosession == null) {
+                this.handler.timeout(conn);
+            } else {
+                this.handler.timeout(conn);
+                synchronized (ssliosession) {
+                    if (ssliosession.isOutboundDone() && !ssliosession.isInboundDone()) {
+                        // The session failed to terminate cleanly
+                        ssliosession.shutdown();
+                    }
+                }
+            }
         } catch (RuntimeException ex) {
             session.shutdown();
             throw ex;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java Thu Sep  1 12:18:49 2011
@@ -27,10 +27,13 @@
 
 package org.apache.http.impl.nio;
 
+import java.io.IOException;
+
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestFactory;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.impl.DefaultHttpRequestFactory;
+import org.apache.http.impl.nio.reactor.SSLIOSession;
 import org.apache.http.nio.NHttpServerIOTarget;
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;
@@ -165,7 +168,21 @@ public class DefaultServerIOEventDispatc
             NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
                     ExecutionContext.HTTP_CONNECTION);
             ensureNotNull(conn);
-            conn.consumeInput(this.handler);
+            SSLIOSession ssliosession = (SSLIOSession) session.getAttribute(
+                    IOSession.SSL_SESSION_KEY);
+            if (ssliosession == null) {
+                conn.consumeInput(this.handler);
+            } else {
+                try {
+                    if (ssliosession.isAppInputReady()) {
+                        conn.consumeInput(this.handler);
+                    }
+                    ssliosession.inboundTransport();
+                } catch (IOException ex) {
+                    this.handler.exception(conn, ex);
+                    ssliosession.shutdown();
+                }
+            }
         } catch (RuntimeException ex) {
             session.shutdown();
             throw ex;
@@ -177,7 +194,21 @@ public class DefaultServerIOEventDispatc
             NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
                     ExecutionContext.HTTP_CONNECTION);
             ensureNotNull(conn);
-            conn.produceOutput(this.handler);
+            SSLIOSession ssliosession = (SSLIOSession) session.getAttribute(
+                    IOSession.SSL_SESSION_KEY);
+            if (ssliosession == null) {
+                conn.produceOutput(this.handler);
+            } else {
+                try {
+                    if (ssliosession.isAppOutputReady()) {
+                        conn.produceOutput(this.handler);
+                    }
+                    ssliosession.outboundTransport();
+                } catch (IOException ex) {
+                    this.handler.exception(conn, ex);
+                    ssliosession.shutdown();
+                }
+            }
         } catch (RuntimeException ex) {
             session.shutdown();
             throw ex;
@@ -189,7 +220,19 @@ public class DefaultServerIOEventDispatc
             NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
                     ExecutionContext.HTTP_CONNECTION);
             ensureNotNull(conn);
-            this.handler.timeout(conn);
+            SSLIOSession ssliosession = (SSLIOSession) session.getAttribute(
+                    IOSession.SSL_SESSION_KEY);
+            if (ssliosession == null) {
+                this.handler.timeout(conn);
+            } else {
+                this.handler.timeout(conn);
+                synchronized (ssliosession) {
+                    if (ssliosession.isOutboundDone() && !ssliosession.isInboundDone()) {
+                        // The session failed to terminate cleanly
+                        ssliosession.shutdown();
+                    }
+                }
+            }
         } catch (RuntimeException ex) {
             session.shutdown();
             throw ex;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java Thu Sep  1 12:18:49 2011
@@ -133,6 +133,9 @@ public class NHttpConnectionBase
         }
 
         int buffersize = HttpConnectionParams.getSocketBufferSize(params);
+        if (buffersize <= 0) {
+            buffersize = 4096;
+        }
         int linebuffersize = buffersize;
         if (linebuffersize > 512) {
             linebuffersize = 512;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnPool.java Thu Sep  1 12:18:49 2011
@@ -26,20 +26,33 @@
  */
 package org.apache.http.impl.nio.pool;
 
+import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
+import javax.net.ssl.SSLContext;
+
 import org.apache.http.HttpHost;
+import org.apache.http.HttpResponseFactory;
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.concurrent.FutureCallback;
+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.SSLMode;
+import org.apache.http.impl.nio.reactor.SSLSetupHandler;
+import org.apache.http.nio.NHttpClientConnection;
 import org.apache.http.nio.pool.AbstractNIOConnPool;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.ExecutionContext;
 
 /**
  * Basic non-blocking {@link IOSession} pool.
@@ -47,26 +60,66 @@ import org.apache.http.params.HttpParams
  * The following parameters can be used to customize the behavior of this
  * class:
  * <ul>
+ *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_TIMEOUT}</li>
  *  <li>{@link org.apache.http.params.CoreConnectionPNames#CONNECTION_TIMEOUT}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
+ *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
  * </ul>
  *
  * @since 4.2
  */
 @ThreadSafe
-public class BasicNIOConnPool extends AbstractNIOConnPool<HttpHost, IOSession, BasicNIOPoolEntry> {
+public class BasicNIOConnPool extends AbstractNIOConnPool<HttpHost, NHttpClientConnection, BasicNIOPoolEntry> {
 
     private static AtomicLong COUNTER = new AtomicLong();
 
+    private final HttpResponseFactory responseFactory;
+    private final ByteBufferAllocator allocator;
+    private final SSLContext sslcontext;
+    private final SSLSetupHandler sslHandler;
     private final HttpParams params;
 
-    public BasicNIOConnPool(final ConnectingIOReactor ioreactor, final HttpParams params) {
+    public BasicNIOConnPool(
+            final ConnectingIOReactor ioreactor,
+            final SSLContext sslcontext,
+            final SSLSetupHandler sslHandler,
+            final HttpResponseFactory responseFactory,
+            final ByteBufferAllocator allocator,
+            final HttpParams params) {
         super(ioreactor, 2, 20);
+        if (responseFactory == null) {
+            throw new IllegalArgumentException("HTTP response factory may not be null");
+        }
+        if (allocator == null) {
+            throw new IllegalArgumentException("Byte buffer allocator may not be null");
+        }
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
+        this.sslcontext = sslcontext;
+        this.sslHandler = sslHandler;
+        this.responseFactory = responseFactory;
+        this.allocator = allocator;
         this.params = params;
     }
 
+    public BasicNIOConnPool(
+            final ConnectingIOReactor ioreactor,
+            final SSLContext sslcontext,
+            final SSLSetupHandler sslHandler,
+            final HttpParams params) {
+        this(ioreactor, sslcontext, sslHandler,
+                new DefaultHttpResponseFactory(), new HeapByteBufferAllocator(), params);
+    }
+
+    public BasicNIOConnPool(
+            final ConnectingIOReactor ioreactor,
+            final HttpParams params) {
+        this(ioreactor, null, null, params);
+    }
+
     @Override
     protected SocketAddress resolveRemoteAddress(final HttpHost host) {
         return new InetSocketAddress(host.getHostName(), host.getPort());
@@ -77,20 +130,54 @@ public class BasicNIOConnPool extends Ab
         return null;
     }
 
+    private SSLContext getDefaultSSLContext() {
+        SSLContext sslcontext;
+        try {
+            sslcontext = SSLContext.getInstance("TLS");
+            sslcontext.init(null, null, null);
+        } catch (Exception ex) {
+            throw new IllegalStateException("Failure initializing default SSL context", ex);
+        }
+        return sslcontext;
+    }
+
     @Override
-    protected IOSession createConnection(final HttpHost route, final IOSession session) {
-        return session;
+    protected NHttpClientConnection createConnection(
+            final HttpHost route, final IOSession session) throws IOException {
+        IOSession connSession;
+        if (route.getSchemeName().equalsIgnoreCase("https")) {
+            SSLContext connSSLContext = this.sslcontext != null ? this.sslcontext : getDefaultSSLContext();
+            SSLIOSession ssliosession = new SSLIOSession(session, connSSLContext, this.sslHandler);
+            ssliosession.bind(SSLMode.CLIENT, this.params);
+            session.setAttribute(IOSession.SSL_SESSION_KEY, ssliosession);
+            connSession = ssliosession;
+        } else {
+            connSession = session;
+        }
+
+        NHttpClientConnection conn = new DefaultNHttpClientConnection(
+                connSession, this.responseFactory, this.allocator, this.params);
+
+        session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+
+        int timeout = HttpConnectionParams.getSoTimeout(this.params);
+        conn.setSocketTimeout(timeout);
+
+        return conn;
     }
 
     @Override
-    protected BasicNIOPoolEntry createEntry(final HttpHost host, final IOSession conn) {
+    protected BasicNIOPoolEntry createEntry(final HttpHost host, final NHttpClientConnection conn) {
         return new BasicNIOPoolEntry(Long.toString(COUNTER.getAndIncrement()), host, conn);
     }
 
     @Override
     protected void closeEntry(final BasicNIOPoolEntry entry) {
-        IOSession iosession = entry.getConnection();
-        iosession.shutdown();
+        NHttpClientConnection conn = entry.getConnection();
+        try {
+            conn.shutdown();
+        } catch (IOException ex) {
+        }
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java Thu Sep  1 12:18:49 2011
@@ -28,7 +28,7 @@ package org.apache.http.impl.nio.pool;
 
 import org.apache.http.HttpHost;
 import org.apache.http.annotation.ThreadSafe;
-import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.NHttpClientConnection;
 import org.apache.http.pool.PoolEntry;
 
 /**
@@ -37,9 +37,9 @@ import org.apache.http.pool.PoolEntry;
  * @since 4.2
  */
 @ThreadSafe
-public class BasicNIOPoolEntry extends PoolEntry<HttpHost, IOSession> {
+public class BasicNIOPoolEntry extends PoolEntry<HttpHost, NHttpClientConnection> {
 
-    public BasicNIOPoolEntry(final String id, final HttpHost route, final IOSession conn) {
+    public BasicNIOPoolEntry(final String id, final HttpHost route, final NHttpClientConnection conn) {
         super(id, route, conn);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLClientIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLClientIOEventDispatch.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLClientIOEventDispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLClientIOEventDispatch.java Thu Sep  1 12:18:49 2011
@@ -27,16 +27,11 @@
 
 package org.apache.http.impl.nio.ssl;
 
-import java.io.IOException;
-
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLException;
 
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpResponseFactory;
 import org.apache.http.annotation.Immutable;
-import org.apache.http.impl.DefaultHttpResponseFactory;
-import org.apache.http.impl.nio.DefaultNHttpClientConnection;
+import org.apache.http.impl.nio.DefaultClientIOEventDispatch;
 import org.apache.http.impl.nio.reactor.SSLIOSession;
 import org.apache.http.impl.nio.reactor.SSLMode;
 import org.apache.http.impl.nio.reactor.SSLSetupHandler;
@@ -44,8 +39,6 @@ import org.apache.http.nio.NHttpClientHa
 import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
-import org.apache.http.nio.util.ByteBufferAllocator;
-import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.ExecutionContext;
@@ -67,14 +60,10 @@ import org.apache.http.protocol.Executio
  * @since 4.1
  */
 @Immutable // provided injected dependencies are immutable
-public class SSLClientIOEventDispatch implements IOEventDispatch {
-
-    private static final String SSL_SESSION = "http.nio.ssl-session";
+public class SSLClientIOEventDispatch extends DefaultClientIOEventDispatch {
 
-    private final NHttpClientHandler handler;
     private final SSLContext sslcontext;
     private final SSLSetupHandler sslHandler;
-    private final HttpParams params;
 
     /**
      * Creates a new instance of this class to be used for dispatching I/O event
@@ -92,18 +81,13 @@ public class SSLClientIOEventDispatch im
             final SSLContext sslcontext,
             final SSLSetupHandler sslHandler,
             final HttpParams params) {
-        super();
-        if (handler == null) {
-            throw new IllegalArgumentException("HTTP client handler may not be null");
-        }
+        super(handler, params);
         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 = handler;
-        this.params = params;
         this.sslcontext = sslcontext;
         this.sslHandler = sslHandler;
     }
@@ -126,51 +110,6 @@ public class SSLClientIOEventDispatch im
     }
 
     /**
-     * Creates an instance of {@link HeapByteBufferAllocator} to be used
-     * by HTTP connections for allocating {@link java.nio.ByteBuffer} objects.
-     * <p>
-     * This method can be overridden in a super class in order to provide
-     * a different implementation of the {@link ByteBufferAllocator} interface.
-     *
-     * @return byte buffer allocator.
-     */
-    protected ByteBufferAllocator createByteBufferAllocator() {
-        return new HeapByteBufferAllocator();
-    }
-
-    /**
-     * Creates an instance of {@link DefaultHttpResponseFactory} to be used
-     * by HTTP connections for creating {@link HttpResponse} objects.
-     * <p>
-     * This method can be overridden in a super class in order to provide
-     * a different implementation of the {@link HttpResponseFactory} interface.
-     *
-     * @return HTTP response factory.
-     */
-    protected HttpResponseFactory createHttpResponseFactory() {
-        return new DefaultHttpResponseFactory();
-    }
-
-    /**
-     * Creates an instance of {@link DefaultNHttpClientConnection} based on the
-     * given SSL {@link IOSession}.
-     * <p>
-     * This method can be overridden in a super class in order to provide
-     * a different implementation of the {@link NHttpClientIOTarget} interface.
-     *
-     * @param session the underlying SSL I/O session.
-     *
-     * @return newly created HTTP connection.
-     */
-    protected NHttpClientIOTarget createConnection(final IOSession session) {
-        return new DefaultNHttpClientConnection(
-                session,
-                createHttpResponseFactory(),
-                createByteBufferAllocator(),
-                this.params);
-    }
-
-    /**
      * Creates an instance of {@link SSLIOSession} decorating the given
      * {@link IOSession}.
      * <p>
@@ -189,18 +128,29 @@ public class SSLClientIOEventDispatch im
         return new SSLIOSession(session, sslcontext, sslHandler);
     }
 
+    @Override
     public void connected(final IOSession session) {
         try {
-            SSLIOSession sslSession = createSSLIOSession(
-                    session,
-                    this.sslcontext,
-                    this.sslHandler);
 
-            NHttpClientIOTarget conn = createConnection(
-                    sslSession);
+            NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
+                    ExecutionContext.HTTP_CONNECTION);
 
-            session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
-            session.setAttribute(SSL_SESSION, sslSession);
+            if (conn == null) {
+                SSLIOSession ssliosession = createSSLIOSession(
+                        session,
+                        this.sslcontext,
+                        this.sslHandler);
+                session.setAttribute(IOSession.SSL_SESSION_KEY, ssliosession);
+                conn = createConnection(ssliosession);
+                session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+
+                try {
+                    ssliosession.bind(SSLMode.CLIENT, this.params);
+                } catch (SSLException ex) {
+                    this.handler.exception(conn, ex);
+                    ssliosession.shutdown();
+                }
+            }
 
             int timeout = HttpConnectionParams.getSoTimeout(this.params);
             conn.setSocketTimeout(timeout);
@@ -208,102 +158,6 @@ public class SSLClientIOEventDispatch im
             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();
-            }
-        } catch (RuntimeException ex) {
-            session.shutdown();
-            throw ex;
-        }
-    }
-
-    public void disconnected(final IOSession session) {
-        NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
-                ExecutionContext.HTTP_CONNECTION);
-        if (conn != null) {
-            this.handler.closed(conn);
-        }
-    }
-
-    private void ensureNotNull(final NHttpClientIOTarget conn) {
-        if (conn == null) {
-            throw new IllegalStateException("HTTP connection is null");
-        }
-    }
-
-    private void ensureNotNull(final SSLIOSession ssliosession) {
-        if (ssliosession == null) {
-            throw new IllegalStateException("SSL I/O session is null");
-        }
-    }
-
-    public void inputReady(final IOSession session) {
-        try {
-            NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
-                    ExecutionContext.HTTP_CONNECTION);
-            ensureNotNull(conn);
-            SSLIOSession sslSession =
-                (SSLIOSession) session.getAttribute(SSL_SESSION);
-            ensureNotNull(sslSession);
-
-            try {
-                if (sslSession.isAppInputReady()) {
-                    conn.consumeInput(this.handler);
-                }
-                sslSession.inboundTransport();
-            } catch (IOException ex) {
-                this.handler.exception(conn, ex);
-                sslSession.shutdown();
-            }
-        } catch (RuntimeException ex) {
-            session.shutdown();
-            throw ex;
-        }
-    }
-
-    public void outputReady(final IOSession session) {
-        try {
-            NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
-                    ExecutionContext.HTTP_CONNECTION);
-            ensureNotNull(conn);
-            SSLIOSession sslSession =
-                (SSLIOSession) session.getAttribute(SSL_SESSION);
-            ensureNotNull(sslSession);
-
-            try {
-                if (sslSession.isAppOutputReady()) {
-                    conn.produceOutput(this.handler);
-                }
-                sslSession.outboundTransport();
-            } catch (IOException ex) {
-                this.handler.exception(conn, ex);
-                sslSession.shutdown();
-            }
-        } catch (RuntimeException ex) {
-            session.shutdown();
-            throw ex;
-        }
-    }
-
-    public void timeout(final IOSession session) {
-        try {
-            NHttpClientIOTarget conn = (NHttpClientIOTarget) session.getAttribute(
-                    ExecutionContext.HTTP_CONNECTION);
-            ensureNotNull(conn);
-            SSLIOSession sslSession =
-                (SSLIOSession) session.getAttribute(SSL_SESSION);
-            ensureNotNull(sslSession);
-
-            this.handler.timeout(conn);
-            synchronized (sslSession) {
-                if (sslSession.isOutboundDone() && !sslSession.isInboundDone()) {
-                    // The session failed to terminate cleanly
-                    sslSession.shutdown();
-                }
-            }
         } catch (RuntimeException ex) {
             session.shutdown();
             throw ex;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLServerIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLServerIOEventDispatch.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLServerIOEventDispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLServerIOEventDispatch.java Thu Sep  1 12:18:49 2011
@@ -27,16 +27,11 @@
 
 package org.apache.http.impl.nio.ssl;
 
-import java.io.IOException;
-
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLException;
 
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpRequestFactory;
 import org.apache.http.annotation.Immutable;
-import org.apache.http.impl.DefaultHttpRequestFactory;
-import org.apache.http.impl.nio.DefaultNHttpServerConnection;
+import org.apache.http.impl.nio.DefaultServerIOEventDispatch;
 import org.apache.http.impl.nio.reactor.SSLIOSession;
 import org.apache.http.impl.nio.reactor.SSLMode;
 import org.apache.http.impl.nio.reactor.SSLSetupHandler;
@@ -44,8 +39,6 @@ import org.apache.http.nio.NHttpServerIO
 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.ByteBufferAllocator;
-import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.ExecutionContext;
@@ -67,14 +60,10 @@ import org.apache.http.protocol.Executio
  * @since 4.1
  */
 @Immutable // provided injected dependencies are immutable
-public class SSLServerIOEventDispatch implements IOEventDispatch {
-
-    private static final String SSL_SESSION = "http.nio.ssl-session";
+public class SSLServerIOEventDispatch extends DefaultServerIOEventDispatch {
 
-    private final NHttpServiceHandler handler;
     private final SSLContext sslcontext;
     private final SSLSetupHandler sslHandler;
-    private final HttpParams params;
 
     /**
      * Creates a new instance of this class to be used for dispatching I/O event
@@ -92,18 +81,13 @@ public class SSLServerIOEventDispatch im
             final SSLContext sslcontext,
             final SSLSetupHandler sslHandler,
             final HttpParams params) {
-        super();
-        if (handler == null) {
-            throw new IllegalArgumentException("HTTP service handler may not be null");
-        }
+        super(handler, params);
         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 = handler;
-        this.params = params;
         this.sslcontext = sslcontext;
         this.sslHandler = sslHandler;
     }
@@ -126,51 +110,6 @@ public class SSLServerIOEventDispatch im
     }
 
     /**
-     * Creates an instance of {@link HeapByteBufferAllocator} to be used
-     * by HTTP connections for allocating {@link java.nio.ByteBuffer} objects.
-     * <p>
-     * This method can be overridden in a super class in order to provide
-     * a different implementation of the {@link ByteBufferAllocator} interface.
-     *
-     * @return byte buffer allocator.
-     */
-    protected ByteBufferAllocator createByteBufferAllocator() {
-        return new HeapByteBufferAllocator();
-    }
-
-    /**
-     * Creates an instance of {@link DefaultHttpRequestFactory} to be used
-     * by HTTP connections for creating {@link HttpRequest} objects.
-     * <p>
-     * This method can be overridden in a super class in order to provide
-     * a different implementation of the {@link HttpRequestFactory} interface.
-     *
-     * @return HTTP request factory.
-     */
-    protected HttpRequestFactory createHttpRequestFactory() {
-        return new DefaultHttpRequestFactory();
-    }
-
-    /**
-     * Creates an instance of {@link DefaultNHttpServerConnection} based on the
-     * given {@link IOSession}.
-     * <p>
-     * This method can be overridden in a super class in order to provide
-     * a different implementation of the {@link NHttpServerIOTarget} interface.
-     *
-     * @param session the underlying SSL I/O session.
-     *
-     * @return newly created HTTP connection.
-     */
-    protected NHttpServerIOTarget createConnection(final IOSession session) {
-        return new DefaultNHttpServerConnection(
-                session,
-                createHttpRequestFactory(),
-                createByteBufferAllocator(),
-                this.params);
-    }
-
-    /**
      * Creates an instance of {@link SSLIOSession} decorating the given
      * {@link IOSession}.
      * <p>
@@ -191,16 +130,14 @@ public class SSLServerIOEventDispatch im
 
     public void connected(final IOSession session) {
         try {
-            SSLIOSession sslSession = createSSLIOSession(
+
+            SSLIOSession ssliosession = createSSLIOSession(
                     session,
                     this.sslcontext,
                     this.sslHandler);
-
-            NHttpServerIOTarget conn = createConnection(
-                    sslSession);
-
+            session.setAttribute(IOSession.SSL_SESSION_KEY, ssliosession);
+            NHttpServerIOTarget conn = createConnection(ssliosession);
             session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
-            session.setAttribute(SSL_SESSION, sslSession);
 
             int timeout = HttpConnectionParams.getSoTimeout(this.params);
             conn.setSocketTimeout(timeout);
@@ -208,100 +145,10 @@ public class SSLServerIOEventDispatch im
             this.handler.connected(conn);
 
             try {
-                sslSession.bind(SSLMode.SERVER, this.params);
+                ssliosession.bind(SSLMode.SERVER, this.params);
             } catch (SSLException ex) {
                 this.handler.exception(conn, ex);
-                sslSession.shutdown();
-            }
-        } catch (RuntimeException ex) {
-            session.shutdown();
-            throw ex;
-        }
-    }
-
-    public void disconnected(final IOSession session) {
-        NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
-                ExecutionContext.HTTP_CONNECTION);
-        if (conn != null) {
-            this.handler.closed(conn);
-        }
-    }
-
-    private void ensureNotNull(final NHttpServerIOTarget conn) {
-        if (conn == null) {
-            throw new IllegalStateException("HTTP connection is null");
-        }
-    }
-
-    private void ensureNotNull(final SSLIOSession ssliosession) {
-        if (ssliosession == null) {
-            throw new IllegalStateException("SSL I/O session is null");
-        }
-    }
-
-    public void inputReady(final IOSession session) {
-        try {
-            NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
-                    ExecutionContext.HTTP_CONNECTION);
-            ensureNotNull(conn);
-            SSLIOSession sslSession =
-                (SSLIOSession) session.getAttribute(SSL_SESSION);
-            ensureNotNull(sslSession);
-
-            try {
-                if (sslSession.isAppInputReady()) {
-                    conn.consumeInput(this.handler);
-                }
-                sslSession.inboundTransport();
-            } catch (IOException ex) {
-                this.handler.exception(conn, ex);
-                sslSession.shutdown();
-            }
-        } catch (RuntimeException ex) {
-            session.shutdown();
-            throw ex;
-        }
-    }
-
-    public void outputReady(final IOSession session) {
-        try {
-            NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
-                    ExecutionContext.HTTP_CONNECTION);
-            ensureNotNull(conn);
-            SSLIOSession sslSession =
-                (SSLIOSession) session.getAttribute(SSL_SESSION);
-            ensureNotNull(sslSession);
-
-            try {
-                if (sslSession.isAppOutputReady()) {
-                    conn.produceOutput(this.handler);
-                }
-                sslSession.outboundTransport();
-            } catch (IOException ex) {
-                this.handler.exception(conn, ex);
-                sslSession.shutdown();
-            }
-        } catch (RuntimeException ex) {
-            session.shutdown();
-            throw ex;
-        }
-    }
-
-    public void timeout(final IOSession session) {
-        try {
-            NHttpServerIOTarget conn = (NHttpServerIOTarget) session.getAttribute(
-                    ExecutionContext.HTTP_CONNECTION);
-            ensureNotNull(conn);
-            SSLIOSession sslSession =
-                (SSLIOSession) session.getAttribute(SSL_SESSION);
-            ensureNotNull(sslSession);
-
-            this.handler.timeout(conn);
-            synchronized (sslSession) {
-                if (sslSession.isOutboundDone() && !sslSession.isInboundDone()) {
-                    // The session failed to cleanly terminate
-                    sslSession.shutdown();
-                }
+                ssliosession.shutdown();
             }
         } catch (RuntimeException ex) {
             session.shutdown();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java Thu Sep  1 12:18:49 2011
@@ -109,7 +109,7 @@ public abstract class AbstractNIOConnPoo
 
     protected abstract SocketAddress resolveLocalAddress(T route);
 
-    protected abstract C createConnection(T route, IOSession session);
+    protected abstract C createConnection(T route, IOSession session) throws IOException;
 
     protected abstract E createEntry(T route, C conn);
 
@@ -345,9 +345,13 @@ public abstract class AbstractNIOConnPoo
             this.pending.remove(request);
             RouteSpecificPool<T, C, E> pool = getPool(route);
             IOSession session = request.getSession();
-            C conn = createConnection(route, session);
-            E entry = pool.completed(request, conn);
-            this.leased.add(entry);
+            try {
+                C conn = createConnection(route, session);
+                E entry = pool.completed(request, conn);
+                this.leased.add(entry);
+            } catch (IOException ex) {
+                pool.failed(request, ex);
+            }
         } finally {
             this.lock.unlock();
         }
@@ -379,7 +383,7 @@ public abstract class AbstractNIOConnPoo
         try {
             this.pending.remove(request);
             RouteSpecificPool<T, C, E> pool = getPool(route);
-            pool.failed(request);
+            pool.failed(request, request.getException());
         } finally {
             this.lock.unlock();
         }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java Thu Sep  1 12:18:49 2011
@@ -162,9 +162,9 @@ abstract class RouteSpecificPool<T, C, E
         future.cancel(true);
     }
 
-    public void failed(final SessionRequest request) {
+    public void failed(final SessionRequest request, final Exception ex) {
         BasicFuture<E> future = removeRequest(request);
-        future.failed(request.getException());
+        future.failed(ex);
     }
 
     public void timeout(final SessionRequest request) {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java Thu Sep  1 12:18:49 2011
@@ -54,6 +54,12 @@ public interface IOSession {
      */
     public static final String ATTACHMENT_KEY = "http.session.attachment";
 
+    /**
+     * Name of the context attribute key, which can be used to obtain the
+     * SSL session.
+     */
+    public static final String SSL_SESSION_KEY = "http.session.ssl";
+
     public static final int ACTIVE       = 0;
     public static final int CLOSING      = 1;
     public static final int CLOSED       = Integer.MAX_VALUE;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/pool/TestBasicNIOConnPool.java Thu Sep  1 12:18:49 2011
@@ -26,8 +26,8 @@
  */
 package org.apache.http.impl.nio.pool;
 
-
 import org.apache.http.HttpHost;
+import org.apache.http.nio.NHttpClientConnection;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.params.BasicHttpParams;
@@ -74,7 +74,7 @@ public class TestBasicNIOConnPool {
 
     @Test
     public void testCreateEntry() throws Exception {
-        IOSession conn = pool.createConnection(route, session);
+        NHttpClientConnection conn = pool.createConnection(route, session);
         BasicNIOPoolEntry entry = pool.createEntry(route, conn);
 
         pool.closeEntry(entry);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java?rev=1164033&r1=1164032&r2=1164033&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestRouteSpecificPool.java Thu Sep  1 12:18:49 2011
@@ -107,14 +107,13 @@ public class TestRouteSpecificPool {
     public void testFailedConnect() throws Exception {
         LocalRoutePool pool = new LocalRoutePool();
         SessionRequest sessionRequest = Mockito.mock(SessionRequest.class);
-        Mockito.when(sessionRequest.getException()).thenReturn(new IOException());
         BasicFuture<LocalPoolEntry> future = new BasicFuture<LocalPoolEntry>(null);
         pool.addPending(sessionRequest, future);
         Assert.assertEquals(1, pool.getAllocatedCount());
         Assert.assertEquals(0, pool.getAvailableCount());
         Assert.assertEquals(0, pool.getLeasedCount());
         Assert.assertEquals(1, pool.getPendingCount());
-        pool.failed(sessionRequest);
+        pool.failed(sessionRequest, new IOException());
         Assert.assertTrue(future.isDone());
         Assert.assertFalse(future.isCancelled());
         try {



Mime
View raw message