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 2012/09/17 15:39:18 UTC
svn commit: r1386609 - in /camel/branches/camel-2.10.x: ./
components/camel-jetty/src/main/java/org/apache/camel/component/jetty/
components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/
Author: ningjiang
Date: Mon Sep 17 13:39:18 2012
New Revision: 1386609
URL: http://svn.apache.org/viewvc?rev=1386609&view=rev
Log:
CAMEL-5621 fix the JettyHttpProducer close input stream issue when the exception is throw during sending the request
Added:
camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerInvalidDestinationTest.java
- copied unchanged from r1386607, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerInvalidDestinationTest.java
camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/MyInputStream.java
- copied unchanged from r1386607, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/MyInputStream.java
Modified:
camel/branches/camel-2.10.x/ (props changed)
camel/branches/camel-2.10.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Merged /camel/trunk:r1386607
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.10.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java?rev=1386609&r1=1386608&r2=1386609&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java (original)
+++ camel/branches/camel-2.10.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java Mon Sep 17 13:39:18 2012
@@ -94,12 +94,8 @@ public class JettyContentExchange extend
@Override
protected void onRequestComplete() throws IOException {
LOG.trace("onRequestComplete");
-
- // close the input stream when its not needed anymore
- InputStream is = getRequestContentSource();
- if (is != null) {
- IOHelper.close(is, "RequestContentSource", LOG);
- }
+
+ closeRequestContentSource();
}
@Override
@@ -120,6 +116,8 @@ public class JettyContentExchange extend
try {
super.onExpire();
} finally {
+ // need to close the request input stream
+ closeRequestContentSource();
doTaskCompleted();
}
}
@@ -131,6 +129,8 @@ public class JettyContentExchange extend
try {
super.onException(ex);
} finally {
+ // need to close the request input stream
+ closeRequestContentSource();
doTaskCompleted(ex);
}
}
@@ -142,6 +142,8 @@ public class JettyContentExchange extend
try {
super.onConnectionFailed(ex);
} finally {
+ // need to close the request input stream
+ closeRequestContentSource();
doTaskCompleted(ex);
}
}
@@ -159,6 +161,14 @@ public class JettyContentExchange extend
String params = getRequestFields().getStringField(HttpHeaders.CONTENT_ENCODING);
return getScheme() + "//" + getAddress().toString() + getRequestURI() + (params != null ? "?" + params : "");
}
+
+ protected void closeRequestContentSource() {
+ // close the input stream when its not needed anymore
+ InputStream is = getRequestContentSource();
+ if (is != null) {
+ IOHelper.close(is, "RequestContentSource", LOG);
+ }
+ }
protected void doTaskCompleted() {
// make sure to lower the latch
Modified: camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java?rev=1386609&r1=1386608&r2=1386609&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java (original)
+++ camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java Mon Sep 17 13:39:18 2012
@@ -16,8 +16,11 @@
*/
package org.apache.camel.component.jetty.jettyproducer;
+import java.io.ByteArrayInputStream;
+
import org.apache.camel.Exchange;
import org.apache.camel.ExchangeTimedOutException;
+import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jetty.BaseJettyTest;
import org.junit.Test;
@@ -38,12 +41,19 @@ public class JettyHttpProducerTimeoutTes
// give Jetty time to startup properly
Thread.sleep(1000);
+ final MyInputStream is = new MyInputStream("Content".getBytes());
- Exchange reply = template.request(url, null);
+ Exchange reply = template.request(url, new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setBody(is);
+ }
+ });
Exception e = reply.getException();
assertNotNull("Should have thrown an exception", e);
ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, e);
assertEquals(2000, cause.getTimeout());
+ assertTrue("The input stream should be closed", is.isClosed());
}
@Override
@@ -55,4 +65,6 @@ public class JettyHttpProducerTimeoutTes
}
};
}
+
+
}
\ No newline at end of file