Minor improvements in AbstractAsyncTest

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/trunk@1673758 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/httpasyncclient/src/test/java/org/apache/http/localserver/AbstractAsyncTest.java b/httpasyncclient/src/test/java/org/apache/http/localserver/AbstractAsyncTest.java
index 2e6869b..980b1e9 100644
--- a/httpasyncclient/src/test/java/org/apache/http/localserver/AbstractAsyncTest.java
+++ b/httpasyncclient/src/test/java/org/apache/http/localserver/AbstractAsyncTest.java
@@ -28,8 +28,13 @@
 package org.apache.http.localserver;
 
 import java.net.InetSocketAddress;
+import java.net.URL;
 import java.util.concurrent.TimeUnit;
 
+import javax.net.ssl.SSLContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.http.ExceptionLogger;
 import org.apache.http.HttpHost;
 import org.apache.http.config.Registry;
@@ -44,6 +49,7 @@
 import org.apache.http.nio.conn.SchemeIOSessionStrategy;
 import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
 import org.apache.http.nio.reactor.ListenerEndpoint;
+import org.apache.http.ssl.SSLContextBuilder;
 import org.junit.After;
 import org.junit.Before;
 
@@ -69,6 +75,23 @@
         return this.scheme.name();
     }
 
+    protected SSLContext createServerSSLContext() throws Exception {
+        final URL keyStoreURL = getClass().getResource("/test.keystore");
+        final String storePassword = "nopassword";
+        return SSLContextBuilder.create()
+                .loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
+                .loadKeyMaterial(keyStoreURL, storePassword.toCharArray(), storePassword.toCharArray())
+                .build();
+    }
+
+    protected SSLContext createClientSSLContext() throws Exception {
+        final URL keyStoreURL = getClass().getResource("/test.keystore");
+        final String storePassword = "nopassword";
+        return SSLContextBuilder.create()
+                .loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
+                .build();
+    }
+
     public HttpHost startServer() throws Exception {
         this.server = this.serverBootstrap.create();
         this.server.start();
@@ -88,16 +111,24 @@
                 .build();
         this.serverBootstrap.setServerInfo("TEST/1.1");
         this.serverBootstrap.setIOReactorConfig(ioReactorConfig);
-        this.serverBootstrap.setExceptionLogger(ExceptionLogger.STD_ERR);
+        this.serverBootstrap.setExceptionLogger(new ExceptionLogger() {
+
+            private final Log log = LogFactory.getLog(AbstractAsyncTest.class);
+
+            @Override
+            public void log(final Exception ex) {
+                log.error(ex.getMessage(), ex);
+            }
+        });
         if (this.scheme.equals(ProtocolScheme.https)) {
-            this.serverBootstrap.setSslContext(SSLTestContexts.createServerSSLContext());
+            this.serverBootstrap.setSslContext(createServerSSLContext());
         }
 
         final RegistryBuilder<SchemeIOSessionStrategy> builder = RegistryBuilder.create();
         builder.register("http", NoopIOSessionStrategy.INSTANCE);
         if (this.scheme.equals(ProtocolScheme.https)) {
             builder.register("https", new SSLIOSessionStrategy(
-                    SSLTestContexts.createClientSSLContext(),
+                    createClientSSLContext(),
                     new DefaultHostnameVerifier()));
         }
         final Registry<SchemeIOSessionStrategy> registry =  builder.build();
diff --git a/httpasyncclient/src/test/java/org/apache/http/localserver/SSLTestContexts.java b/httpasyncclient/src/test/java/org/apache/http/localserver/SSLTestContexts.java
deleted file mode 100644
index c3332ea..0000000
--- a/httpasyncclient/src/test/java/org/apache/http/localserver/SSLTestContexts.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ====================================================================
- * 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.localserver;
-
-import java.net.URL;
-import java.security.KeyStore;
-import java.security.NoSuchAlgorithmException;
-
-import javax.net.ssl.KeyManager;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-
-public class SSLTestContexts {
-
-    private static KeyManagerFactory createKeyManagerFactory() throws NoSuchAlgorithmException {
-        final String algo = KeyManagerFactory.getDefaultAlgorithm();
-        try {
-            return KeyManagerFactory.getInstance(algo);
-        } catch (final NoSuchAlgorithmException ex) {
-            return KeyManagerFactory.getInstance("SunX509");
-        }
-    }
-
-    public static SSLContext createServerSSLContext() throws Exception {
-        final ClassLoader cl = SSLTestContexts.class.getClassLoader();
-        final URL url = cl.getResource("test.keystore");
-        final KeyStore keystore  = KeyStore.getInstance("jks");
-        keystore.load(url.openStream(), "nopassword".toCharArray());
-        final KeyManagerFactory kmfactory = createKeyManagerFactory();
-        kmfactory.init(keystore, "nopassword".toCharArray());
-        final KeyManager[] keymanagers = kmfactory.getKeyManagers();
-        final SSLContext sslcontext = SSLContext.getInstance("TLS");
-        sslcontext.init(keymanagers, null, null);
-        return sslcontext;
-    }
-
-    private static TrustManagerFactory createTrustManagerFactory() throws NoSuchAlgorithmException {
-        final String algo = TrustManagerFactory.getDefaultAlgorithm();
-        try {
-            return TrustManagerFactory.getInstance(algo);
-        } catch (final NoSuchAlgorithmException ex) {
-            return TrustManagerFactory.getInstance("SunX509");
-        }
-    }
-
-    public static SSLContext createClientSSLContext() throws Exception {
-        final ClassLoader cl = SSLTestContexts.class.getClassLoader();
-        final URL url = cl.getResource("test.keystore");
-        final KeyStore keystore  = KeyStore.getInstance("jks");
-        keystore.load(url.openStream(), "nopassword".toCharArray());
-        final TrustManagerFactory tmfactory = createTrustManagerFactory();
-        tmfactory.init(keystore);
-        final TrustManager[] trustmanagers = tmfactory.getTrustManagers();
-        final SSLContext sslcontext = SSLContext.getInstance("TLS");
-        sslcontext.init(null, trustmanagers, null);
-        return sslcontext;
-    }
-
-}