camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/2] git commit: CAMEL-7940 Fixed the test failure of JettyHttpsProducerSslContextInUriTest
Date Tue, 04 Nov 2014 10:53:29 GMT
CAMEL-7940 Fixed the test failure of JettyHttpsProducerSslContextInUriTest


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

Branch: refs/heads/master
Commit: cbad2d60b56ece455b7183d3858c0ccbf3636c15
Parents: aeafbe3
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Tue Nov 4 18:53:01 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Tue Nov 4 18:53:01 2014 +0800

----------------------------------------------------------------------
 .../camel/component/jetty/CamelHttpClient.java  | 29 +++++-----
 .../component/jetty/JettyHttpComponent.java     | 59 +++++++++++---------
 .../component/jetty/JettyHttpEndpoint.java      |  2 +-
 .../JettyHttpsProducerSslContextInUriTest.java  |  6 +-
 4 files changed, 54 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cbad2d60/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
index 204921c..664b4df 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java
@@ -20,27 +20,30 @@ import javax.net.ssl.SSLContext;
 
 import org.apache.camel.util.ObjectHelper;
 import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.client.RedirectListener;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
 import org.eclipse.jetty.util.thread.QueuedThreadPool;
 
 public class CamelHttpClient extends HttpClient {
     
-    private SSLContext context;
     private boolean supportRedirect;
-
-    @Override
-    protected SSLContext getSSLContext() {
-        if (context == null) {
-            this.context = super.getSSLContext();
-        }
-        
-        return this.context;
+    
+    public CamelHttpClient() {
+        super();
     }
-
+    
+    public CamelHttpClient(SslContextFactory sslContextFactory) {
+        super(sslContextFactory);
+    }
+    
+    @Deprecated
+    /**
+     * It does nothing here, please setup SslContextFactory directly, it will be removed
in Camel 2.16.0
+     * @param context
+     */
     public void setSSLContext(SSLContext context) {
-        this.context = context;
+        // do nothing here, please setup SslContextFactory directly.
     }
-
+    
     @Override
     protected void doStart() throws Exception {
         if (getThreadPool() == null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/cbad2d60/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index 8d18d1f..71c3f1e 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -17,14 +17,17 @@
 package org.apache.camel.component.jetty;
 
 import java.io.File;
+import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.URI;
+import java.security.GeneralSecurityException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+
 import javax.management.MBeanServer;
 import javax.servlet.Filter;
 
@@ -510,24 +513,7 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
         SSLContextParameters endpointSslContextParameters = endpoint.getSslContextParameters();
         
         if (endpointSslContextParameters != null) {
-            SslContextFactory contextFact = new SslContextFactory() {
-
-                // This method is for Jetty 7.0.x ~ 7.4.x
-                @SuppressWarnings("unused")
-                public boolean checkConfig() {
-                    if (getSslContext() == null) {
-                        return checkSSLContextFactoryConfig(this);
-                    } else {
-                        return true;
-                    }
-                }
-                // This method is for Jetty 7.5.x
-                public void checkKeyStore() {
-                    // here we don't check the SslContext as it is already created
-                }
-                
-            };
-            contextFact.setSslContext(endpointSslContextParameters.createSSLContext());
+            SslContextFactory contextFact = createSslContextFactory(endpointSslContextParameters);
             for (Constructor<?> c : SslSelectChannelConnector.class.getConstructors())
{
                 if (c.getParameterTypes().length == 1
                     && c.getParameterTypes()[0].isInstance(contextFact)) {
@@ -595,6 +581,28 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
         return answer;
     }
     
+    private SslContextFactory createSslContextFactory(SSLContextParameters ssl) throws GeneralSecurityException,
IOException {
+        SslContextFactory answer = new SslContextFactory() {
+
+            // This method is for Jetty 7.0.x ~ 7.4.x
+            @SuppressWarnings("unused")
+            public boolean checkConfig() {
+                if (getSslContext() == null) {
+                    return checkSSLContextFactoryConfig(this);
+                } else {
+                    return true;
+                }
+            }
+            // This method is for Jetty 7.5.x
+            public void checkKeyStore() {
+                // here we don't check the SslContext as it is already created
+            }
+            
+        };
+        answer.setSslContext(ssl.createSSLContext());
+        return answer;
+    }
+    
     private void invokeSslContextFactoryMethod(Object connector, String method, String value)
{
         Object factory;
         try {
@@ -698,8 +706,13 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
      * @param maxThreads optional maximum number of threads in client thread pool
      * @param ssl        option SSL parameters
      */
-    public static CamelHttpClient createHttpClient(JettyHttpEndpoint endpoint, Integer minThreads,
Integer maxThreads, SSLContextParameters ssl) throws Exception {
-        CamelHttpClient httpClient = new CamelHttpClient();
+    public CamelHttpClient createHttpClient(JettyHttpEndpoint endpoint, Integer minThreads,
Integer maxThreads, SSLContextParameters ssl) throws Exception {
+        CamelHttpClient httpClient = null;
+        if (ssl != null) {
+            httpClient = new CamelHttpClient(createSslContextFactory(ssl));
+        } else {
+            httpClient = new CamelHttpClient();
+        }
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
         
         CamelContext context = endpoint.getCamelContext();
@@ -738,11 +751,7 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
             qtp.setName("CamelJettyClient(" + ObjectHelper.getIdentityHashCode(httpClient)
+ ")");
             httpClient.setThreadPool(qtp);
         }
-
-        if (ssl != null) {
-            httpClient.setSSLContext(ssl.createSSLContext());
-        }
-
+        
         if (LOG.isDebugEnabled()) {
             if (minThreads != null) {
                 LOG.debug("Created HttpClient with thread pool {}-{} -> {}", new Object[]{minThreads,
maxThreads, httpClient});

http://git-wip-us.apache.org/repos/asf/camel/blob/cbad2d60/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
index 483fc9a..bded0df 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
@@ -90,7 +90,7 @@ public class JettyHttpEndpoint extends HttpEndpoint {
             // thread pool min/max from endpoint take precedence over from component
             Integer min = httpClientMinThreads != null ? httpClientMinThreads : getComponent().getHttpClientMinThreads();
             Integer max = httpClientMaxThreads != null ? httpClientMaxThreads : getComponent().getHttpClientMaxThreads();
-            HttpClient httpClient = JettyHttpComponent.createHttpClient(this, min, max, sslContextParameters);
+            HttpClient httpClient = getComponent().createHttpClient(this, min, max, sslContextParameters);
 
             // set optional http client parameters
             if (httpClientParameters != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/cbad2d60/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerSslContextInUriTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerSslContextInUriTest.java
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerSslContextInUriTest.java
index 50b1c3a..f9d3172 100644
--- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerSslContextInUriTest.java
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpsProducerSslContextInUriTest.java
@@ -42,12 +42,12 @@ public class JettyHttpsProducerSslContextInUriTest extends JettyProducerHttpsRou
         kmp.setKeyPassword(pwd);
         kmp.setKeyStore(ksp);
 
-        TrustManagersParameters tmp = new TrustManagersParameters();
-        tmp.setKeyStore(ksp);
+        //TrustManagersParameters tmp = new TrustManagersParameters();
+        //tmp.setKeyStore(ksp);
 
         SSLContextParameters sslContextParameters = new SSLContextParameters();
         sslContextParameters.setKeyManagers(kmp);
-        sslContextParameters.setTrustManagers(tmp);
+        //sslContextParameters.setTrustManagers(tmp);
 
         JndiRegistry registry = super.createRegistry();
         registry.bind("sslContextParameters", sslContextParameters);


Mime
View raw message