You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2014/12/19 13:07:50 UTC

cxf git commit: Enable protocol support for async http clients

Repository: cxf
Updated Branches:
  refs/heads/master 28346081d -> 0d5b5185a


Enable protocol support for async http clients


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/0d5b5185
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0d5b5185
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0d5b5185

Branch: refs/heads/master
Commit: 0d5b5185a2cb8243cb1f69980a9ccc94a810bf32
Parents: 2834608
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Fri Dec 19 11:28:58 2014 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Fri Dec 19 11:28:58 2014 +0000

----------------------------------------------------------------------
 .../http/asyncclient/AsyncHTTPConduit.java      | 23 ++++++++
 .../cxf/systest/https/ssl3/SSLv3Test.java       | 58 ++++++++++++++++++++
 2 files changed, 81 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0d5b5185/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
index 57c9a42..56a677b 100644
--- a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
+++ b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
@@ -877,6 +877,29 @@ public class AsyncHTTPConduit extends URLConnectionHTTPConduit {
                                                          SSLUtils.getSupportedCipherSuites(sslcontext), 
                                                          tlsClientParameters.getCipherSuitesFilter(), LOG, false);
         sslengine.setEnabledCipherSuites(cipherSuites);
+        
+        String protocol = tlsClientParameters.getSecureSocketProtocol() != null ? tlsClientParameters
+            .getSecureSocketProtocol() : "TLS";
+            
+        String p[] = findProtocols(protocol, sslengine.getSupportedProtocols());
+        if (p != null) {
+            sslengine.setEnabledProtocols(p);
+        }
+    }
+    
+    private String[] findProtocols(String p, String[] options) {
+        List<String> list = new ArrayList<String>();
+        for (String s : options) {
+            if (s.equals(p)) {
+                return new String[] {p};
+            } else if (s.startsWith(p)) {
+                list.add(s);
+            }
+        }
+        if (list.isEmpty()) {
+            return null;
+        }
+        return list.toArray(new String[list.size()]);
     }
 
     protected static KeyManager[] getKeyManagersWithCertAlias(TLSClientParameters tlsClientParameters,

http://git-wip-us.apache.org/repos/asf/cxf/blob/0d5b5185/systests/transports/src/test/java/org/apache/cxf/systest/https/ssl3/SSLv3Test.java
----------------------------------------------------------------------
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/https/ssl3/SSLv3Test.java b/systests/transports/src/test/java/org/apache/cxf/systest/https/ssl3/SSLv3Test.java
index 834ff50..169a13d 100644
--- a/systests/transports/src/test/java/org/apache/cxf/systest/https/ssl3/SSLv3Test.java
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/https/ssl3/SSLv3Test.java
@@ -27,6 +27,7 @@ import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLSession;
 import javax.net.ssl.TrustManager;
+import javax.xml.ws.BindingProvider;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.spring.SpringBusFactory;
@@ -164,6 +165,37 @@ public class SSLv3Test extends AbstractBusClientServerTestBase {
     }
     
     @org.junit.Test
+    public void testAsyncClientSSL3NotAllowed() throws Exception {
+        SpringBusFactory bf = new SpringBusFactory();
+        URL busFile = SSLv3Test.class.getResource("sslv3-client.xml");
+
+        Bus bus = bf.createBus(busFile.toString());
+        SpringBusFactory.setDefaultBus(bus);
+        SpringBusFactory.setThreadDefaultBus(bus);
+        
+        URL url = SOAPService.WSDL_LOCATION;
+        SOAPService service = new SOAPService(url, SOAPService.SERVICE);
+        assertNotNull("Service is null", service);   
+        final Greeter port = service.getHttpsPort();
+        assertNotNull("Port is null", port);
+        
+        // Enable Async
+        ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true);
+        
+        updateAddressPort(port, PORT3);
+        
+        try {
+            port.greetMe("Kitty");
+            fail("Failure expected on the client not supporting SSLv3 by default");
+        } catch (Exception ex) {
+            // expected
+        }
+        
+        ((java.io.Closeable)port).close();
+        bus.shutdown(true);
+    }
+    
+    @org.junit.Test
     public void testClientSSL3Allowed() throws Exception {
         SpringBusFactory bf = new SpringBusFactory();
         URL busFile = SSLv3Test.class.getResource("sslv3-client-allow.xml");
@@ -186,6 +218,32 @@ public class SSLv3Test extends AbstractBusClientServerTestBase {
         bus.shutdown(true);
     }
     
+    @org.junit.Test
+    public void testAsyncClientSSL3Allowed() throws Exception {
+        SpringBusFactory bf = new SpringBusFactory();
+        URL busFile = SSLv3Test.class.getResource("sslv3-client-allow.xml");
+
+        Bus bus = bf.createBus(busFile.toString());
+        SpringBusFactory.setDefaultBus(bus);
+        SpringBusFactory.setThreadDefaultBus(bus);
+        
+        URL url = SOAPService.WSDL_LOCATION;
+        SOAPService service = new SOAPService(url, SOAPService.SERVICE);
+        assertNotNull("Service is null", service);   
+        final Greeter port = service.getHttpsPort();
+        assertNotNull("Port is null", port);
+        
+        // Enable Async
+        ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true);
+        
+        updateAddressPort(port, PORT3);
+        
+        assertEquals(port.greetMe("Kitty"), "Hello Kitty");
+        
+        ((java.io.Closeable)port).close();
+        bus.shutdown(true);
+    }
+    
     private static final class DisableCNCheckVerifier implements HostnameVerifier {
 
         @Override