Skip to content

Commit

Permalink
CAMEL-5395: Skip writing if null body. Thanks to Henryk for the patch.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/camel/branches/camel-2.8.x@1353622 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
davsclaus committed Jun 25, 2012
1 parent d611f1b commit 45bf742
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ private void delay(long ms) throws InterruptedException {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ public void testBinaryContent() {
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() {
Expand Down

0 comments on commit 45bf742

Please sign in to comment.