You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/04/09 10:50:09 UTC

[2/5] git commit: CAMEL-7353 fixed camel-http4 issue when the hostname stars with http with thanks to Andreas

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/27c4a521
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/27c4a521
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/27c4a521

Branch: refs/heads/camel-2.13.x
Commit: 27c4a52133406760c5d2769d1ed6807d83a96a27
Parents: dd5faf3
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Apr 9 16:14:25 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Apr 9 16:48:38 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/27c4a521/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 5eb3ee3..e7820cd 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/27c4a521/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);
+        }
+         
+        
     }
 
 }