camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/2] git commit: CAMEL-7940 Fixed the test failure of JettyHttpsProducerSslContextInUriTest
Date Tue, 04 Nov 2014 11:58:35 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.13.x 3d2949f30 -> b99544548
  refs/heads/camel-2.14.x 72062e9a9 -> 3192a4845


CAMEL-7940 Fixed the test failure of JettyHttpsProducerSslContextInUriTest

Conflicts:
	components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelHttpClient.java


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

Branch: refs/heads/camel-2.14.x
Commit: 3192a4845822a13ee5f8189fe7b40e9c2669435d
Parents: 72062e9
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 19:34:42 2014 +0800

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


http://git-wip-us.apache.org/repos/asf/camel/blob/3192a484/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 386ed03..0fab2e3 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,23 +20,28 @@ import javax.net.ssl.SSLContext;
 
 import org.apache.camel.util.ObjectHelper;
 import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
 import org.eclipse.jetty.util.thread.QueuedThreadPool;
 
 public class CamelHttpClient extends HttpClient {
-    
-    private SSLContext context;
 
-    @Override
-    protected SSLContext getSSLContext() {
-        if (context == null) {
-            this.context = super.getSSLContext();
-        }
-        
-        return this.context;
+    private boolean supportRedirect;
+
+    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

http://git-wip-us.apache.org/repos/asf/camel/blob/3192a484/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/3192a484/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/3192a484/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