From c9e48b81d1a7f7a2b6502bc84d93cb3fdeb11389 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 30 Sep 2009 21:29:26 +0000 Subject: [PATCH] added ready() check to support empty string --- .../integration/http/DefaultInboundRequestMapper.java | 2 +- .../http/DefaultInboundRequestMapperTests.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/org.springframework.integration.http/src/main/java/org/springframework/integration/http/DefaultInboundRequestMapper.java b/org.springframework.integration.http/src/main/java/org/springframework/integration/http/DefaultInboundRequestMapper.java index 9aa06c5417..7b438065b1 100644 --- a/org.springframework.integration.http/src/main/java/org/springframework/integration/http/DefaultInboundRequestMapper.java +++ b/org.springframework.integration.http/src/main/java/org/springframework/integration/http/DefaultInboundRequestMapper.java @@ -216,7 +216,7 @@ public class DefaultInboundRequestMapper implements InboundRequestMapper { int bufferLength = (contentLength > -1) ? contentLength : 1024; char[] buffer = new char[bufferLength]; int charsRead = 0; - while ((charsRead = reader.read(buffer, 0, bufferLength)) != -1) { + while (reader.ready() && (charsRead = reader.read(buffer, 0, bufferLength)) != -1) { sb.append(buffer, 0, charsRead); buffer = new char[bufferLength]; } diff --git a/org.springframework.integration.http/src/test/java/org/springframework/integration/http/DefaultInboundRequestMapperTests.java b/org.springframework.integration.http/src/test/java/org/springframework/integration/http/DefaultInboundRequestMapperTests.java index e4e99dd899..3fe184c8ca 100644 --- a/org.springframework.integration.http/src/test/java/org/springframework/integration/http/DefaultInboundRequestMapperTests.java +++ b/org.springframework.integration.http/src/test/java/org/springframework/integration/http/DefaultInboundRequestMapperTests.java @@ -70,4 +70,15 @@ public class DefaultInboundRequestMapperTests { assertThat(message.getPayload(), is(content)); } + @Test + public void emptyStringTest() throws Exception { + String content = ""; + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setContentType("text"); + byte[] bytes = content.getBytes(); + request.setContent(bytes); + Message message = (Message) mapper.toMessage(request); + assertThat(message.getPayload(), is(content)); + } + }