Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B17B799D7 for ; Sat, 7 Apr 2012 08:43:56 +0000 (UTC) Received: (qmail 71979 invoked by uid 500); 7 Apr 2012 08:43:56 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 71947 invoked by uid 500); 7 Apr 2012 08:43:56 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 71936 invoked by uid 99); 7 Apr 2012 08:43:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Apr 2012 08:43:56 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Apr 2012 08:43:52 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 47AD423889EC; Sat, 7 Apr 2012 08:43:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1310700 - in /camel/branches/camel-2.9.x: ./ components/camel-http4/src/main/java/org/apache/camel/component/http4/ components/camel-http4/src/test/java/org/apache/camel/component/http4/ Date: Sat, 07 Apr 2012 08:43:31 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120407084331.47AD423889EC@eris.apache.org> Author: davsclaus Date: Sat Apr 7 08:43:30 2012 New Revision: 1310700 URL: http://svn.apache.org/viewvc?rev=1310700&view=rev Log: CAMEL-4693: Added support for httpContext option. Thanks to Jeff Segal for the patch. Modified: camel/branches/camel-2.9.x/ (props changed) camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java camel/branches/camel-2.9.x/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java Propchange: camel/branches/camel-2.9.x/ ------------------------------------------------------------------------------ Merged /camel/trunk:r1310695 Propchange: camel/branches/camel-2.9.x/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java?rev=1310700&r1=1310699&r2=1310700&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java (original) +++ camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java Sat Apr 7 08:43:30 2012 @@ -45,6 +45,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; @@ -60,6 +61,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(); @@ -172,12 +174,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; @@ -227,6 +234,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/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java?rev=1310700&r1=1310699&r2=1310700&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java (original) +++ camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java Sat Apr 7 08:43:30 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/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java?rev=1310700&r1=1310699&r2=1310700&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java (original) +++ camel/branches/camel-2.9.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java Sat Apr 7 08:43:30 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/branches/camel-2.9.x/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java?rev=1310700&r1=1310699&r2=1310700&view=diff ============================================================================== --- camel/branches/camel-2.9.x/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java (original) +++ camel/branches/camel-2.9.x/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java Sat Apr 7 08:43:30 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; }