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 2013/07/05 20:58:36 UTC

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

Author: olegk
Date: Fri Jul  5 18:58:35 2013
New Revision: 1500099

URL: http://svn.apache.org/r1500099
Log:
Connection factories to use default SSL settings if SSL context is not explicitly set

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLContextUtils.java   (with props)
Modified:
    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/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLContextUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLContextUtils.java?rev=1500099&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLContextUtils.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLContextUtils.java Fri Jul  5 18:58:35 2013
@@ -0,0 +1,50 @@
+/*
+ * ====================================================================
+ * 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 javax.net.ssl.SSLContext;
+import java.security.NoSuchAlgorithmException;
+
+// TODO: to be replaced by SSLContext#getDefault() after upgrade to 1.6
+class SSLContextUtils {
+
+    static SSLContext getDefault() {
+        SSLContext sslcontext;
+        try {
+            try {
+                sslcontext = SSLContext.getInstance("Default");
+            }  catch (NoSuchAlgorithmException ex) {
+                sslcontext = SSLContext.getInstance("TLS");
+            }
+            sslcontext.init(null, null, null);
+        } catch (final Exception ex) {
+            throw new IllegalStateException("Failure initializing default SSL context", ex);
+        }
+        return sslcontext;
+    }
+
+}

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

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

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

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=1500099&r1=1500098&r2=1500099&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 Fri Jul  5 18:58:35 2013
@@ -196,17 +196,6 @@ public class SSLNHttpClientConnectionFac
         this(null, null, null, null, null, null);
     }
 
-    private SSLContext getDefaultSSLContext() {
-        final SSLContext sslcontext;
-        try {
-            sslcontext = SSLContext.getInstance("TLS");
-            sslcontext.init(null, null, null);
-        } catch (final Exception ex) {
-            throw new IllegalStateException("Failure initializing default SSL context", ex);
-        }
-        return sslcontext;
-    }
-
     /**
      * @deprecated (4.3) no longer used.
      */
@@ -227,7 +216,7 @@ public class SSLNHttpClientConnectionFac
             final SSLContext sslcontext,
             final SSLSetupHandler sslHandler) {
         final SSLIOSession ssliosession = new SSLIOSession(iosession, SSLMode.CLIENT,
-                (sslcontext != null ? sslcontext : getDefaultSSLContext()),
+                (sslcontext != null ? sslcontext : SSLContextUtils.getDefault()),
                 sslHandler);
         iosession.setAttribute(SSLIOSession.SESSION_KEY, ssliosession);
         return ssliosession;

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=1500099&r1=1500098&r2=1500099&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 Fri Jul  5 18:58:35 2013
@@ -194,17 +194,6 @@ public class SSLNHttpServerConnectionFac
         this(null, null, null, null, null, null, null, null);
     }
 
-    private SSLContext getDefaultSSLContext() {
-        final SSLContext sslcontext;
-        try {
-            sslcontext = SSLContext.getInstance("TLS");
-            sslcontext.init(null, null, null);
-        } catch (final Exception ex) {
-            throw new IllegalStateException("Failure initializing default SSL context", ex);
-        }
-        return sslcontext;
-    }
-
     /**
      * @deprecated (4.3) no longer used.
      */
@@ -225,7 +214,7 @@ public class SSLNHttpServerConnectionFac
             final SSLContext sslcontext,
             final SSLSetupHandler sslHandler) {
         final SSLIOSession ssliosession = new SSLIOSession(iosession, SSLMode.SERVER,
-                (sslcontext != null ? sslcontext : getDefaultSSLContext()),
+                (sslcontext != null ? sslcontext : SSLContextUtils.getDefault()),
                 sslHandler);
         iosession.setAttribute(SSLIOSession.SESSION_KEY, ssliosession);
         return ssliosession;

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java?rev=1500099&r1=1500098&r2=1500099&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java Fri Jul  5 18:58:35 2013
@@ -149,9 +149,8 @@ public class BasicConnFactory implements
             socket = this.plainfactory != null ? this.plainfactory.createSocket() :
                     new Socket();
         } if ("https".equalsIgnoreCase(scheme)) {
-            if (this.sslfactory != null) {
-                socket = this.sslfactory.createSocket();
-            }
+            socket = (this.sslfactory != null ? this.sslfactory :
+                    SSLSocketFactory.getDefault()).createSocket();
         }
         if (socket == null) {
             throw new IOException(scheme + " scheme is not supported");