Author: ningjiang
Date: Thu Jul 15 14:51:10 2010
New Revision: 964453

URL: http://svn.apache.org/viewvc?rev=964453&view=rev
Log:
CAMEL-2950, CAMEL-2945 Fixed the issue of HttpEndpoint uri

Modified:
    
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
    
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpGetTest.java
    
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
    
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.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=964453&r1=964452&r2=964453&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
 Thu Jul 15 14:51:10 2010
@@ -17,6 +17,7 @@
 package org.apache.camel.component.http;
 
 import java.net.URI;
+import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
@@ -195,7 +196,11 @@ public class HttpComponent extends Heade
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
-
+        String addressUri = uri;
+        if (!uri.startsWith("http:") && !uri.startsWith("https:")) {
+            addressUri = remaining;
+        }
+        Map<String, Object> httpClientParameters = new HashMap<String, 
Object>(parameters);
         // must extract well known parameters before we create the endpoint
         HttpBinding binding = resolveAndRemoveReferenceParameter(parameters, 
"httpBindingRef", HttpBinding.class);
         if (binding == null) {
@@ -218,11 +223,10 @@ public class HttpComponent extends Heade
         // 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), 
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(uri), 
CastUtils.cast(parameters));
-        uri = httpUri.toString();
-
+        URI httpUri = URISupport.createRemainingURI(new URI(addressUri), 
CastUtils.cast(parameters));
+        
         // validate http uri that end-user did not duplicate the http part 
that can be a common error
         String part = httpUri.getSchemeSpecificPart();
         if (part != null) {
@@ -232,9 +236,10 @@ public class HttpComponent extends Heade
                         "The uri part is not configured correctly. You have 
duplicated the http(s) protocol.");
             }
         }
+        // need to keep the parameters of http client configure to avoid 
unwiser endpoint caching
 
         // create the endpoint
-        HttpEndpoint endpoint = new HttpEndpoint(uri, this, httpUri, 
clientParams, httpConnectionManager, configurer);
+        HttpEndpoint endpoint = new HttpEndpoint(endpointUri.toString(), this, 
httpUri, clientParams, httpConnectionManager, configurer);
         setEndpointHeaderFilterStrategy(endpoint);
 
         // prefer to use endpoint configured over component configured

Modified: 
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpGetTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpGetTest.java?rev=964453&r1=964452&r2=964453&view=diff
==============================================================================
--- 
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpGetTest.java
 (original)
+++ 
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpGetTest.java
 Thu Jul 15 14:51:10 2010
@@ -71,8 +71,9 @@ public class HttpGetTest extends CamelTe
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
+                getContext().addComponent("http2", new HttpComponent());
                 from("direct:start").setHeader(Exchange.HTTP_QUERY, 
constant("hl=en&q=activemq"))
-                    .to("http://www.google.com/search";).to("mock:results");
+                    
.to("http2://http://www.google.com/search";).to("mock:results");
             }
         };
     }

Modified: 
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java?rev=964453&r1=964452&r2=964453&view=diff
==============================================================================
--- 
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
 (original)
+++ 
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
 Thu Jul 15 14:51:10 2010
@@ -33,6 +33,25 @@ public class HttpProxyTest extends Camel
         assertNull("No proxy configured yet", 
client.getHostConfiguration().getProxyHost());
         assertEquals("No proxy configured yet", -1, 
client.getHostConfiguration().getProxyPort());
     }
+    
+    @Test
+    public void testDifferentHttpProxyConfigured() throws Exception {
+        HttpEndpoint http1 = 
context.getEndpoint("http://www.google.com?proxyHost=myproxy&proxyPort=1234";, 
HttpEndpoint.class);
+        HttpEndpoint http2 = 
context.getEndpoint("http://www.google.com?test=parameter&proxyHost=myotherproxy&proxyPort=2345";,
 HttpEndpoint.class);
+        
+        HttpClient client1 = http1.createHttpClient();
+        assertEquals("myproxy", client1.getHostConfiguration().getProxyHost());
+        assertEquals(1234, client1.getHostConfiguration().getProxyPort());
+        
+        HttpClient client2 = http2.createHttpClient();
+        assertEquals("myotherproxy", 
client2.getHostConfiguration().getProxyHost());
+        assertEquals(2345, client2.getHostConfiguration().getProxyPort());
+
+        assertEquals("Get a wrong endpoint uri", 
"http://www.google.com?proxyHost=myproxy&proxyPort=1234";, 
http1.getEndpointUri());
+        assertEquals("Get a wrong endpoint uri", 
"http://www.google.com?test=parameter&proxyHost=myotherproxy&proxyPort=2345";, 
http2.getEndpointUri());
+       
+        assertEquals("Should get the same EndpointKey", 
http1.getEndpointKey(), http2.getEndpointKey());
+    }
 
     @Test
     public void testHttpProxyConfigured() throws Exception {

Modified: 
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java?rev=964453&r1=964452&r2=964453&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
 (original)
+++ 
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
 Thu Jul 15 14:51:10 2010
@@ -109,8 +109,9 @@ public class JettyHttpComponent extends 
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
-        uri = uri.startsWith("jetty:") ? remaining : uri;
-
+        String addressUri = uri.startsWith("jetty:") ? remaining : uri;
+        Map<String, Object> httpClientParameters = new HashMap<String, 
Object>(parameters);
+        
         // must extract well known parameters before we create the endpoint
         List<Handler> handlerList = 
resolveAndRemoveReferenceListParameter(parameters, "handlers", Handler.class);
         HttpBinding binding = resolveAndRemoveReferenceParameter(parameters, 
"httpBindingRef", HttpBinding.class);
@@ -130,13 +131,17 @@ public class JettyHttpComponent extends 
             // validate that we could resolve all httpClient. parameters as 
this component is lenient
             validateParameters(uri, parameters, "httpClient.");
         }
-
+        // keep the configure parameters for the http client
+        for (String key : parameters.keySet()) {
+            httpClientParameters.remove(key);
+        }
+        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(uri), 
CastUtils.cast(parameters));
-        uri = httpUri.toString();
-
+        URI httpUri = URISupport.createRemainingURI(new URI(addressUri), 
CastUtils.cast(parameters));
+     
         // create endpoint after all known parameters have been extracted from 
parameters
-        JettyHttpEndpoint endpoint = new JettyHttpEndpoint(this, uri, httpUri);
+        JettyHttpEndpoint endpoint = new JettyHttpEndpoint(this, 
endpointUri.toString(), httpUri);
         setEndpointHeaderFilterStrategy(endpoint);
 
         if (client != null) {


Reply via email to