geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r603885 - in /geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc: AsyncHttpClient.java codec/HttpRequestMessage.java
Date Thu, 13 Dec 2007 11:12:51 GMT
Author: rickmcguire
Date: Thu Dec 13 03:12:43 2007
New Revision: 603885

URL: http://svn.apache.org/viewvc?rev=603885&view=rev
Log:
GERONIMO-3703 should allow custom SSL context for AsyncHttpClient

Patch provided by Sangjin Lee. 


Modified:
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java?rev=603885&r1=603884&r2=603885&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java Thu
Dec 13 03:12:43 2007
@@ -108,9 +108,6 @@
     /** The HttpIoHandler handler. */
     private final HttpIoHandler handler;
 
-    /** The ssl filter. */
-    private SSLFilter sslFilter;
-    
     /** connection reuse option */
     private volatile boolean reuseConnection = DEFAULT_REUSE_CONNECTION;
     
@@ -577,30 +574,35 @@
                 // add the SSL filter if it's not there already like in a reused
                 // session
                 if (!sess.getFilterChain().contains(SSL_FILTER)) {
-                    if (sslFilter == null) {
+                    try {
+                        SSLContext context = request.getSSLContext();
+                        if (context == null) {
+                            // if the caller did not provide an SSL context
+                            // create a default SSL context
+                            context = createDefaultSSLContext();
+                        }
+                        SSLFilter sslFilter = new SSLFilter(context);
+                        sslFilter.setUseClientMode(true);
+                        sess.getFilterChain().addLast(SSL_FILTER, sslFilter);
+                    } catch (GeneralSecurityException e) {
                         try {
-                            sslFilter = new SSLFilter(createClientSSLContext());
-                            sslFilter.setUseClientMode(true);
-                        } catch (GeneralSecurityException e) {
-                            try {
-                                sess.getHandler().exceptionCaught(sess, e);
-                            } catch (Exception e1) {
-                                //Do nothing...we just reported it
-                            }
+                            sess.getHandler().exceptionCaught(sess, e);
+                        } catch (Exception e1) {
+                            //Do nothing...we just reported it
                         }
                     }
-                    sess.getFilterChain().addLast(SSL_FILTER, sslFilter);
                 }
             }
         }
 
         /**
-         * Creates the client ssl context.
+         * Creates a default SSL context in case it was not provided by the
+         * caller.
          *
          * @return the SSL context
          * @throws GeneralSecurityException the general security exception
          */
-        private SSLContext createClientSSLContext() throws GeneralSecurityException {
+        private SSLContext createDefaultSSLContext() throws GeneralSecurityException {
             SSLContext context = SSLContext.getInstance(sslProtocol);
             context.init(null, TrustManagerFactoryImpl.X509_MANAGERS, null);
             return context;

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java?rev=603885&r1=603884&r2=603885&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
(original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
Thu Dec 13 03:12:43 2007
@@ -26,6 +26,8 @@
 import java.util.Map;
 import java.util.concurrent.ScheduledFuture;
 
+import javax.net.ssl.SSLContext;
+
 import org.apache.ahc.AsyncHttpClientCallback;
 import org.apache.ahc.auth.AuthScope;
 import org.apache.ahc.auth.AuthState;
@@ -146,6 +148,11 @@
      * Auth attempt count
      */
     private int authCount = 0;
+    
+    /**
+     * SSL context for https
+     */
+    private SSLContext sslContext;
 
     /**
      * Instantiates a new http request message.
@@ -208,14 +215,14 @@
      * Returns the response future object associated with the request.
      */
     public ResponseFuture getResponseFuture() {
-    	return responseFuture;
+        return responseFuture;
     }
 
     /**
      * Sets the response future object.
      */
     public void setResponseFuture(ResponseFuture result) {
-    	responseFuture = result;
+        responseFuture = result;
     }
 
     /**
@@ -366,7 +373,7 @@
      *
      */
     public void clearAllParameters() {
-    	parameters.clear();
+        parameters.clear();
     }
 
     /**
@@ -513,5 +520,23 @@
      */
     public void setAuthCount(int authCount) {
         this.authCount = authCount;
+    }
+    
+    /**
+     * Gets the SSL context
+     * 
+     * @return the SSL context
+     */
+    public SSLContext getSSLContext() {
+        return sslContext;
+    }
+    
+    /**
+     * Sets the SSL context
+     * 
+     * @param sslContext the SSL context
+     */
+    public void setSSLContext(SSLContext sslContext) {
+        this.sslContext = sslContext;
     }
 }



Mime
View raw message