CAMEL-7353 fixed camel-http4 issue when the hostname stars with http with 
thanks to  Andreas


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1defc7b3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1defc7b3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1defc7b3

Branch: refs/heads/camel-2.12.x
Commit: 1defc7b363e021c8265883ea2bf7fca559114cd2
Parents: 665230d
Author: Willem Jiang <[email protected]>
Authored: Wed Apr 9 16:14:25 2014 +0800
Committer: Willem Jiang <[email protected]>
Committed: Wed Apr 9 16:49:33 2014 +0800

----------------------------------------------------------------------
 .../apache/camel/component/http4/HttpComponent.java    |  9 +--------
 .../camel/component/http4/HttpEndpointURLTest.java     | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1defc7b3/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
 
b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
index 1406968..aa4083b 100644
--- 
a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
+++ 
b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
@@ -208,14 +208,7 @@ public class HttpComponent extends 
HeaderFilterStrategyComponent {
         boolean secure = HttpHelper.isSecureConnection(uri) || 
sslContextParameters != null;
 
         // need to set scheme on address uri depending on if its secure or not
-        String addressUri = remaining.startsWith("http") ? remaining : null;
-        if (addressUri == null) {
-            if (secure) {
-                addressUri = "https://"; + remaining;
-            } else {
-                addressUri = "http://"; + remaining;
-            }
-        }
+        String addressUri = (secure ? "https://"; : "http://";) + remaining;
         
         addressUri = UnsafeUriCharactersEncoder.encodeHttpURI(addressUri);
         URI uriHttpUriAddress = new URI(addressUri);

http://git-wip-us.apache.org/repos/asf/camel/blob/1defc7b3/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointURLTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointURLTest.java
 
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointURLTest.java
index eadd2b5..2fa01a5 100644
--- 
a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointURLTest.java
+++ 
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointURLTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.http4;
 
+import org.apache.camel.ResolveEndpointFailedException;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
@@ -32,10 +33,20 @@ public class HttpEndpointURLTest extends CamelTestSupport {
         HttpEndpoint http1 = context.getEndpoint("http4://www.google.com", 
HttpEndpoint.class);
         HttpEndpoint http2 = 
context.getEndpoint("https4://www.google.com?test=parameter&proxyAuthHost=myotherproxy&proxyAuthPort=2345",
 HttpEndpoint.class);
         HttpEndpoint http3 = 
context.getEndpoint("https4://www.google.com?test=parameter", 
HttpEndpoint.class);
-       
+        
         assertEquals("Get a wrong HttpUri of http1", "http://www.google.com";, 
http1.getHttpUri().toString());
         assertEquals("Get a wrong HttpUri of http2", 
"https://www.google.com?test=parameter";, http2.getHttpUri().toString());
         assertEquals("Get a wrong HttpUri of http2 andhttp3", 
http2.getHttpUri(), http3.getHttpUri());
+        
+        try {
+            // need to catch the exception here
+            context.getEndpoint("https4://http://www.google.com";, 
HttpEndpoint.class);
+            fail("need to throw an exception here");
+        } catch (ResolveEndpointFailedException ex) {
+            assertTrue("Get a wrong exception message", 
ex.getMessage().indexOf("You have duplicated the http(s) protocol") > 0);
+        }
+         
+        
     }
 
 }

Reply via email to