hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1164860 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http: impl/nio/ nio/ nio/reactor/ssl/
Date Sat, 03 Sep 2011 13:04:50 GMT
Author: olegk
Date: Sat Sep  3 13:04:49 2011
New Revision: 1164860

URL: http://svn.apache.org/viewvc?rev=1164860&view=rev
Log:
SSL I/O session initialization is now handled by the I/O event dispatch

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/SSLNHttpClientConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.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=1164860&r1=1164859&r2=1164860&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
Sat Sep  3 13:04:49 2011
@@ -74,6 +74,18 @@ public abstract class AbstractIODispatch
                 session.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
             }
             onConnected(conn);
+            SSLIOSession ssliosession = (SSLIOSession) session.getAttribute(
+                    SSLIOSession.SESSION_KEY);
+            if (ssliosession != null) {
+                try {
+                    if (!ssliosession.isInitialized()) {
+                        ssliosession.initialize();
+                    }
+                } catch (IOException ex) {
+                    onException(conn, ex);
+                    ssliosession.shutdown();
+                }
+            }
         } catch (RuntimeException ex) {
             session.shutdown();
             throw ex;
@@ -99,6 +111,9 @@ public abstract class AbstractIODispatch
             	onInputReady(conn);
             } else {
                 try {
+                    if (!ssliosession.isInitialized()) {
+                        ssliosession.initialize();
+                    }
                     if (ssliosession.isAppInputReady()) {
                     	onInputReady(conn);
                     }
@@ -125,6 +140,9 @@ public abstract class AbstractIODispatch
                 onOutputReady(conn);
             } else {
                 try {
+                    if (!ssliosession.isInitialized()) {
+                        ssliosession.initialize();
+                    }
                     if (ssliosession.isAppOutputReady()) {
                         onOutputReady(conn);
                     }
@@ -147,10 +165,8 @@ public abstract class AbstractIODispatch
             SSLIOSession ssliosession = (SSLIOSession) session.getAttribute(
                     SSLIOSession.SESSION_KEY);
             ensureNotNull(conn);
-            if (ssliosession == null) {
-                onTimeout(conn);
-            } else {
-            	onTimeout(conn);
+            onTimeout(conn);
+            if (ssliosession != null) {
                 synchronized (ssliosession) {
                     if (ssliosession.isOutboundDone() && !ssliosession.isInboundDone())
{
                         // The session failed to terminate cleanly

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java?rev=1164860&r1=1164859&r2=1164860&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java
Sat Sep  3 13:04:49 2011
@@ -26,8 +26,6 @@
  */
 package org.apache.http.impl.nio;
 
-import java.io.IOException;
-
 import javax.net.ssl.SSLContext;
 
 import org.apache.http.HttpResponseFactory;
@@ -115,14 +113,13 @@ public class SSLNHttpClientConnectionFac
             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 createConnection(final IOSession session) throws IOException
{
+    public NHttpClientConnection createConnection(final IOSession session) {
         SSLContext sslcontext = this.sslcontext != null ? this.sslcontext : getDefaultSSLContext();
         SSLIOSession ssliosession = new SSLIOSession(session, SSLMode.CLIENT, sslcontext,
this.sslHandler);
-        ssliosession.initialize();
         session.setAttribute(SSLIOSession.SESSION_KEY, ssliosession);
         return createConnection(ssliosession, this.responseFactory, this.allocator, this.params);
     }

Modified: 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=1164860&r1=1164859&r2=1164860&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
Sat Sep  3 13:04:49 2011
@@ -26,8 +26,6 @@
  */
 package org.apache.http.impl.nio;
 
-import java.io.IOException;
-
 import javax.net.ssl.SSLContext;
 
 import org.apache.http.HttpRequestFactory;
@@ -115,14 +113,13 @@ public class SSLNHttpServerConnectionFac
             final IOSession session,
             final HttpRequestFactory requestFactory,
             final ByteBufferAllocator allocator,
-            final HttpParams params) throws IOException {
+            final HttpParams params) {
         return new DefaultNHttpServerConnection(session, requestFactory, allocator, params);
     }
 
-    public NHttpServerConnection createConnection(final IOSession session) throws IOException
{
+    public NHttpServerConnection createConnection(final IOSession session) {
         SSLContext sslcontext = this.sslcontext != null ? this.sslcontext : getDefaultSSLContext();
         SSLIOSession ssliosession = new SSLIOSession(session, SSLMode.CLIENT, sslcontext,
this.sslHandler);
-        ssliosession.initialize();
         session.setAttribute(SSLIOSession.SESSION_KEY, ssliosession);
         return createConnection(ssliosession, this.requestFactory, this.allocator, this.params);
     }

Modified: 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=1164860&r1=1164859&r2=1164860&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpConnectionFactory.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpConnectionFactory.java
Sat Sep  3 13:04:49 2011
@@ -27,8 +27,6 @@
 
 package org.apache.http.nio;
 
-import java.io.IOException;
-
 import org.apache.http.nio.reactor.IOSession;
 
 /**
@@ -36,6 +34,6 @@ import org.apache.http.nio.reactor.IOSes
  */
 public interface NHttpConnectionFactory<T extends NHttpConnection> {
 
-	T createConnection(IOSession session) throws IOException;
+	T createConnection(IOSession session);
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java?rev=1164860&r1=1164859&r2=1164860&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
Sat Sep  3 13:04:49 2011
@@ -76,6 +76,7 @@ public class SSLIOSession implements IOS
 
     private boolean endOfStream;
     private volatile int status;
+    private volatile boolean initialized;
 
     public SSLIOSession(
             final IOSession session,
@@ -122,7 +123,14 @@ public class SSLIOSession implements IOS
         return this.handler;
     }
 
+    public boolean isInitialized() {
+        return this.initialized;
+    }
+
     public synchronized void initialize(final SSLMode mode) throws SSLException {
+        if (this.initialized) {
+            throw new IllegalStateException("SSL I/O session already initialized");
+        }
         switch (mode) {
         case CLIENT:
             this.sslEngine.setUseClientMode(true);
@@ -134,6 +142,7 @@ public class SSLIOSession implements IOS
         if (this.handler != null) {
             this.handler.initalize(this.sslEngine);
         }
+        this.initialized = true;
         this.sslEngine.beginHandshake();
         doHandshake();
     }



Mime
View raw message