camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject git commit: CAMEL-6327: camel-netty-http - Ensure CamelHttpUrl header is always using absolute http url, to be consistent and similar with camel-jetty.
Date Thu, 27 Jun 2013 09:36:12 GMT
Updated Branches:
  refs/heads/master b7e0a366f -> 020ddb9e1


CAMEL-6327: camel-netty-http - Ensure CamelHttpUrl header is always using absolute http url,
to be consistent and similar with camel-jetty.


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

Branch: refs/heads/master
Commit: 020ddb9e1fd77f74b3929f21955ab472e05c8088
Parents: b7e0a36
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Jun 27 11:35:36 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Jun 27 11:35:36 2013 +0200

----------------------------------------------------------------------
 .../component/netty/http/DefaultNettyHttpBinding.java  | 13 +++++++++++++
 .../camel/component/netty/http/NettyHttpEndpoint.java  |  7 ++++++-
 .../component/netty/http/NettyHttpContentTypeTest.java |  4 +++-
 3 files changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/020ddb9e/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
index 90ddba3..0a57638 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
@@ -92,6 +92,19 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding {
         if (s.contains("?")) {
             s = ObjectHelper.before(s, "?");
         }
+
+        // we want the full path for the url, as the client may provide the url in the HTTP
headers as absolute or relative, eg
+        //   /foo
+        //   http://servername/foo
+        String http = configuration.isSsl() ? "https://" : "http://";
+        if (!s.startsWith(http)) {
+            if (configuration.getPort() != 80) {
+                s = http + configuration.getHost() + ":" + configuration.getPort() + s;
+            } else {
+                s = http + configuration.getHost() + s;
+            }
+        }
+
         headers.put(Exchange.HTTP_URL, s);
         // uri is without the host and port
         URI uri = new URI(request.getUri());

http://git-wip-us.apache.org/repos/asf/camel/blob/020ddb9e/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
index 252ea46..c6a02f5 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
@@ -24,6 +24,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.component.netty.NettyConfiguration;
 import org.apache.camel.component.netty.NettyEndpoint;
+import org.apache.camel.converter.IOConverter;
 import org.apache.camel.impl.SynchronousDelegateProducer;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategyAware;
@@ -103,7 +104,11 @@ public class NettyHttpEndpoint extends NettyEndpoint implements HeaderFilterStra
 
         // honor the character encoding
         String contentType = in.getHeader(Exchange.CONTENT_TYPE, String.class);
-        NettyHttpHelper.setCharsetFromContentType(contentType, exchange);
+        String charset = NettyHttpHelper.getCharsetFromContentType(contentType);
+        if (charset != null) {
+            exchange.setProperty(Exchange.CHARSET_NAME, charset);
+            in.setHeader(Exchange.HTTP_CHARACTER_ENCODING, charset);
+        }
 
         return exchange;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/020ddb9e/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpContentTypeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpContentTypeTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpContentTypeTest.java
index 1330c8e..f0dade9 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpContentTypeTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpContentTypeTest.java
@@ -28,10 +28,12 @@ public class NettyHttpContentTypeTest extends BaseNettyTest {
     public void testContentType() throws Exception {
         getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");
         getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.CONTENT_TYPE, "text/plain;
charset=\"iso-8859-1\"");
+        getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_CHARACTER_ENCODING,
"iso-8859-1");
+        getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_URL, "http://0.0.0.0:"
+ getPort() + "/foo");
         getMockEndpoint("mock:input").expectedPropertyReceived(Exchange.CHARSET_NAME, "iso-8859-1");
 
         byte[] data = "Hello World".getBytes(Charset.forName("iso-8859-1"));
-        String out = template.requestBodyAndHeader("netty-http:http://localhost:{{port}}/foo",
data,
+        String out = template.requestBodyAndHeader("netty-http:http://0.0.0.0:{{port}}/foo",
data,
                 "content-type", "text/plain; charset=\"iso-8859-1\"", String.class);
         assertEquals("Bye World", out);
 


Mime
View raw message