camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1310695 - in /camel/trunk/components/camel-http4/src: main/java/org/apache/camel/component/http4/ test/java/org/apache/camel/component/http4/
Date Sat, 07 Apr 2012 08:36:02 GMT
Author: davsclaus
Date: Sat Apr  7 08:36:02 2012
New Revision: 1310695

URL: http://svn.apache.org/viewvc?rev=1310695&view=rev
Log:
CAMEL-4693: Added support for httpContext option. Thanks to Jeff Segal for the patch.

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/HttpProducer.java
    camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.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=1310695&r1=1310694&r2=1310695&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
Sat Apr  7 08:36:02 2012
@@ -44,6 +44,7 @@ import org.apache.http.params.BasicHttpP
 import org.apache.http.params.HttpConnectionParamBean;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParamBean;
+import org.apache.http.protocol.HttpContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -59,6 +60,7 @@ public class HttpComponent extends Heade
     protected HttpClientConfigurer httpClientConfigurer;
     protected ClientConnectionManager clientConnectionManager;
     protected HttpBinding httpBinding;
+    protected HttpContext httpContext;
     protected SSLContextParameters sslContextParameters;
     protected X509HostnameVerifier x509HostnameVerifier = new BrowserCompatHostnameVerifier();
 
@@ -171,12 +173,17 @@ public class HttpComponent extends Heade
         if (httpBinding == null) {
             httpBinding = resolveAndRemoveReferenceParameter(parameters, "httpBinding", HttpBinding.class);
         }
-        
+
         HttpClientConfigurer httpClientConfigurer = resolveAndRemoveReferenceParameter(parameters,
"httpClientConfigurerRef", HttpClientConfigurer.class);
         if (httpClientConfigurer == null) {
             httpClientConfigurer = resolveAndRemoveReferenceParameter(parameters, "httpClientConfigurer",
HttpClientConfigurer.class);
         }
-        
+
+        HttpContext httpContext = resolveAndRemoveReferenceParameter(parameters, "httpContextRef",
HttpContext.class);
+        if (httpContext == null) {
+            httpContext = resolveAndRemoveReferenceParameter(parameters, "httpContext", HttpContext.class);
+        }
+
         X509HostnameVerifier x509HostnameVerifier = resolveAndRemoveReferenceParameter(parameters,
"x509HostnameVerifier", X509HostnameVerifier.class);
         if (x509HostnameVerifier == null) {
             x509HostnameVerifier = this.x509HostnameVerifier;
@@ -226,6 +233,9 @@ public class HttpComponent extends Heade
         if (httpClientConfigurer != null) {
             endpoint.setHttpClientConfigurer(httpClientConfigurer);
         }
+        if (httpContext != null) {
+            endpoint.setHttpContext(httpContext);
+        }
         // register port on schema registry
         int port = getPort(httpUri);
         registerPort(secure, x509HostnameVerifier, port, sslContextParameters);

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=1310695&r1=1310694&r2=1310695&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
Sat Apr  7 08:36:02 2012
@@ -33,6 +33,7 @@ import org.apache.http.conn.params.ConnR
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.params.BasicHttpParams;
 import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.HttpContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,6 +47,7 @@ public class HttpEndpoint extends Defaul
     private static final transient Logger LOG = LoggerFactory.getLogger(HttpEndpoint.class);
     private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
     private HttpBinding binding;
+    private HttpContext httpContext;
     private HttpComponent component;
     private URI httpUri;
     private HttpParams clientParams;
@@ -184,6 +186,10 @@ public class HttpEndpoint extends Defaul
         return httpClientConfigurer;
     }
 
+    public HttpContext getHttpContext() {
+        return httpContext;
+    }
+
     /**
      * Register a custom configuration strategy for new {@link HttpClient} instances
      * created by producers or consumers such as to configure authentication mechanisms etc
@@ -205,22 +211,18 @@ public class HttpEndpoint extends Defaul
         this.binding = binding;
     }
     
-    /**
-     * Used from the IntrospectionSupport in HttpComponent.
-     * @param binding
-     */
     public void setHttpBinding(HttpBinding binding) {
         this.binding = binding;
     }
-    
-    /**
-     * Used from the IntrospectionSupport in HttpComponent.
-     * @param binding
-     */
+
     public void setHttpBindingRef(HttpBinding binding) {
         this.binding = binding;
     }
 
+    public void setHttpContext(HttpContext httpContext) {
+        this.httpContext = httpContext;
+    }
+
     public String getPath() {
         return httpUri.getPath();
     }

Modified: camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java?rev=1310695&r1=1310694&r2=1310695&view=diff
==============================================================================
--- camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
(original)
+++ camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
Sat Apr  7 08:36:02 2012
@@ -56,6 +56,7 @@ import org.apache.http.entity.FileEntity
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.EntityUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -66,12 +67,14 @@ import org.slf4j.LoggerFactory;
 public class HttpProducer extends DefaultProducer {
     private static final transient Logger LOG = LoggerFactory.getLogger(HttpProducer.class);
     private HttpClient httpClient;
+    private HttpContext httpContext;
     private boolean throwException;
     private boolean transferException;
 
     public HttpProducer(HttpEndpoint endpoint) {
         super(endpoint);
         this.httpClient = endpoint.getHttpClient();
+        this.httpContext = endpoint.getHttpContext();
         this.throwException = endpoint.isThrowExceptionOnFailure();
         this.transferException = endpoint.isTransferException();
     }
@@ -234,7 +237,11 @@ public class HttpProducer extends Defaul
      * @throws IOException can be thrown
      */
     protected HttpResponse executeMethod(HttpUriRequest httpRequest) throws IOException {
-        return httpClient.execute(httpRequest);
+        if (httpContext != null) {
+            return httpClient.execute(httpRequest, httpContext);
+        } else {
+            return httpClient.execute(httpRequest);
+        }
     }
 
     /**

Modified: camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java?rev=1310695&r1=1310694&r2=1310695&view=diff
==============================================================================
--- camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java
(original)
+++ camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java
Sat Apr  7 08:36:02 2012
@@ -20,6 +20,8 @@ import org.apache.camel.builder.RouteBui
 import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.http.client.HttpClient;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpContext;
 import org.junit.Test;
 
 /**
@@ -29,19 +31,21 @@ import org.junit.Test;
  */
 public class HttpReferenceParameterTest extends CamelTestSupport {
 
-    private static final String TEST_URI_1 = "http4://localhost:8080?httpBindingRef=#customBinding&httpClientConfigurerRef=#customConfigurer";
-    private static final String TEST_URI_2 = "http4://localhost:8081?httpBindingRef=customBinding&httpClientConfigurerRef=customConfigurer";
+    private static final String TEST_URI_1 = "http4://localhost:8080?httpBindingRef=#customBinding&httpClientConfigurerRef=#customConfigurer&httpContext=#customContext";
+    private static final String TEST_URI_2 = "http4://localhost:8081?httpBindingRef=customBinding&httpClientConfigurerRef=customConfigurer&httpContext=customContext";
 
     private HttpEndpoint endpoint1;
     private HttpEndpoint endpoint2;
 
     private TestHttpBinding testBinding;
     private TestClientConfigurer testConfigurer;
+    private HttpContext testHttpContext;
 
     @Override
     public void setUp() throws Exception {
         this.testBinding = new TestHttpBinding();
         this.testConfigurer = new TestClientConfigurer();
+        this.testHttpContext = new BasicHttpContext();
         super.setUp();
         this.endpoint1 = context.getEndpoint(TEST_URI_1, HttpEndpoint.class);
         this.endpoint2 = context.getEndpoint(TEST_URI_2, HttpEndpoint.class);
@@ -59,11 +63,18 @@ public class HttpReferenceParameterTest 
         assertSame(testConfigurer, endpoint2.getHttpClientConfigurer());
     }
 
+    @Test
+    public void testHttpContextRef() {
+        assertSame(testHttpContext, endpoint1.getHttpContext());
+        assertSame(testHttpContext, endpoint2.getHttpContext());
+    }
+
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry registry = super.createRegistry();
         registry.bind("customBinding", testBinding);
         registry.bind("customConfigurer", testConfigurer);
+        registry.bind("customContext", testHttpContext);
         return registry;
     }
 



Mime
View raw message