Merge pull request #123 from olegz/INT-1977
log WARN message for irrelevant extractPayload
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user