You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/09/02 15:32:21 UTC

svn commit: r1164526 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http: impl/nio/ impl/nio/pool/ impl/nio/ssl/ nio/

Author: olegk
Date: Fri Sep  2 13:32:19 2011
New Revision: 1164526

URL: http://svn.apache.org/viewvc?rev=1164526&view=rev
Log:
Non-blocking HTTP connection factory implementations

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java
      - copied, changed from r1164404, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java
      - copied, changed from r1164404, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpConnectionFactory.java   (with props)
Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/AbstractIODispatch.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/ssl/SSLServerIOEventDispatch.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/AbstractIODispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/AbstractIODispatch.java?rev=1164526&r1=1164525&r2=1164526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/AbstractIODispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/AbstractIODispatch.java Fri Sep  2 13:32:19 2011
@@ -37,7 +37,7 @@ import org.apache.http.nio.reactor.IOSes
 import org.apache.http.protocol.ExecutionContext;
 
 /**
- * Abstract {@link IOEventDispatch} implementation that supports both plain (unencrypted)
+ * Abstract {@link IOEventDispatch} implementation that supports both plain (non-encrypted)
  * and SSL encrypted HTTP connections.
  *
  * @since 4.2

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java (from r1164404, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java&p1=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java&r1=1164404&r2=1164526&rev=1164526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java Fri Sep  2 13:32:19 2011
@@ -24,38 +24,25 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.nio.pool;
+package org.apache.http.impl.nio;
 
-import java.io.IOException;
-
-import javax.net.ssl.SSLContext;
-
-import org.apache.http.HttpHost;
 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.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.NIOConnFactory;
+import org.apache.http.nio.NHttpConnectionFactory;
 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 NHttpClientConnection} factory.
+ * Plain (non-encrypted) {@link NHttpClientConnection} factory.
  * <p>
  * 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>
@@ -64,17 +51,13 @@ import org.apache.http.protocol.Executio
  * @since 4.2
  */
 @Immutable
-public class BasicNIOConnFactory implements NIOConnFactory<HttpHost, NHttpClientConnection> {
+public class DefaultNHttpClientConnectionFactory implements NHttpConnectionFactory<NHttpClientConnection> {
 
     private final HttpResponseFactory responseFactory;
     private final ByteBufferAllocator allocator;
-    private final SSLContext sslcontext;
-    private final SSLSetupHandler sslHandler;
     private final HttpParams params;
 
-    public BasicNIOConnFactory(
-            final SSLContext sslcontext,
-            final SSLSetupHandler sslHandler,
+    public DefaultNHttpClientConnectionFactory(
             final HttpResponseFactory responseFactory,
             final ByteBufferAllocator allocator,
             final HttpParams params) {
@@ -88,64 +71,25 @@ public class BasicNIOConnFactory impleme
         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 BasicNIOConnFactory(
-            final SSLContext sslcontext,
-            final SSLSetupHandler sslHandler,
-            final HttpParams params) {
-        this(sslcontext, sslHandler, new DefaultHttpResponseFactory(), new HeapByteBufferAllocator(), params);
-    }
-
-    public BasicNIOConnFactory(final HttpParams params) {
-        this(null, null, params);
-    }
-
-    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;
+    public DefaultNHttpClientConnectionFactory(final HttpParams params) {
+        this(new DefaultHttpResponseFactory(), new HeapByteBufferAllocator(), params);
     }
 
-    protected NHttpClientConnection create(
+    protected NHttpClientConnection createConnection(
             final IOSession session,
             final HttpResponseFactory responseFactory,
             final ByteBufferAllocator allocator,
-            final HttpParams params) throws IOException {
+            final HttpParams params) {
         return new DefaultNHttpClientConnection(session, responseFactory, allocator, params);
     }
 
-    public NHttpClientConnection create(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 = create(connSession,
-                this.responseFactory, this.allocator, this.params);
-
-        session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
-
-        int timeout = HttpConnectionParams.getSoTimeout(this.params);
-        conn.setSocketTimeout(timeout);
-
-        return conn;
+    public NHttpClientConnection createConnection(final IOSession session) {
+        return createConnection(session, this.responseFactory, this.allocator, this.params);
     }
 
 }

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java?rev=1164526&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java Fri Sep  2 13:32:19 2011
@@ -0,0 +1,95 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.nio;
+
+import org.apache.http.HttpRequestFactory;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.impl.DefaultHttpRequestFactory;
+import org.apache.http.nio.NHttpConnectionFactory;
+import org.apache.http.nio.NHttpServerConnection;
+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.HttpParams;
+
+/**
+ * Plain (non-encrypted) {@link NHttpServerConnection} factory.
+ * <p>
+ * 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#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
+ */
+@Immutable
+public class DefaultNHttpServerConnectionFactory implements NHttpConnectionFactory<NHttpServerConnection> {
+
+    private final HttpRequestFactory requestFactory;
+    private final ByteBufferAllocator allocator;
+    private final HttpParams params;
+
+    public DefaultNHttpServerConnectionFactory(
+            final HttpRequestFactory requestFactory,
+            final ByteBufferAllocator allocator,
+            final HttpParams params) {
+        super();
+        if (requestFactory == null) {
+            throw new IllegalArgumentException("HTTP request 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.requestFactory = requestFactory;
+        this.allocator = allocator;
+        this.params = params;
+    }
+
+    public DefaultNHttpServerConnectionFactory(final HttpParams params) {
+        this(new DefaultHttpRequestFactory(), new HeapByteBufferAllocator(), params);
+    }
+
+    protected NHttpServerConnection createConnection(
+            final IOSession session,
+            final HttpRequestFactory requestFactory,
+            final ByteBufferAllocator allocator,
+            final HttpParams params) {
+        return new DefaultNHttpServerConnection(session, requestFactory, allocator, params);
+    }
+
+    public NHttpServerConnection createConnection(final IOSession session) {
+        return createConnection(session, this.requestFactory, this.allocator, this.params);
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java (from r1164404, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java&p1=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java&r1=1164404&r2=1164526&rev=1164526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java Fri Sep  2 13:32:19 2011
@@ -24,38 +24,32 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.impl.nio.pool;
+package org.apache.http.impl.nio;
 
 import java.io.IOException;
 
 import javax.net.ssl.SSLContext;
 
-import org.apache.http.HttpHost;
 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.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.NIOConnFactory;
+import org.apache.http.nio.NHttpConnectionFactory;
 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 NHttpClientConnection} factory.
+ * SSL encrypted non-blocking {@link NHttpClientConnection} factory.
  * <p>
  * 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>
@@ -64,7 +58,7 @@ import org.apache.http.protocol.Executio
  * @since 4.2
  */
 @Immutable
-public class BasicNIOConnFactory implements NIOConnFactory<HttpHost, NHttpClientConnection> {
+public class SSLNHttpClientConnectionFactory implements NHttpConnectionFactory<NHttpClientConnection> {
 
     private final HttpResponseFactory responseFactory;
     private final ByteBufferAllocator allocator;
@@ -72,7 +66,7 @@ public class BasicNIOConnFactory impleme
     private final SSLSetupHandler sslHandler;
     private final HttpParams params;
 
-    public BasicNIOConnFactory(
+    public SSLNHttpClientConnectionFactory(
             final SSLContext sslcontext,
             final SSLSetupHandler sslHandler,
             final HttpResponseFactory responseFactory,
@@ -95,14 +89,14 @@ public class BasicNIOConnFactory impleme
         this.params = params;
     }
 
-    public BasicNIOConnFactory(
+    public SSLNHttpClientConnectionFactory(
             final SSLContext sslcontext,
             final SSLSetupHandler sslHandler,
             final HttpParams params) {
         this(sslcontext, sslHandler, new DefaultHttpResponseFactory(), new HeapByteBufferAllocator(), params);
     }
 
-    public BasicNIOConnFactory(final HttpParams params) {
+    public SSLNHttpClientConnectionFactory(final HttpParams params) {
         this(null, null, params);
     }
 
@@ -117,7 +111,7 @@ public class BasicNIOConnFactory impleme
         return sslcontext;
     }
 
-    protected NHttpClientConnection create(
+    protected NHttpClientConnection createConnection(
             final IOSession session,
             final HttpResponseFactory responseFactory,
             final ByteBufferAllocator allocator,
@@ -125,27 +119,12 @@ public class BasicNIOConnFactory impleme
         return new DefaultNHttpClientConnection(session, responseFactory, allocator, params);
     }
 
-    public NHttpClientConnection create(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 = create(connSession,
-                this.responseFactory, this.allocator, this.params);
-
-        session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
-
-        int timeout = HttpConnectionParams.getSoTimeout(this.params);
-        conn.setSocketTimeout(timeout);
-
-        return conn;
+    public NHttpClientConnection createConnection(final IOSession session) throws IOException {
+        SSLContext sslcontext = this.sslcontext != null ? this.sslcontext : getDefaultSSLContext();
+        SSLIOSession ssliosession = new SSLIOSession(session, sslcontext, this.sslHandler);
+        ssliosession.bind(SSLMode.CLIENT, this.params);
+        session.setAttribute(IOSession.SSL_SESSION_KEY, ssliosession);
+        return createConnection(ssliosession, this.responseFactory, this.allocator, this.params);
     }
 
 }

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java?rev=1164526&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java Fri Sep  2 13:32:19 2011
@@ -0,0 +1,130 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.nio;
+
+import java.io.IOException;
+
+import javax.net.ssl.SSLContext;
+
+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.impl.nio.reactor.SSLMode;
+import org.apache.http.impl.nio.reactor.SSLSetupHandler;
+import org.apache.http.nio.NHttpConnectionFactory;
+import org.apache.http.nio.NHttpServerConnection;
+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.HttpParams;
+
+/**
+ * SSL encrypted non-blocking {@link NHttpServerConnection} factory.
+ * <p>
+ * 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#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
+ */
+@Immutable
+public class SSLNHttpServerConnectionFactory implements NHttpConnectionFactory<NHttpServerConnection> {
+
+    private final HttpRequestFactory requestFactory;
+    private final ByteBufferAllocator allocator;
+    private final SSLContext sslcontext;
+    private final SSLSetupHandler sslHandler;
+    private final HttpParams params;
+
+    public SSLNHttpServerConnectionFactory(
+            final SSLContext sslcontext,
+            final SSLSetupHandler sslHandler,
+            final HttpRequestFactory requestFactory,
+            final ByteBufferAllocator allocator,
+            final HttpParams params) {
+        super();
+        if (requestFactory == null) {
+            throw new IllegalArgumentException("HTTP request 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.requestFactory = requestFactory;
+        this.allocator = allocator;
+        this.params = params;
+    }
+
+    public SSLNHttpServerConnectionFactory(
+            final SSLContext sslcontext,
+            final SSLSetupHandler sslHandler,
+            final HttpParams params) {
+        this(sslcontext, sslHandler, new DefaultHttpRequestFactory(), new HeapByteBufferAllocator(), params);
+    }
+
+    public SSLNHttpServerConnectionFactory(final HttpParams params) {
+        this(null, null, params);
+    }
+
+    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;
+    }
+
+    protected NHttpServerConnection createConnection(
+            final IOSession session,
+            final HttpRequestFactory requestFactory,
+            final ByteBufferAllocator allocator,
+            final HttpParams params) throws IOException {
+        return new DefaultNHttpServerConnection(session, requestFactory, allocator, params);
+    }
+
+    public NHttpServerConnection createConnection(final IOSession session) throws IOException {
+        SSLContext sslcontext = this.sslcontext != null ? this.sslcontext : getDefaultSSLContext();
+        SSLIOSession ssliosession = new SSLIOSession(session, sslcontext, this.sslHandler);
+        ssliosession.bind(SSLMode.CLIENT, this.params);
+        session.setAttribute(IOSession.SSL_SESSION_KEY, ssliosession);
+        return createConnection(ssliosession, this.requestFactory, this.allocator, this.params);
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java?rev=1164526&r1=1164525&r2=1164526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java Fri Sep  2 13:32:19 2011
@@ -34,16 +34,15 @@ import org.apache.http.HttpHost;
 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.reactor.SSLIOSession;
-import org.apache.http.impl.nio.reactor.SSLMode;
+import org.apache.http.impl.nio.DefaultNHttpClientConnectionFactory;
+import org.apache.http.impl.nio.SSLNHttpClientConnectionFactory;
 import org.apache.http.impl.nio.reactor.SSLSetupHandler;
 import org.apache.http.nio.NHttpClientConnection;
+import org.apache.http.nio.NHttpConnectionFactory;
 import org.apache.http.nio.pool.NIOConnFactory;
 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;
 
@@ -54,8 +53,6 @@ import org.apache.http.protocol.Executio
  * 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>
@@ -66,11 +63,22 @@ import org.apache.http.protocol.Executio
 @Immutable
 public class BasicNIOConnFactory implements NIOConnFactory<HttpHost, NHttpClientConnection> {
 
-    private final HttpResponseFactory responseFactory;
-    private final ByteBufferAllocator allocator;
-    private final SSLContext sslcontext;
-    private final SSLSetupHandler sslHandler;
-    private final HttpParams params;
+    private final NHttpConnectionFactory<NHttpClientConnection> plainFactory;
+    private final NHttpConnectionFactory<NHttpClientConnection> sslFactory;
+
+    public BasicNIOConnFactory(
+            final NHttpConnectionFactory<NHttpClientConnection> plainFactory,
+            final NHttpConnectionFactory<NHttpClientConnection> sslFactory) {
+        super();
+        if (plainFactory == null) {
+        	throw new IllegalArgumentException("Plain HTTP client connection factory may not be null");
+        }
+        if (sslFactory == null) {
+        	throw new IllegalArgumentException("SSL HTTP client connection factory may not be null");
+        }
+        this.plainFactory = plainFactory;
+        this.sslFactory = sslFactory;
+    }
 
     public BasicNIOConnFactory(
             final SSLContext sslcontext,
@@ -78,73 +86,32 @@ public class BasicNIOConnFactory impleme
             final HttpResponseFactory responseFactory,
             final ByteBufferAllocator allocator,
             final HttpParams params) {
-        super();
-        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;
+        this(new DefaultNHttpClientConnectionFactory(
+                responseFactory, allocator, params),
+                new SSLNHttpClientConnectionFactory(
+                        sslcontext, sslHandler, responseFactory, allocator, params));
     }
 
     public BasicNIOConnFactory(
             final SSLContext sslcontext,
             final SSLSetupHandler sslHandler,
             final HttpParams params) {
-        this(sslcontext, sslHandler, new DefaultHttpResponseFactory(), new HeapByteBufferAllocator(), params);
+        this(sslcontext, sslHandler,
+                new DefaultHttpResponseFactory(), new HeapByteBufferAllocator(), params);
     }
 
     public BasicNIOConnFactory(final HttpParams params) {
         this(null, null, params);
     }
 
-    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;
-    }
-
-    protected NHttpClientConnection create(
-            final IOSession session,
-            final HttpResponseFactory responseFactory,
-            final ByteBufferAllocator allocator,
-            final HttpParams params) throws IOException {
-        return new DefaultNHttpClientConnection(session, responseFactory, allocator, params);
-    }
-
     public NHttpClientConnection create(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;
+    	NHttpClientConnection conn;
+    	if (route.getSchemeName().equalsIgnoreCase("https")) {
+        	conn = this.sslFactory.createConnection(session);
         } else {
-            connSession = session;
+        	conn = this.plainFactory.createConnection(session);
         }
-
-        NHttpClientConnection conn = create(connSession,
-                this.responseFactory, this.allocator, this.params);
-
         session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
-
-        int timeout = HttpConnectionParams.getSoTimeout(this.params);
-        conn.setSocketTimeout(timeout);
-
         return conn;
     }
 

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=1164526&r1=1164525&r2=1164526&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 Fri Sep  2 13:32:19 2011
@@ -35,7 +35,6 @@ import org.apache.http.impl.nio.DefaultS
 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.NHttpClientIOTarget;
 import org.apache.http.nio.NHttpServerIOTarget;
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpConnectionFactory.java?rev=1164526&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpConnectionFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpConnectionFactory.java Fri Sep  2 13:32:19 2011
@@ -0,0 +1,41 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.nio;
+
+import java.io.IOException;
+
+import org.apache.http.nio.reactor.IOSession;
+
+/**
+ * @since 4.2
+ */
+public interface NHttpConnectionFactory<T extends NHttpConnection> {
+
+	T createConnection(IOSession session) throws IOException;
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpConnectionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpConnectionFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpConnectionFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain