camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1386615 - in /camel/branches/camel-2.9.x: ./ components/camel-jetty/src/main/java/org/apache/camel/component/jetty/ components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/
Date Mon, 17 Sep 2012 13:49:20 GMT
Author: ningjiang
Date: Mon Sep 17 13:49:20 2012
New Revision: 1386615

URL: http://svn.apache.org/viewvc?rev=1386615&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.9.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerInvalidDestinationTest.java
      - copied unchanged from r1386609, camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerInvalidDestinationTest.java
    camel/branches/camel-2.9.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/MyInputStream.java
      - copied unchanged from r1386609, camel/branches/camel-2.10.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/MyInputStream.java
Modified:
    camel/branches/camel-2.9.x/   (props changed)
    camel/branches/camel-2.9.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
    camel/branches/camel-2.9.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1386607
  Merged /camel/branches/camel-2.10.x:r1386609

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.9.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java?rev=1386615&r1=1386614&r2=1386615&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
Mon Sep 17 13:49:20 2012
@@ -95,12 +95,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
@@ -121,6 +117,8 @@ public class JettyContentExchange extend
         try {
             super.onExpire();
         } finally {
+            // need to close the request input stream
+            closeRequestContentSource();
             doTaskCompleted();
         }
     }
@@ -132,6 +130,8 @@ public class JettyContentExchange extend
         try {
             super.onException(ex);
         } finally {
+            // need to close the request input stream
+            closeRequestContentSource();
             doTaskCompleted(ex);
         }
     }
@@ -143,6 +143,8 @@ public class JettyContentExchange extend
         try {
             super.onConnectionFailed(ex);
         } finally {
+            // need to close the request input stream
+            closeRequestContentSource();
             doTaskCompleted(ex);
         }
     }
@@ -160,6 +162,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.9.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.9.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java?rev=1386615&r1=1386614&r2=1386615&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/jettyproducer/JettyHttpProducerTimeoutTest.java
Mon Sep 17 13:49:20 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



Mime
View raw message