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 2014/12/22 02:09:05 UTC
[1/3] camel git commit: CAMEL-8169 Camel Jetty/Http4 producers should
respect Content-Length/Transfer-Encoding:Chunked headers
Repository: camel
Updated Branches:
refs/heads/master 4dfdc8414 -> 97634ae69
CAMEL-8169 Camel Jetty/Http4 producers should respect Content-Length/Transfer-Encoding:Chunked headers
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/97634ae6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/97634ae6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/97634ae6
Branch: refs/heads/master
Commit: 97634ae69587f4327dcefae3b54672d3914ce7ac
Parents: cefb210
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Dec 22 08:56:13 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Dec 22 09:08:30 2014 +0800
----------------------------------------------------------------------
.../component/http4/HttpEntityConverter.java | 11 ++-
.../camel/component/http4/HttpProducer.java | 8 +-
.../component/jetty/JettyHttpProducer.java | 5 ++
.../itest/http/HttpRouteContentLengthTest.java | 91 ++++++++++++++++++++
.../http/JettyHttpRouteContentLengthTest.java | 25 ++++++
5 files changed, 138 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/97634ae6/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java
index 8236da8..bcbe502 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEntityConverter.java
@@ -22,8 +22,10 @@ import java.io.InputStream;
import org.apache.camel.Converter;
import org.apache.camel.Exchange;
+import org.apache.camel.Message;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.GZIPHelper;
+import org.apache.camel.util.ObjectHelper;
import org.apache.http.HttpEntity;
import org.apache.http.entity.AbstractHttpEntity;
import org.apache.http.entity.ByteArrayEntity;
@@ -67,7 +69,14 @@ public final class HttpEntityConverter {
entity = new InputStreamEntity(stream, stream instanceof ByteArrayInputStream
? stream.available() != 0 ? stream.available() : -1 : -1);
} else {
- entity = new InputStreamEntity(in, -1);
+ Message inMessage = exchange.getIn();
+ String length = inMessage.getHeader(Exchange.CONTENT_LENGTH, String.class);
+
+ if (ObjectHelper.isEmpty(length)) {
+ entity = new InputStreamEntity(in, -1);
+ } else {
+ entity = new InputStreamEntity(in, Long.parseLong(length));
+ }
}
if (exchange != null) {
String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/97634ae6/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
index d41dbe1..01709eb 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
@@ -464,7 +464,13 @@ public class HttpProducer extends DefaultProducer {
if (answer == null) {
// force the body as an input stream since this is the fallback
InputStream is = in.getMandatoryBody(InputStream.class);
- InputStreamEntity entity = new InputStreamEntity(is, -1);
+ String length = in.getHeader(Exchange.CONTENT_LENGTH, String.class);
+ InputStreamEntity entity = null;
+ if (ObjectHelper.isEmpty(length)) {
+ entity = new InputStreamEntity(is, -1);
+ } else {
+ entity = new InputStreamEntity(is, Long.parseLong(length));
+ }
if (contentType != null) {
entity.setContentType(contentType.toString());
}
http://git-wip-us.apache.org/repos/asf/camel/blob/97634ae6/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
index 93f4380..17132af 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpProducer.java
@@ -154,6 +154,11 @@ public class JettyHttpProducer extends DefaultAsyncProducer implements AsyncProc
// then fallback to input stream
InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, exchange, exchange.getIn().getBody());
httpExchange.setRequestContent(is);
+ // setup the content length if it is possible
+ String length = exchange.getIn().getHeader(Exchange.CONTENT_LENGTH, String.class);
+ if (ObjectHelper.isNotEmpty(length)) {
+ httpExchange.addRequestHeader(Exchange.CONTENT_LENGTH, length);
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/97634ae6/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpRouteContentLengthTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpRouteContentLengthTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpRouteContentLengthTest.java
new file mode 100644
index 0000000..b4c8918
--- /dev/null
+++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpRouteContentLengthTest.java
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.itest.http;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class HttpRouteContentLengthTest extends CamelTestSupport {
+
+ private int port1;
+ private int port2;
+
+ @Test
+ public void testHttpClientContentLength() throws Exception {
+ invokeService(port1, true);
+ }
+
+ @Test
+ public void testHttpRouteContentLength() throws Exception {
+ invokeService(port2, false);
+ }
+
+ private void invokeService(int port, boolean checkChunkedHeader) {
+ Exchange out = template.request("http://localhost:" + port + "/test", new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setBody("Camel request.");
+ }
+ });
+
+ assertNotNull(out);
+ assertEquals("Bye Camel request.: 14", out.getOut().getBody(String.class));
+
+
+
+ }
+
+ protected String getHttpEndpointScheme() {
+ return "http4://localhost:";
+ }
+
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ port1 = AvailablePortFinder.getNextAvailable(8000);
+ port2 = AvailablePortFinder.getNextAvailable(9000);
+
+ // use jetty as server as it supports sending response as chunked encoding
+ from("jetty:http://localhost:" + port1 + "/test")
+ .process(new Processor() {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ String contentLength = exchange.getIn().getHeader(Exchange.CONTENT_LENGTH, String.class);
+ String request = exchange.getIn().getBody(String.class);
+ exchange.getOut().setBody(request + ": " + contentLength);
+ }
+
+ })
+ .transform().simple("Bye ${body}");
+
+ // set up a netty http proxy
+ from("jetty:http://localhost:" + port2 + "/test")
+ .to(getHttpEndpointScheme() + port1 + "/test?bridgeEndpoint=true&throwExceptionOnFailure=false");
+
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/97634ae6/tests/camel-itest/src/test/java/org/apache/camel/itest/http/JettyHttpRouteContentLengthTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/http/JettyHttpRouteContentLengthTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/http/JettyHttpRouteContentLengthTest.java
new file mode 100644
index 0000000..db21146
--- /dev/null
+++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/http/JettyHttpRouteContentLengthTest.java
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.itest.http;
+
+public class JettyHttpRouteContentLengthTest extends HttpRouteContentLengthTest {
+
+ protected String getHttpEndpointScheme() {
+ return "jetty://http://localhost:";
+ }
+
+}
[2/3] camel git commit: CAMEL-8168 Added an unit test in camel-mina
Posted by ni...@apache.org.
CAMEL-8168 Added an unit test in camel-mina
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/cefb210e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cefb210e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cefb210e
Branch: refs/heads/master
Commit: cefb210efecfaa8659c213b45ecc63524a96b11f
Parents: 4e4cc18
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Dec 22 08:50:04 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Dec 22 09:08:30 2014 +0800
----------------------------------------------------------------------
.../org/apache/camel/component/mina/MinaTcpTest.java | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/cefb210e/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java b/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java
index f5a8d8e..ffa9f46 100644
--- a/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java
+++ b/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTest.java
@@ -26,7 +26,18 @@ import org.junit.Test;
public class MinaTcpTest extends BaseMinaTest {
@Test
- public void testMinaRoute() throws Exception {
+ public void testMinaRoute1() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:result");
+ Object body = "Hello there!";
+ endpoint.expectedBodiesReceived(body);
+
+ template.sendBodyAndHeader("mina:tcp://localhost:{{port}}?sync=false&minaLogger=true", body, "cheese", 123);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testMinaRoute2() throws Exception {
MockEndpoint endpoint = getMockEndpoint("mock:result");
Object body = "Hello there!";
endpoint.expectedBodiesReceived(body);
@@ -39,7 +50,7 @@ public class MinaTcpTest extends BaseMinaTest {
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
- from("mina:tcp://localhost:{{port}}?sync=false&minaLogger=true")
+ from("mina:tcp://0.0.0.0:{{port}}?sync=false&minaLogger=true")
.to("log:before?showAll=true").to("mock:result").to("log:after?showAll=true");
}
};
[3/3] camel git commit: CAMEL-8168 Fixed the issue that mina2 doesn't
unbind from the listening port
Posted by ni...@apache.org.
CAMEL-8168 Fixed the issue that mina2 doesn't unbind from the listening port
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4e4cc189
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4e4cc189
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4e4cc189
Branch: refs/heads/master
Commit: 4e4cc18929ae1e35515667d368be687d31930a93
Parents: 4dfdc84
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Dec 22 08:49:14 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Dec 22 09:08:30 2014 +0800
----------------------------------------------------------------------
.../apache/camel/component/mina2/Mina2Consumer.java | 10 +++++++++-
.../apache/camel/component/mina2/Mina2TcpTest.java | 15 +++++++++++++--
2 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4e4cc189/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java
----------------------------------------------------------------------
diff --git a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java
index df85635..deea5b6 100644
--- a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java
+++ b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java
@@ -95,7 +95,15 @@ public class Mina2Consumer extends DefaultConsumer {
@Override
protected void doStop() throws Exception {
LOG.info("Unbinding from server address: {} using acceptor: {}", address, acceptor);
- acceptor.unbind(address);
+ // need to check if the address is IPV4 TCP all net work address
+ if (address instanceof InetSocketAddress) {
+ if ("0.0.0.0".equals(((InetSocketAddress)address).getAddress().getHostAddress())) {
+ acceptor.unbind(acceptor.getLocalAddresses());
+ }
+ } else {
+ acceptor.unbind(address);
+ }
+
super.doStop();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4e4cc189/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java b/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java
index f268a10..f9b1762 100644
--- a/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java
+++ b/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTest.java
@@ -26,7 +26,18 @@ import org.junit.Test;
public class Mina2TcpTest extends BaseMina2Test {
@Test
- public void testMinaRoute() throws Exception {
+ public void testMinaRoute1() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:result");
+ Object body = "Hello there!";
+ endpoint.expectedBodiesReceived(body);
+
+ template.sendBodyAndHeader(String.format("mina2:tcp://localhost:%1$s?sync=false&minaLogger=true", getPort()), body, "cheese", 123);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testMinaRoute2() throws Exception {
MockEndpoint endpoint = getMockEndpoint("mock:result");
Object body = "Hello there!";
endpoint.expectedBodiesReceived(body);
@@ -40,7 +51,7 @@ public class Mina2TcpTest extends BaseMina2Test {
return new RouteBuilder() {
public void configure() {
- from(String.format("mina2:tcp://localhost:%1$s?sync=false&minaLogger=true", getPort())).to("log:before?showAll=true").to("mock:result").to("log:after?showAll=true");
+ from(String.format("mina2:tcp://0.0.0.0:%1$s?sync=false&minaLogger=true", getPort())).to("log:before?showAll=true").to("mock:result").to("log:after?showAll=true");
}
};
}