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/06/16 15:27:40 UTC
[1/2] git commit: CAMEL-7500 updated the state of exceptionHandled to
avoid the callback be called twice when the ChannelClosedException is thrown.
Repository: camel
Updated Branches:
refs/heads/master d62ac0f4e -> bd4f8d1e8
CAMEL-7500 updated the state of exceptionHandled to avoid the callback be called twice when the ChannelClosedException is thrown.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/bd4f8d1e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bd4f8d1e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bd4f8d1e
Branch: refs/heads/master
Commit: bd4f8d1e8e686e37ebfbd1c400e6d0a422a23ae9
Parents: f01a736
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Jun 16 11:03:27 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Jun 16 21:27:04 2014 +0800
----------------------------------------------------------------------
.../camel/component/netty/handlers/ClientChannelHandler.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/bd4f8d1e/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
index c9f997f..e0ddb9f 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
@@ -62,8 +62,8 @@ public class ClientChannelHandler extends SimpleChannelUpstreamHandler {
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent exceptionEvent) throws Exception {
if (LOG.isTraceEnabled()) {
LOG.trace("Exception caught at Channel: " + ctx.getChannel(), exceptionEvent.getCause());
-
}
+
if (exceptionHandled) {
// ignore subsequent exceptions being thrown
return;
@@ -108,6 +108,8 @@ public class ClientChannelHandler extends SimpleChannelUpstreamHandler {
producer.getAllChannels().remove(ctx.getChannel());
if (producer.getConfiguration().isSync() && !messageReceived && !exceptionHandled) {
+ // To avoid call the callback.done twice
+ exceptionHandled = true;
// session was closed but no message received. This could be because the remote server had an internal error
// and could not return a response. We should count down to stop waiting for a response
if (LOG.isDebugEnabled()) {
[2/2] git commit: Added an unit test to show how to send multi part
form request entity to the server
Posted by ni...@apache.org.
Added an unit test to show how to send multi part form request entity to the server
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f01a7366
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f01a7366
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f01a7366
Branch: refs/heads/master
Commit: f01a736657903e83d2ee7b05daa851342690ba5a
Parents: d62ac0f
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Jun 16 10:08:46 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Jun 16 21:27:04 2014 +0800
----------------------------------------------------------------------
.../component/jetty/MultiPartFormTest.java | 53 +++++++++++++-------
1 file changed, 35 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f01a7366/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormTest.java
index 201ebd7..7c81101 100644
--- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormTest.java
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormTest.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.jetty;
import java.io.File;
+
import javax.activation.DataHandler;
import org.apache.camel.Exchange;
@@ -25,28 +26,32 @@ import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;
+import org.apache.commons.httpclient.params.HttpMethodParams;
import org.junit.Test;
public class MultiPartFormTest extends BaseJettyTest {
+ private RequestEntity createMultipartRequestEntity() throws Exception {
+ File file = new File("src/main/resources/META-INF/NOTICE.txt");
+
+ Part[] parts = {new StringPart("comment", "A binary file of some kind"),
+ new FilePart(file.getName(), file)};
+
+ return new MultipartRequestEntity(parts, new HttpMethodParams());
+
+ }
@Test
public void testSendMultiPartForm() throws Exception {
HttpClient httpclient = new HttpClient();
- File file = new File("src/main/resources/META-INF/NOTICE.txt");
-
PostMethod httppost = new PostMethod("http://localhost:" + getPort() + "/test");
- Part[] parts = {
- new StringPart("comment", "A binary file of some kind"),
- new FilePart(file.getName(), file)
- };
-
- MultipartRequestEntity reqEntity = new MultipartRequestEntity(parts, httppost.getParams());
- httppost.setRequestEntity(reqEntity);
+
+ httppost.setRequestEntity(createMultipartRequestEntity());
int status = httpclient.executeMethod(httppost);
@@ -57,15 +62,23 @@ public class MultiPartFormTest extends BaseJettyTest {
}
+ @Test
+ public void testSendMultiPartFormFromCamelHttpComponnent() throws Exception {
+ String result = template.requestBody("http://localhost:" + getPort() + "/test", createMultipartRequestEntity(), String.class);
+ assertEquals("Get a wrong result", "A binary file of some kind", result);
+ }
+
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
// START SNIPPET: e1
- // Set the jetty temp directory which store the file for multi part form
- // camel-jetty will clean up the file after it handled the request.
+ // Set the jetty temp directory which store the file for multi
+ // part form
+ // camel-jetty will clean up the file after it handled the
+ // request.
// The option works rightly from Camel 2.4.0
getContext().getProperties().put("CamelJettyTempDir", "target");
-
+
from("jetty://http://localhost:{{port}}/test").process(new Processor() {
public void process(Exchange exchange) throws Exception {
@@ -75,16 +88,21 @@ public class MultiPartFormTest extends BaseJettyTest {
DataHandler data = in.getAttachment("NOTICE.txt");
assertNotNull("Should get the DataHandle NOTICE.txt", data);
- // This assert is wrong, but the correct content-type (application/octet-stream)
- // will not be returned until Jetty makes it available - currently the content-type
- // returned is just the default for FileDataHandler (for the implentation being used)
- //assertEquals("Get a wrong content type", "text/plain", data.getContentType());
+ // This assert is wrong, but the correct content-type
+ // (application/octet-stream)
+ // will not be returned until Jetty makes it available -
+ // currently the content-type
+ // returned is just the default for FileDataHandler (for
+ // the implentation being used)
+ // assertEquals("Get a wrong content type",
+ // "text/plain", data.getContentType());
assertEquals("Got the wrong name", "NOTICE.txt", data.getName());
assertTrue("We should get the data from the DataHandle", data.getDataSource()
.getInputStream().available() > 0);
- // The other form date can be get from the message header
+ // The other form date can be get from the message
+ // header
exchange.getOut().setBody(in.getHeader("comment"));
}
@@ -94,5 +112,4 @@ public class MultiPartFormTest extends BaseJettyTest {
};
}
-
}