INT-1951 fixed HttpRequestExecutingMessageHandler to ensure that it sets Content-Type only for POST and PUT requests

This commit is contained in:
Oleg Zhurakousky
2011-07-12 13:28:50 -04:00
parent 30b39da1d0
commit af7bc5ac74
2 changed files with 92 additions and 7 deletions

View File

@@ -282,11 +282,15 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe
HttpHeaders httpHeaders = new HttpHeaders();
this.headerMapper.fromHeaders(requestMessage.getHeaders(), httpHeaders);
Object payload = requestMessage.getPayload();
if (httpHeaders.getContentType() == null) {
MediaType contentType = (payload instanceof String) ? this.resolveContentType((String) payload, this.charset)
: this.resolveContentType(payload);
httpHeaders.setContentType(contentType);
if (HttpMethod.POST.equals(this.httpMethod) || HttpMethod.PUT.equals(this.httpMethod)) { //INT-1951
if (httpHeaders.getContentType() == null) {
MediaType contentType = (payload instanceof String) ? this.resolveContentType((String) payload, this.charset)
: this.resolveContentType(payload);
httpHeaders.setContentType(contentType);
}
}
if (MediaType.APPLICATION_FORM_URLENCODED.equals(httpHeaders.getContentType()) ||
MediaType.MULTIPART_FORM_DATA.equals(httpHeaders.getContentType())) {
if (!(payload instanceof MultiValueMap)) {
@@ -300,9 +304,13 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe
}
private HttpEntity<Object> createHttpEntityWithMessageAsBody(Message<?> requestMessage) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(new MediaType("application", "x-java-serialized-object"));
return new HttpEntity<Object>(requestMessage, headers);
HttpHeaders httpHeaders = new HttpHeaders();
if (HttpMethod.POST.equals(this.httpMethod) || HttpMethod.PUT.equals(this.httpMethod)) { //INT-1951
httpHeaders.setContentType(new MediaType("application", "x-java-serialized-object"));
}
return new HttpEntity<Object>(requestMessage, httpHeaders);
}
@SuppressWarnings("unchecked")