Updated Branches: refs/heads/camel-2.12.x a53180622 -> 2b3704f97 refs/heads/master 4c3d1526c -> 160d992a2
CAMEL-6872: camel-netty-http - support optional parameters on Content-Type when extracting charset. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7d94e223 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7d94e223 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7d94e223 Branch: refs/heads/camel-2.12.x Commit: 7d94e223a92f2d236e1b05c9365dcceb1c583416 Parents: a531806 Author: Claus Ibsen <davscl...@apache.org> Authored: Thu Oct 17 20:01:49 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Oct 17 20:02:09 2013 +0200 ---------------------------------------------------------------------- .../camel/component/netty/http/NettyHttpHelper.java | 5 +++++ .../netty/http/NettyHttpContentTypeTest.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/7d94e223/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java index 22d89a3..0d4de7b 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java @@ -30,6 +30,7 @@ import org.apache.camel.Message; import org.apache.camel.RuntimeExchangeException; import org.apache.camel.converter.IOConverter; import org.apache.camel.util.IOHelper; +import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.URISupport; import org.apache.camel.util.UnsafeUriCharactersEncoder; import org.jboss.netty.handler.codec.http.HttpMethod; @@ -57,6 +58,10 @@ public final class NettyHttpHelper { int index = contentType.indexOf("charset="); if (index > 0) { String charset = contentType.substring(index + 8); + // there may be another parameter after a semi colon, so skip that + if (charset.contains(";")) { + charset = ObjectHelper.before(charset, ";"); + } return IOHelper.normalizeCharset(charset); } } http://git-wip-us.apache.org/repos/asf/camel/blob/7d94e223/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 f0dade9..67f8031 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 @@ -40,6 +40,22 @@ public class NettyHttpContentTypeTest extends BaseNettyTest { assertMockEndpointsSatisfied(); } + @Test + public void testContentTypeWithAction() throws Exception { + getMockEndpoint("mock:input").expectedBodiesReceived("Hello World"); + getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.CONTENT_TYPE, "text/plain;charset=\"iso-8859-1\";action=\"http://somewhere.com/foo"); + 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://0.0.0.0:{{port}}/foo", data, + "content-type", "text/plain;charset=\"iso-8859-1\";action=\"http://somewhere.com/foo", String.class); + assertEquals("Bye World", out); + + assertMockEndpointsSatisfied(); + } + @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() {