diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java index 060c78a902..b1d6a5fd0b 100755 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java @@ -83,6 +83,8 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe private volatile Class expectedResponseType; private volatile boolean extractPayload = true; + + private volatile boolean extractPayloadExplicitlySet = false; private volatile String charset = "UTF-8"; @@ -93,7 +95,7 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe private final RestTemplate restTemplate; private final StandardEvaluationContext evaluationContext; - + /** * Create a handler that will send requests to the provided URI. @@ -139,6 +141,7 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe */ public void setExtractPayload(boolean extractPayload) { this.extractPayload = extractPayload; + this.extractPayloadExplicitlySet = true; } /** @@ -223,6 +226,12 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe if (conversionService != null) { this.evaluationContext.setTypeConverter(new StandardTypeConverter(conversionService)); } + if (!this.shouldIncludeRequestBody() && this.extractPayloadExplicitlySet){ + if (logger.isWarnEnabled()){ + logger.warn("The 'extractPayload' attribute has no meaning in the context of this handler since the provided HTTP Method is '" + + this.httpMethod + "', and no request body will be sent for that method."); + } + } } @Override diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java index 66c9be27b8..de03d2ff01 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java @@ -530,6 +530,35 @@ public class HttpRequestExecutingMessageHandlerTests { assertEquals(MediaType.TEXT_XML, request.getHeaders().getContentType()); } + @Test // no asertions just a warn message in a log + public void testWarnMessageForNonPostPutAndExtractPayload() throws Exception { + // should see a warn message + + HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("http://www.springsource.org/spring-integration"); + MockRestTemplate template = new MockRestTemplate(); + new DirectFieldAccessor(handler).setPropertyValue("restTemplate", template); + handler.setHttpMethod(HttpMethod.GET); + handler.setExtractPayload(true); + handler.afterPropertiesSet(); + + // should not see a warn message since 'setExtractPayload' is not set explicitly + + handler = new HttpRequestExecutingMessageHandler("http://www.springsource.org/spring-integration"); + template = new MockRestTemplate(); + new DirectFieldAccessor(handler).setPropertyValue("restTemplate", template); + handler.setHttpMethod(HttpMethod.GET); + handler.afterPropertiesSet(); + + // should not see a warn message since HTTP method is not GET + + handler = new HttpRequestExecutingMessageHandler("http://www.springsource.org/spring-integration"); + template = new MockRestTemplate(); + new DirectFieldAccessor(handler).setPropertyValue("restTemplate", template); + handler.setHttpMethod(HttpMethod.POST); + handler.setExtractPayload(true); + handler.afterPropertiesSet(); + } + @Test public void contentTypeIsNotSetForGetRequest() throws Exception { //GET