camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1353616 - in /camel/branches/camel-2.9.x: ./ components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java components/camel-stream/src/test/java/org/apache/camel/component/stream/StreamSystemOutTest.java
Date Mon, 25 Jun 2012 15:53:31 GMT
Author: davsclaus
Date: Mon Jun 25 15:53:30 2012
New Revision: 1353616

URL: http://svn.apache.org/viewvc?rev=1353616&view=rev
Log:
CAMEL-5395: Skip writing if null body. Thanks to Henryk for the patch.

Modified:
    camel/branches/camel-2.9.x/   (props changed)
    camel/branches/camel-2.9.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java
    camel/branches/camel-2.9.x/components/camel-stream/src/test/java/org/apache/camel/component/stream/StreamSystemOutTest.java

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1353613

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

Modified: camel/branches/camel-2.9.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java?rev=1353616&r1=1353615&r2=1353616&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java
Mon Jun 25 15:53:30 2012
@@ -113,6 +113,11 @@ public class StreamProducer extends Defa
     private synchronized void writeToStream(OutputStream outputStream, Exchange exchange)
throws IOException, CamelExchangeException {
         Object body = exchange.getIn().getBody();
 
+        if (body == null) {
+            log.debug("Body is null, cannot write it to the stream.");
+            return;
+        }
+
         // if not a string then try as byte array first
         if (!(body instanceof String)) {
             byte[] bytes = exchange.getIn().getBody(byte[].class);

Modified: camel/branches/camel-2.9.x/components/camel-stream/src/test/java/org/apache/camel/component/stream/StreamSystemOutTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-stream/src/test/java/org/apache/camel/component/stream/StreamSystemOutTest.java?rev=1353616&r1=1353615&r2=1353616&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-stream/src/test/java/org/apache/camel/component/stream/StreamSystemOutTest.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-stream/src/test/java/org/apache/camel/component/stream/StreamSystemOutTest.java
Mon Jun 25 15:53:30 2012
@@ -36,6 +36,22 @@ public class StreamSystemOutTest extends
         template.sendBody("direct:in", "Hello Bytes World\n".getBytes());
     }
 
+    @Test
+    public void shouldSkipNullBody() {
+        try {
+            // Given
+            System.setOut(new PrintStream(mockOut));
+
+            // When
+            template.sendBody("direct:in", null);
+
+            // Then
+            assertEquals(0, mockOut.toByteArray().length);
+        } finally {
+            System.setOut(stdOut);
+        }
+    }
+
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {



Mime
View raw message