Return-Path: Delivered-To: apmail-activemq-camel-commits-archive@locus.apache.org Received: (qmail 53437 invoked from network); 3 Jan 2009 08:24:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jan 2009 08:24:53 -0000 Received: (qmail 71930 invoked by uid 500); 3 Jan 2009 08:24:53 -0000 Delivered-To: apmail-activemq-camel-commits-archive@activemq.apache.org Received: (qmail 71914 invoked by uid 500); 3 Jan 2009 08:24:53 -0000 Mailing-List: contact camel-commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: camel-dev@activemq.apache.org Delivered-To: mailing list camel-commits@activemq.apache.org Received: (qmail 71904 invoked by uid 99); 3 Jan 2009 08:24:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Jan 2009 00:24:53 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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, 03 Jan 2009 08:24:52 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 06DB6238895D; Sat, 3 Jan 2009 00:24:32 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r730936 - in /activemq/camel/trunk/components: camel-http/src/main/java/org/apache/camel/component/http/ camel-jetty/ camel-jetty/src/main/java/org/apache/camel/component/jetty/ camel-jetty/src/test/java/org/apache/camel/component/jetty/ Date: Sat, 03 Jan 2009 08:24:31 -0000 To: camel-commits@activemq.apache.org From: ningjiang@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090103082432.06DB6238895D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ningjiang Date: Sat Jan 3 00:24:31 2009 New Revision: 730936 URL: http://svn.apache.org/viewvc?rev=730936&view=rev Log: CAMEL-1217 Get the Jetty component's 'httpClient.' options to be set into the indeed apache http client; also some refactoring of camel-http component Modified: activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java activemq/camel/trunk/components/camel-jetty/pom.xml activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java Modified: activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java?rev=730936&r1=730935&r2=730936&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java (original) +++ activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java Sat Jan 3 00:24:31 2009 @@ -1,3 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.component.http; import org.apache.commons.httpclient.Credentials; Modified: activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java?rev=730936&r1=730935&r2=730936&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java (original) +++ activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java Sat Jan 3 00:24:31 2009 @@ -65,14 +65,15 @@ public void disconnect(HttpConsumer consumer) throws Exception { } - @Override - protected Endpoint createEndpoint(String uri, String remaining, Map parameters) - throws Exception { - - // http client can be configured from URI options - HttpClientParams params = new HttpClientParams(); - IntrospectionSupport.setProperties(params, parameters, "httpClient."); - + /** + * Setting http binding and http client configurer according to the parameters + * Also setting the BasicAuthenticationHttpClientConfigurer if the username + * and password option are not null. + * + * @param parameters the map of parameters + * + */ + protected void configureParameters(Map parameters) { // lookup http binding in registry if provided String ref = getAndRemoveParameter(parameters, "httpBindingRef", String.class); if (ref != null) { @@ -91,6 +92,17 @@ if (ref != null) { httpClientConfigurer = CamelContextHelper.mandatoryLookup(getCamelContext(), ref, HttpClientConfigurer.class); } + } + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map parameters) + throws Exception { + + // http client can be configured from URI options + HttpClientParams params = new HttpClientParams(); + IntrospectionSupport.setProperties(params, parameters, "httpClient."); + + configureParameters(parameters); // 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(uri), parameters); Modified: activemq/camel/trunk/components/camel-jetty/pom.xml URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/pom.xml?rev=730936&r1=730935&r2=730936&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-jetty/pom.xml (original) +++ activemq/camel/trunk/components/camel-jetty/pom.xml Sat Jan 3 00:24:31 2009 @@ -51,11 +51,7 @@ org.mortbay.jetty jetty - - org.mortbay.jetty - jetty-client - - + org.apache.camel Modified: activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java?rev=730936&r1=730935&r2=730936&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java (original) +++ activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java Sat Jan 3 00:24:31 2009 @@ -22,18 +22,16 @@ import org.apache.camel.Endpoint; import org.apache.camel.component.http.CamelServlet; -import org.apache.camel.component.http.HttpBinding; import org.apache.camel.component.http.HttpComponent; import org.apache.camel.component.http.HttpConsumer; import org.apache.camel.component.http.HttpEndpoint; -import org.apache.camel.util.CamelContextHelper; import org.apache.camel.util.IntrospectionSupport; import org.apache.camel.util.URISupport; +import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.mortbay.jetty.Connector; import org.mortbay.jetty.Server; -import org.mortbay.jetty.client.HttpClient; import org.mortbay.jetty.handler.ContextHandlerCollection; import org.mortbay.jetty.nio.SelectChannelConnector; import org.mortbay.jetty.security.SslSocketConnector; @@ -72,8 +70,7 @@ private static final transient Log LOG = LogFactory.getLog(JettyHttpComponent.class); protected Server server; - protected HashMap connectors = new HashMap(); - protected HttpClient httpClient; + protected HashMap connectors = new HashMap(); protected String sslKeyPassword; protected String sslPassword; protected String sslKeystore; @@ -83,23 +80,16 @@ protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { uri = uri.startsWith("jetty:") ? remaining : uri; - // http client can be configured from URI options - if (httpClient == null) { - httpClient = createHttpClient(); - } - IntrospectionSupport.setProperties(httpClient, parameters, "httpClient."); - - // lookup http binding in registry if provided - String ref = getAndRemoveParameter(parameters, "httpBindingRef", String.class); - if (ref != null) { - httpBinding = CamelContextHelper.mandatoryLookup(getCamelContext(), ref, HttpBinding.class); - } + HttpClientParams params = new HttpClientParams(); + IntrospectionSupport.setProperties(params, parameters, "httpClient."); + + configureParameters(parameters); // 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(uri), parameters); uri = httpUri.toString(); - JettyHttpEndpoint result = new JettyHttpEndpoint(this, uri, httpUri, getHttpConnectionManager()); + JettyHttpEndpoint result = new JettyHttpEndpoint(this, uri, httpUri, params, getHttpConnectionManager(), httpClientConfigurer); if (httpBinding != null) { result.setBinding(httpBinding); } @@ -283,31 +273,8 @@ if (server != null) { server.stop(); } - httpClient.stop(); + super.doStop(); } - - @Override - protected void doStart() throws Exception { - super.doStart(); - if (httpClient == null) { - httpClient = createHttpClient(); - } - httpClient.start(); - } - - protected HttpClient createHttpClient() throws Exception { - HttpClient httpClient = new HttpClient(); - httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); - httpClient.setMaxConnectionsPerAddress(2); - return httpClient; - } - - public HttpClient getHttpClient() { - return httpClient; - } - - public void setHttpClient(HttpClient httpClient) { - this.httpClient = httpClient; - } + } Modified: activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java?rev=730936&r1=730935&r2=730936&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java (original) +++ activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java Sat Jan 3 00:24:31 2009 @@ -24,10 +24,12 @@ import org.apache.camel.PollingConsumer; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.component.http.HttpClientConfigurer; import org.apache.camel.component.http.HttpConsumer; import org.apache.camel.component.http.HttpEndpoint; import org.apache.camel.component.http.HttpPollingConsumer; import org.apache.commons.httpclient.HttpConnectionManager; +import org.apache.commons.httpclient.params.HttpClientParams; /** * @version $Revision$ @@ -36,8 +38,9 @@ private JettyHttpComponent component; private boolean sessionSupport; - public JettyHttpEndpoint(JettyHttpComponent component, String uri, URI httpURL, HttpConnectionManager httpConnectionManager) throws URISyntaxException { - super(uri, component, httpURL, httpConnectionManager); + public JettyHttpEndpoint(JettyHttpComponent component, String uri, URI httpURL, HttpClientParams clientParams, + HttpConnectionManager httpConnectionManager, HttpClientConfigurer clientConfigurer) throws URISyntaxException { + super(uri, component, httpURL, clientParams, httpConnectionManager, clientConfigurer); this.component = component; } Modified: activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java?rev=730936&r1=730935&r2=730936&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java (original) +++ activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java Sat Jan 3 00:24:31 2009 @@ -17,7 +17,9 @@ package org.apache.camel.component.jetty; import org.apache.camel.ContextTestSupport; +import org.apache.camel.Endpoint; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.http.HttpProducer; /** * Unit test for http client options. @@ -26,9 +28,10 @@ public void testCustomHttpBinding() throws Exception { // assert jetty was configured with our timeout - JettyHttpComponent jetty = context.getComponent("jetty", JettyHttpComponent.class); - assertNotNull(jetty); - assertEquals(5555, jetty.getHttpClient().getIdleTimeout()); + JettyHttpEndpoint jettyEndpoint = (JettyHttpEndpoint) context.getEndpoint("jetty:http://localhost:8080/myapp/myservice?httpClient.soTimeout=5555"); + assertNotNull("Jetty endpoint should not be null ", jettyEndpoint); + HttpProducer producer = (HttpProducer)jettyEndpoint.createProducer(); + assertEquals("Get the wrong http client parameter", 5555, producer.getHttpClient().getParams().getSoTimeout()); // send and receive Object out = template.requestBody("http://localhost:8080/myapp/myservice", "Hello World"); @@ -40,7 +43,7 @@ return new RouteBuilder() { @Override public void configure() throws Exception { - from("jetty:http://localhost:8080/myapp/myservice?httpClient.idleTimeout=5555").transform().constant("Bye World"); + from("jetty:http://localhost:8080/myapp/myservice?httpClient.soTimeout=5555").transform().constant("Bye World"); } }; }