camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1143693 - in /camel/trunk/components/camel-http4/src: main/java/org/apache/camel/component/http4/ test/java/org/apache/camel/component/http4/
Date Thu, 07 Jul 2011 07:38:25 GMT
Author: davsclaus
Date: Thu Jul  7 07:38:25 2011
New Revision: 1143693

URL: http://svn.apache.org/viewvc?rev=1143693&view=rev
Log:
CAMEL-4176: camel-http4 added support for setting scheme to use for proxy. Will use the same
scheme on the proxy as the endpoint if not explicit configured.

Modified:
    camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
    camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java
    camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/ProxyHttpClientConfigurer.java
    camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpClientConfigurerTest.java

Modified: camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java?rev=1143693&r1=1143692&r2=1143693&view=diff
==============================================================================
--- camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
(original)
+++ camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
Thu Jul  7 07:38:25 2011
@@ -88,9 +88,10 @@ public class HttpComponent extends Heade
      * Creates the HttpClientConfigurer based on the given parameters
      *
      * @param parameters the map of parameters
+     * @param secure whether the endpoint is secure (eg https4)
      * @return the configurer
      */
-    protected HttpClientConfigurer createHttpClientConfigurer(Map<String, Object> parameters)
{
+    protected HttpClientConfigurer createHttpClientConfigurer(Map<String, Object> parameters,
boolean secure) {
         // prefer to use endpoint configured over component configured
         HttpClientConfigurer configurer = resolveAndRemoveReferenceParameter(parameters,
"httpClientConfigurerRef", HttpClientConfigurer.class);
         if (configurer == null) {
@@ -104,7 +105,7 @@ public class HttpComponent extends Heade
         }
 
         configurer = configureBasicAuthentication(parameters, configurer);
-        configurer = configureHttpProxy(parameters, configurer);
+        configurer = configureHttpProxy(parameters, configurer, secure);
 
         return configurer;
     }
@@ -123,7 +124,12 @@ public class HttpComponent extends Heade
         return configurer;
     }
 
-    private HttpClientConfigurer configureHttpProxy(Map<String, Object> parameters,
HttpClientConfigurer configurer) {
+    private HttpClientConfigurer configureHttpProxy(Map<String, Object> parameters,
HttpClientConfigurer configurer, boolean secure) {
+        String proxyAuthScheme = getAndRemoveParameter(parameters, "proxyAuthScheme", String.class);
+        if (proxyAuthScheme == null) {
+            // fallback and use either http4 or https4 depending on secure
+            proxyAuthScheme = secure ? "https4" : "http4";
+        }
         String proxyAuthHost = getAndRemoveParameter(parameters, "proxyAuthHost", String.class);
         Integer proxyAuthPort = getAndRemoveParameter(parameters, "proxyAuthPort", Integer.class);
         
@@ -132,12 +138,12 @@ public class HttpComponent extends Heade
             String proxyAuthPassword = getAndRemoveParameter(parameters, "proxyAuthPassword",
String.class);
             String proxyAuthDomain = getAndRemoveParameter(parameters, "proxyAuthDomain",
String.class);
             String proxyAuthNtHost = getAndRemoveParameter(parameters, "proxyAuthNtHost",
String.class);
-            
+
             if (proxyAuthUsername != null && proxyAuthPassword != null) {
                 return CompositeHttpConfigurer.combineConfigurers(
-                    configurer, new ProxyHttpClientConfigurer(proxyAuthHost, proxyAuthPort,
proxyAuthUsername, proxyAuthPassword, proxyAuthDomain, proxyAuthNtHost));
+                    configurer, new ProxyHttpClientConfigurer(proxyAuthHost, proxyAuthPort,
proxyAuthScheme, proxyAuthUsername, proxyAuthPassword, proxyAuthDomain, proxyAuthNtHost));
             } else {
-                return CompositeHttpConfigurer.combineConfigurers(configurer, new ProxyHttpClientConfigurer(proxyAuthHost,
proxyAuthPort));
+                return CompositeHttpConfigurer.combineConfigurers(configurer, new ProxyHttpClientConfigurer(proxyAuthHost,
proxyAuthPort, proxyAuthScheme));
             }
         }
         
@@ -176,8 +182,10 @@ public class HttpComponent extends Heade
             sslContextParameters = this.sslContextParameters;
         }
         
+        boolean secure = isSecureConnection(uri);
+
         // create the configurer to use for this endpoint
-        HttpClientConfigurer configurer = createHttpClientConfigurer(parameters);
+        HttpClientConfigurer configurer = createHttpClientConfigurer(parameters, secure);
         URI endpointUri = URISupport.createRemainingURI(new URI(addressUri), CastUtils.cast(httpClientParameters));
         // restructure uri to be based on the parameters left as we dont want to include
the Camel internal options
         URI httpUri = URISupport.createRemainingURI(new URI(addressUri), CastUtils.cast(parameters));
@@ -193,10 +201,9 @@ public class HttpComponent extends Heade
         }
 
         // register port on schema registry
-        boolean secure = isSecureConnection(uri);
         int port = getPort(httpUri);
         registerPort(secure, x509HostnameVerifier, port, sslContextParameters);
-        
+
         // create the endpoint
         HttpEndpoint endpoint = new HttpEndpoint(endpointUri.toString(), this, httpUri, clientParams,
clientConnectionManager, configurer);
         setProperties(endpoint, parameters);
@@ -229,7 +236,7 @@ public class HttpComponent extends Heade
     protected void registerPort(boolean secure, X509HostnameVerifier x509HostnameVerifier,
int port, SSLContextParameters sslContextParams) throws Exception {
         SchemeRegistry registry = clientConnectionManager.getSchemeRegistry();
         if (secure) {
-            SSLSocketFactory socketFactory = null;
+            SSLSocketFactory socketFactory;
             if (sslContextParams == null) {
                 socketFactory = SSLSocketFactory.getSocketFactory();
             } else {

Modified: camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java?rev=1143693&r1=1143692&r2=1143693&view=diff
==============================================================================
--- camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java
(original)
+++ camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java
Thu Jul  7 07:38:25 2011
@@ -116,8 +116,10 @@ public class HttpEndpoint extends Defaul
         if (ObjectHelper.isNotEmpty(getCamelContext().getProperties().get("http.proxyHost"))
&& ObjectHelper.isNotEmpty(getCamelContext().getProperties().get("http.proxyPort")))
{
             String host = getCamelContext().getProperties().get("http.proxyHost");
             int port = Integer.parseInt(getCamelContext().getProperties().get("http.proxyPort"));
-            LOG.debug("CamelContext properties http.proxyHost and http.proxyPort detected.
Using http proxy host: {} port: {}", host, port);
-            HttpHost proxy = new HttpHost(host, port);
+            String scheme = getCamelContext().getProperties().get("http.proxyScheme");
+
+            LOG.debug("CamelContext properties http.proxyHost, http.proxyPort, and http.proxyScheme
detected. Using http proxy host: {} port: {} scheme: {}", new Object[]{host, port, scheme});
+            HttpHost proxy = new HttpHost(host, port, scheme);
             answer.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
         }
 

Modified: camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/ProxyHttpClientConfigurer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/ProxyHttpClientConfigurer.java?rev=1143693&r1=1143692&r2=1143693&view=diff
==============================================================================
--- camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/ProxyHttpClientConfigurer.java
(original)
+++ camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/ProxyHttpClientConfigurer.java
Thu Jul  7 07:38:25 2011
@@ -32,19 +32,20 @@ public class ProxyHttpClientConfigurer i
 
     private final String host;
     private final Integer port;
-
+    private final String scheme;
     private final String username;
     private final String password;
     private final String domain;
     private final String ntHost;
 
-    public ProxyHttpClientConfigurer(String host, Integer port) {
-        this(host, port, null, null, null, null);
+    public ProxyHttpClientConfigurer(String host, Integer port, String scheme) {
+        this(host, port, scheme, null, null, null, null);
     }
 
-    public ProxyHttpClientConfigurer(String host, Integer port, String username, String password,
String domain, String ntHost) {
+    public ProxyHttpClientConfigurer(String host, Integer port, String scheme, String username,
String password, String domain, String ntHost) {
         this.host = host;
         this.port = port;
+        this.scheme = scheme;
         this.username = username;
         this.password = password;
         this.domain = domain;
@@ -52,7 +53,7 @@ public class ProxyHttpClientConfigurer i
     }
 
     public void configureHttpClient(HttpClient client) {
-        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(host,
port));
+        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(host,
port, scheme));
 
         if (username != null && password != null) {
             Credentials defaultcreds;

Modified: camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpClientConfigurerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpClientConfigurerTest.java?rev=1143693&r1=1143692&r2=1143693&view=diff
==============================================================================
--- camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpClientConfigurerTest.java
(original)
+++ camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpClientConfigurerTest.java
Thu Jul  7 07:38:25 2011
@@ -37,7 +37,7 @@ public class HttpClientConfigurerTest ex
         return new RouteBuilder() {
             public void configure() {
                 // add configurer to http component
-                configurer = new ProxyHttpClientConfigurer("proxyhost", 80, "user", "password",
null, null);
+                configurer = new ProxyHttpClientConfigurer("proxyhost", 80, "http4", "user",
"password", null, null);
                 getContext().getComponent("http4", HttpComponent.class).setHttpClientConfigurer(configurer);
 
                 from("direct:start")



Mime
View raw message