diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGateway.java b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGateway.java index 7507454e38..0aefe320b2 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGateway.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGateway.java @@ -17,6 +17,7 @@ package org.springframework.integration.http.inbound; import java.io.IOException; +import java.util.Collections; import java.util.List; import javax.servlet.ServletException; @@ -30,6 +31,7 @@ import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.http.server.ServletServerHttpResponse; import org.springframework.integration.MessagingException; import org.springframework.integration.http.converter.MultipartAwareFormHttpMessageConverter; +import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; import org.springframework.web.HttpRequestHandler; @@ -98,12 +100,12 @@ public class HttpRequestHandlingMessagingGateway extends HttpRequestHandlingEndp if (responseContent != null) { ServletServerHttpRequest request = new ServletServerHttpRequest(servletRequest); ServletServerHttpResponse response = new ServletServerHttpResponse(servletResponse); - if (responseContent instanceof HttpStatus){ + if (responseContent instanceof HttpStatus) { response.setStatusCode((HttpStatus) responseContent); } else { this.writeResponse(responseContent, response, request.getHeaders().getAccept()); - } + } } } @@ -126,6 +128,9 @@ public class HttpRequestHandlingMessagingGateway extends HttpRequestHandlingEndp @SuppressWarnings({"unchecked", "rawtypes"}) private void writeResponse(Object content, ServletServerHttpResponse response, List acceptTypes) throws IOException { + if (CollectionUtils.isEmpty(acceptTypes)) { + acceptTypes = Collections.singletonList(MediaType.ALL); + } for (HttpMessageConverter converter : this.getMessageConverters()) { for (MediaType acceptType : acceptTypes) { if (converter.canWrite(content.getClass(), acceptType)) { diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGatewayTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGatewayTests.java index d039d0b7f6..9bd5a87dda 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGatewayTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGatewayTests.java @@ -108,6 +108,26 @@ public class HttpRequestHandlingMessagingGatewayTests { assertEquals("HELLO", response.getContentAsString()); } + @Test // INT-1767 + public void noAcceptHeaderOnRequest() throws Exception { + DirectChannel requestChannel = new DirectChannel(); + requestChannel.subscribe(new AbstractReplyProducingMessageHandler() { + protected Object handleRequestMessage(Message requestMessage) { + return requestMessage.getPayload().toString().toUpperCase(); + } + }); + HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true); + gateway.setRequestPayloadType(String.class); + gateway.setRequestChannel(requestChannel); + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setMethod("POST"); + request.setContentType("text/plain"); + request.setContent("hello".getBytes()); + MockHttpServletResponse response = new MockHttpServletResponse(); + gateway.handleRequest(request, response); + assertEquals("HELLO", response.getContentAsString()); + } + @Test public void testExceptionConversion() throws Exception { QueueChannel requestChannel = new QueueChannel() {