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 b38ec48070..9aa06c5417 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 @@ -212,10 +212,13 @@ public class DefaultInboundRequestMapper implements InboundRequestMapper { private Object createPayloadFromTextContent(HttpServletRequest request) throws IOException { StringBuilder sb = new StringBuilder(); BufferedReader reader = request.getReader(); - String line = reader.readLine(); - while (line != null) { - sb.append(line); - line = reader.readLine(); + int contentLength = request.getContentLength(); + int bufferLength = (contentLength > -1) ? contentLength : 1024; + char[] buffer = new char[bufferLength]; + int charsRead = 0; + while ((charsRead = reader.read(buffer, 0, bufferLength)) != -1) { + sb.append(buffer, 0, charsRead); + buffer = new char[bufferLength]; } return sb.toString(); } 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 2e69ffbdd6..e4e99dd899 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 @@ -23,9 +23,8 @@ import org.springframework.integration.core.Message; import org.springframework.mock.web.MockHttpServletRequest; /** - * * @author Iwein Fuld - * + * @author Mark Fisher */ @SuppressWarnings("unchecked") public class DefaultInboundRequestMapperTests { @@ -59,4 +58,16 @@ public class DefaultInboundRequestMapperTests { Message message = (Message) mapper.toMessage(request); assertThat(message.getPayload(), is(COMPLEX_STRING)); } + + @Test + public void newlineTest() throws Exception { + String content = "foo\nbar\n"; + 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)); + } + }