Merge pull request #123 from olegz/INT-1977

log WARN message for irrelevant extractPayload
This commit is contained in:
Mark Fisher
2011-10-15 14:27:12 -04:00
2 changed files with 39 additions and 1 deletions

View File

@@ -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

View File

@@ -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