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:43:25 UTC

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

Repository: camel
Updated Branches:
  refs/heads/master 504b12caf -> ed5105800


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

Branch: refs/heads/master
Commit: ed51058008cf92bc10da3a4ccbfc80292d3f3241
Parents: 4fa5ffc
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:41:58 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/ed510580/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/ed510580/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);
+        }
+         
+        
     }
 
 }


[2/2] git commit: CAMEL-7355 Moving HttpPollingConsumer to use HttpClient 4.3.x API

Posted by ni...@apache.org.
CAMEL-7355 Moving HttpPollingConsumer to use HttpClient 4.3.x API


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

Branch: refs/heads/master
Commit: 4fa5ffcf9833281b09bff09315810436e41529b3
Parents: 504b12c
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Apr 9 16:08:50 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Apr 9 16:41:58 2014 +0800

----------------------------------------------------------------------
 .../apache/camel/component/http4/HttpComponent.java   | 14 --------------
 .../camel/component/http4/HttpPollingConsumer.java    |  9 ++++++---
 .../camel/component/http4/helper/HttpHelper.java      |  2 +-
 3 files changed, 7 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4fa5ffcf/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 1e80f00..5eb3ee3 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
@@ -302,20 +302,6 @@ public class HttpComponent extends HeaderFilterStrategyComponent {
         
         return endpoint;
     }
-   
-    private static int getPort(URI uri) {
-        int port = uri.getPort();
-        if (port < 0) {
-            if ("http4".equals(uri.getScheme()) || "http".equals(uri.getScheme())) {
-                port = 80;
-            } else if ("https4".equals(uri.getScheme()) || "https".equals(uri.getScheme())) {
-                port = 443;
-            } else {
-                throw new IllegalArgumentException("Unknown scheme, cannot determine port number for uri: " + uri);
-            }
-        }
-        return port;
-    }
     
     protected Registry<ConnectionSocketFactory> createConnectionRegistry(X509HostnameVerifier x509HostnameVerifier, SSLContextParameters sslContextParams)
         throws GeneralSecurityException, IOException {

http://git-wip-us.apache.org/repos/asf/camel/blob/4fa5ffcf/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpPollingConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpPollingConsumer.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpPollingConsumer.java
index 9ecf668..3cfb8ec 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpPollingConsumer.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpPollingConsumer.java
@@ -28,9 +28,10 @@ import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpRequestBase;
-import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.util.EntityUtils;
 
 /**
@@ -63,16 +64,18 @@ public class HttpPollingConsumer extends PollingConsumerSupport {
     protected Exchange doReceive(int timeout) {
         Exchange exchange = endpoint.createExchange();
         HttpRequestBase method = createMethod(exchange);
+        HttpClientContext httpClientContext = new HttpClientContext();
 
         // set optional timeout in millis
         if (timeout > 0) {
-            HttpConnectionParams.setSoTimeout(method.getParams(), timeout);
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).build();
+            httpClientContext.setRequestConfig(requestConfig);
         }
 
         HttpEntity responeEntity = null;
         try {
             // execute request
-            HttpResponse response = httpClient.execute(method);
+            HttpResponse response = httpClient.execute(method, httpClientContext);
             int responseCode = response.getStatusLine().getStatusCode();
             responeEntity = response.getEntity();
             Object body = HttpHelper.readResponseBodyFromInputStream(responeEntity.getContent(), exchange);

http://git-wip-us.apache.org/repos/asf/camel/blob/4fa5ffcf/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
index 930e566..5610d6a 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/helper/HttpHelper.java
@@ -151,7 +151,7 @@ public final class HttpHelper {
         } else {
             CachedOutputStream cos = new CachedOutputStream(exchange);
             IOHelper.copyAndCloseInput(is, cos);
-            return cos.getStreamCache();
+            return cos.newStreamCache();
         }
     }