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 2013/10/14 10:38:37 UTC
[2/2] git commit: CAMEL-6861 fixed the camel-netty-http route cannot
proxy the response which is chunked
CAMEL-6861 fixed the camel-netty-http route cannot proxy the response which is chunked
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9d7d54e7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9d7d54e7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9d7d54e7
Branch: refs/heads/master
Commit: 9d7d54e770a6ea1019ee8a7a99da6c9abb726fce
Parents: 32f32b9
Author: Willem Jiang <ni...@apache.org>
Authored: Mon Oct 14 16:20:53 2013 +0800
Committer: Willem Jiang <ni...@apache.org>
Committed: Mon Oct 14 16:35:33 2013 +0800
----------------------------------------------------------------------
.../netty/http/DefaultNettyHttpBinding.java | 5 ++++
.../http/handlers/HttpClientChannelHandler.java | 2 +-
.../NettyHttpClientChunkedResponseTest.java | 30 ++++++++++++++++----
3 files changed, 30 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/9d7d54e7/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 e64b800..84d315b 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
@@ -346,6 +346,11 @@ public class DefaultNettyHttpBinding implements NettyHttpBinding {
}
if (buffer != null) {
response.setContent(buffer);
+ // We just need to reset the readerIndex this time
+ if (buffer.readerIndex() == buffer.writerIndex()) {
+ buffer.setIndex(0, buffer.writerIndex());
+ }
+ // TODO How to enable the chunk transport
int len = buffer.readableBytes();
// set content-length
response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, len);
http://git-wip-us.apache.org/repos/asf/camel/blob/9d7d54e7/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpClientChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpClientChannelHandler.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpClientChannelHandler.java
index fc508e2..497ed45 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpClientChannelHandler.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpClientChannelHandler.java
@@ -85,7 +85,7 @@ public class HttpClientChannelHandler extends ClientChannelHandler {
// the copy must not be readable when the content was chunked, so set the index to the end
copy.setIndex(end, end);
response.setContent(copy);
- // we the all the content now, so call super to process the received message
+ // we get the all the content now, so call super to process the received message
super.messageReceived(ctx, messageEvent);
}
} else if (msg instanceof HttpResponse) {
http://git-wip-us.apache.org/repos/asf/camel/blob/9d7d54e7/tests/camel-itest/src/test/java/org/apache/camel/itest/nettyhttp/NettyHttpClientChunkedResponseTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/nettyhttp/NettyHttpClientChunkedResponseTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/nettyhttp/NettyHttpClientChunkedResponseTest.java
index 88cd3be..f9a6c4a 100644
--- a/tests/camel-itest/src/test/java/org/apache/camel/itest/nettyhttp/NettyHttpClientChunkedResponseTest.java
+++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/nettyhttp/NettyHttpClientChunkedResponseTest.java
@@ -25,12 +25,22 @@ import org.junit.Test;
public class NettyHttpClientChunkedResponseTest extends CamelTestSupport {
- private int port;
+ private int port1;
+ private int port2;
@Test
public void testNettyHttpClientChunked() throws Exception {
+ invokeService(port1, true);
+ }
+
+ @Test
+ public void testNettyHttpRouteClientChunked() throws Exception {
+ invokeService(port2, false);
+ }
+
+ private void invokeService(int port, boolean checkChunkedHeader) {
Exchange out = template.request("netty-http:http://localhost:" + port + "/test", new Processor() {
-// Exchange out = template.request("jetty:http://localhost:" + port + "/test", new Processor() {
+
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Camel in chunks.");
@@ -38,22 +48,30 @@ public class NettyHttpClientChunkedResponseTest extends CamelTestSupport {
});
assertNotNull(out);
-
assertEquals("Bye Camel in chunks.", out.getOut().getBody(String.class));
- assertEquals("chunked", out.getOut().getHeader("Transfer-Encoding"));
+ if (checkChunkedHeader) {
+ assertEquals("chunked", out.getOut().getHeader("Transfer-Encoding"));
+ }
}
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- port = AvailablePortFinder.getNextAvailable(8000);
+ port1 = AvailablePortFinder.getNextAvailable(8000);
+ port2 = AvailablePortFinder.getNextAvailable(9000);
// use jetty as server as it supports sending response as chunked encoding
- from("jetty:http://localhost:" + port + "/test")
+ from("jetty:http://localhost:" + port1 + "/test")
.setHeader("Transfer-Encoding", constant("chunked"))
.transform().simple("Bye ${body}");
+
+ // set up a netty http proxy
+ from("netty-http:http://localhost:" + port2 + "/test")
+ .to("netty-http:http://localhost:" + port1 + "/test?bridgeEndpoint=true&throwExceptionOnFailure=false");
+
}
};
}