hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r831312 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http: impl/nio/reactor/ mockup/ nio/protocol/
Date Fri, 30 Oct 2009 14:34:34 GMT
Author: olegk
Date: Fri Oct 30 14:34:34 2009
New Revision: 831312

URL: http://svn.apache.org/viewvc?rev=831312&view=rev
Log:
SSL test cases to fall back onto SunX509 implementation of SSL classes the default implementation
is not available / functional

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java?rev=831312&r1=831311&r2=831312&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java
Fri Oct 30 14:34:34 2009
@@ -33,6 +33,7 @@
 import java.net.Socket;
 import java.net.URL;
 import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
 
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManager;
@@ -118,6 +119,15 @@
         return serviceHandler;
     }
 
+    private TrustManagerFactory createTrustManagerFactory() throws NoSuchAlgorithmException
{
+        String algo = TrustManagerFactory.getDefaultAlgorithm();
+        try {
+            return TrustManagerFactory.getInstance(algo);
+        } catch (NoSuchAlgorithmException ex) {
+            return TrustManagerFactory.getInstance("SunX509");
+        }
+    }
+    
     public void testBufferedInput() throws Exception {
         final int[] result = new int[1];
         HttpRequestHandler requestHandler = new HttpRequestHandler() {
@@ -141,8 +151,7 @@
         URL url = cl.getResource("test.keystore");
         KeyStore keystore  = KeyStore.getInstance("jks");
         keystore.load(url.openStream(), "nopassword".toCharArray());
-        TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
-                TrustManagerFactory.getDefaultAlgorithm());
+        TrustManagerFactory tmfactory = createTrustManagerFactory();
         tmfactory.init(keystore);
         TrustManager[] trustmanagers = tmfactory.getTrustManagers(); 
         SSLContext sslcontext = SSLContext.getInstance("TLS");

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java?rev=831312&r1=831311&r2=831312&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java
Fri Oct 30 14:34:34 2009
@@ -51,6 +51,7 @@
 import org.apache.http.nio.protocol.BufferingHttpServiceHandler;
 import org.apache.http.nio.protocol.EventListener;
 import org.apache.http.nio.protocol.HttpRequestExecutionHandler;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpProcessor;
@@ -195,6 +196,9 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
         
+        assertEquals(IOReactorStatus.ACTIVE, this.server.getStatus());
+        assertEquals(IOReactorStatus.ACTIVE, this.client.getStatus());
+        
         for (int i = 0; i < connNo; i++) {
             this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()), 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java?rev=831312&r1=831311&r2=831312&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
Fri Oct 30 14:34:34 2009
@@ -31,6 +31,7 @@
 import java.net.InetSocketAddress;
 import java.net.URL;
 import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
 import java.util.List;
 
 import javax.net.ssl.SSLContext;
@@ -57,18 +58,30 @@
     public TestHttpSSLClient(final HttpParams params) throws Exception {
         super();
         this.params = params;
+        this.sslcontext = createSSLContext();
         this.ioReactor = new DefaultConnectingIOReactor(2, this.params);
-        
+    }
+
+    private TrustManagerFactory createTrustManagerFactory() throws NoSuchAlgorithmException
{
+        String algo = TrustManagerFactory.getDefaultAlgorithm();
+        try {
+            return TrustManagerFactory.getInstance(algo);
+        } catch (NoSuchAlgorithmException ex) {
+            return TrustManagerFactory.getInstance("SunX509");
+        }
+    }
+    
+    protected SSLContext createSSLContext() throws Exception {
         ClassLoader cl = getClass().getClassLoader();
         URL url = cl.getResource("test.keystore");
         KeyStore keystore  = KeyStore.getInstance("jks");
         keystore.load(url.openStream(), "nopassword".toCharArray());
-        TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
-                TrustManagerFactory.getDefaultAlgorithm());
+        TrustManagerFactory tmfactory = createTrustManagerFactory();
         tmfactory.init(keystore);
         TrustManager[] trustmanagers = tmfactory.getTrustManagers(); 
-        this.sslcontext = SSLContext.getInstance("TLS");
-        this.sslcontext.init(null, trustmanagers, null);
+        SSLContext sslcontext = SSLContext.getInstance("TLS");
+        sslcontext.init(null, trustmanagers, null);
+        return sslcontext;
     }
     
     public HttpParams getParams() {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java?rev=831312&r1=831311&r2=831312&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
Fri Oct 30 14:34:34 2009
@@ -31,6 +31,7 @@
 import java.net.InetSocketAddress;
 import java.net.URL;
 import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
 import java.util.List;
 
 import javax.net.ssl.KeyManager;
@@ -63,18 +64,30 @@
     public TestHttpSSLServer(final HttpParams params) throws Exception {
         super();
         this.params = params;
+        this.sslcontext = createSSLContext();
         this.ioReactor = new DefaultListeningIOReactor(2, this.params);
-        
+    }
+    
+    private KeyManagerFactory createKeyManagerFactory() throws NoSuchAlgorithmException {
+        String algo = KeyManagerFactory.getDefaultAlgorithm();
+        try {
+            return KeyManagerFactory.getInstance(algo);
+        } catch (NoSuchAlgorithmException ex) {
+            return KeyManagerFactory.getInstance("SunX509");
+        }
+    }
+    
+    protected SSLContext createSSLContext() throws Exception {
         ClassLoader cl = getClass().getClassLoader();
         URL url = cl.getResource("test.keystore");
         KeyStore keystore  = KeyStore.getInstance("jks");
         keystore.load(url.openStream(), "nopassword".toCharArray());
-        KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
-                KeyManagerFactory.getDefaultAlgorithm());
+        KeyManagerFactory kmfactory = createKeyManagerFactory();
         kmfactory.init(keystore, "nopassword".toCharArray());
         KeyManager[] keymanagers = kmfactory.getKeyManagers(); 
-        this.sslcontext = SSLContext.getInstance("TLS");
-        this.sslcontext.init(keymanagers, null, null);
+        SSLContext sslcontext = SSLContext.getInstance("TLS");
+        sslcontext.init(keymanagers, null, null);
+        return sslcontext;
     }
     
     public HttpParams getParams() {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java?rev=831312&r1=831311&r2=831312&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
Fri Oct 30 14:34:34 2009
@@ -49,6 +49,7 @@
 import org.apache.http.mockup.SimpleEventListener;
 import org.apache.http.mockup.SimpleNHttpRequestHandlerResolver;
 import org.apache.http.nio.entity.NStringEntity;
+import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.protocol.HttpProcessor;
@@ -143,6 +144,9 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
 
+        assertEquals(IOReactorStatus.ACTIVE, this.server.getStatus());
+        assertEquals(IOReactorStatus.ACTIVE, this.client.getStatus());
+        
         for (int i = 0; i < connNo; i++) {
             this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()),



Mime
View raw message