You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/10/17 20:36:12 UTC
[3/4] git commit: CAMEL-6872: camel-netty-http - support optional
parameters on Content-Type when extracting charset.
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/a28a7db4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a28a7db4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a28a7db4
Branch: refs/heads/master
Commit: a28a7db496ecd32ad400b9ffc8e09c3fca25aa42
Parents: 4c3d152
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Oct 17 20:01:49 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Oct 17 20:36:22 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/a28a7db4/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/a28a7db4/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() {