Author: ningjiang
Date: Fri Apr 19 07:22:53 2013
New Revision: 1469718

URL: http://svn.apache.org/r1469718
Log:
CAMEL-6296 Support httpConnectionManager.* parameters on Camel-Http

Added:
    
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpConnectionManagerSettingTest.java
Modified:
    
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java

Modified: 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java?rev=1469718&r1=1469717&r2=1469718&view=diff
==============================================================================
--- 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
 (original)
+++ 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
 Fri Apr 19 07:22:53 2013
@@ -33,6 +33,7 @@ import org.apache.camel.util.URISupport;
 import org.apache.commons.httpclient.HttpConnectionManager;
 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
 import org.apache.commons.httpclient.params.HttpClientParams;
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
 
 /**
  * Defines the <a href="http://camel.apache.org/http.html";>HTTP
@@ -42,7 +43,7 @@ import org.apache.commons.httpclient.par
  */
 public class HttpComponent extends HeaderFilterStrategyComponent {
     protected HttpClientConfigurer httpClientConfigurer;
-    protected HttpConnectionManager httpConnectionManager = new 
MultiThreadedHttpConnectionManager();
+    protected HttpConnectionManager httpConnectionManager;
     protected HttpBinding httpBinding;
     protected HttpConfiguration httpConfiguration;
 
@@ -217,14 +218,28 @@ public class HttpComponent extends Heade
         IntrospectionSupport.setProperties(clientParams, parameters, 
"httpClient.");
         // validate that we could resolve all httpClient. parameters as this 
component is lenient
         validateParameters(uri, parameters, "httpClient.");       
-        
+        // http client can be configured from URI options
+        HttpConnectionManagerParams connectionManagerParams = new 
HttpConnectionManagerParams();
+        // setup the httpConnectionManagerParams
+        IntrospectionSupport.setProperties(connectionManagerParams, 
parameters, "httpConnectionManager.");
+        validateParameters(uri, parameters, "httpConnectionManager.");
+        // make sure the component httpConnectionManager is take effect
+        HttpConnectionManager thisHttpConnectionManager = 
httpConnectionManager;
+        if (thisHttpConnectionManager == null) {
+            // only set the params on the new created http connection manager
+            thisHttpConnectionManager = new 
MultiThreadedHttpConnectionManager();
+            thisHttpConnectionManager.setParams(connectionManagerParams);
+        }
         // create the configurer to use for this endpoint (authMethods 
contains the used methods created by the configurer)
         final Set<AuthMethod> authMethods = new LinkedHashSet<AuthMethod>();
         HttpClientConfigurer configurer = 
createHttpClientConfigurer(parameters, authMethods);
         URI endpointUri = URISupport.createRemainingURI(new URI(addressUri), 
httpClientParameters);
        
         // create the endpoint
-        HttpEndpoint endpoint = new HttpEndpoint(endpointUri.toString(), this, 
clientParams, httpConnectionManager, configurer);
+        HttpEndpoint endpoint = new HttpEndpoint(endpointUri.toString(), this, 
clientParams, thisHttpConnectionManager, configurer);
+        
+        endpoint.getHttpConnectionManager().setParams(connectionManagerParams);
+        
         if (headerFilterStrategy != null) {
             endpoint.setHeaderFilterStrategy(headerFilterStrategy);
         } else {

Added: 
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpConnectionManagerSettingTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpConnectionManagerSettingTest.java?rev=1469718&view=auto
==============================================================================
--- 
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpConnectionManagerSettingTest.java
 (added)
+++ 
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpConnectionManagerSettingTest.java
 Fri Apr 19 07:22:53 2013
@@ -0,0 +1,57 @@
+/**
+ * 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 static org.apache.camel.component.http.HttpMethods.POST;
+import org.apache.camel.Exchange;
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
+import org.junit.Before;
+import org.junit.Test;
+
+public class HttpConnectionManagerSettingTest extends CamelTestSupport {
+    
+    @Before
+    public void setUp() throws Exception {
+        try {
+            super.setUp();
+            fail("Should have thrown ResolveEndpointFailedException");
+        } catch (FailedToCreateRouteException e) {
+            ResolveEndpointFailedException cause = 
assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
+            assertTrue(cause.getMessage().endsWith("Unknown 
parameters=[{xxx=true}]"));
+        }
+    }
+
+    @Test
+    public void testHttpConnectionManagerSettingConfiguration() {
+        HttpEndpoint endpoint = 
(HttpEndpoint)context.getEndpoint("http://www.google.com?httpConnectionManager.maxTotalConnections=300";);
+        HttpConnectionManagerParams params = 
endpoint.getHttpConnectionManager().getParams();
+        assertEquals("Get the wrong parameter.", 300, 
params.getMaxTotalConnections());
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start").setHeader(Exchange.HTTP_METHOD, 
POST).to("http://www.google.com?httpConnectionManager.xxx=true";);
+            }
+        };
+    }
+
+}


Reply via email to