Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 94E6C10F56 for ; Thu, 27 Jun 2013 09:36:19 +0000 (UTC) Received: (qmail 28946 invoked by uid 500); 27 Jun 2013 09:36:19 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 28835 invoked by uid 500); 27 Jun 2013 09:36:15 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 28817 invoked by uid 99); 27 Jun 2013 09:36:12 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Jun 2013 09:36:12 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 8C78C38475; Thu, 27 Jun 2013 09:36:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer 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 +0000 (UTC) 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 Authored: Thu Jun 27 11:35:36 2013 +0200 Committer: Claus Ibsen 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);