Commit bdab24a6b0d9952fe7c61c0e421cddff97ee139b

INT-1657, INT-1658 outbound http adapters now use an explicitly mapped 'Content-Type' header and only fallback to determining the header value from payload type. Also fixed a casting issue in the MultiValueMap conversion code.
spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java
(25 / 24)
  
1818
1919import java.net.URI;
2020import java.nio.charset.Charset;
21import java.util.ArrayList;
2122import java.util.Arrays;
2223import java.util.Collection;
24import java.util.Collections;
2325import java.util.HashMap;
2426import java.util.List;
2527import java.util.Map;
260260 HttpHeaders httpHeaders = new HttpHeaders();
261261 this.headerMapper.fromHeaders(requestMessage.getHeaders(), httpHeaders);
262262 Object payload = requestMessage.getPayload();
263
264 MediaType contentType = (payload instanceof String) ? this.resolveContentType((String) payload, this.charset)
265 : this.resolveContentType(payload);
266 if (contentType.equals(MediaType.APPLICATION_FORM_URLENCODED) || contentType.equals(MediaType.MULTIPART_FORM_DATA)){
267 if (!(payload instanceof MultiValueMap)){
263 if (httpHeaders.getContentType() == null) {
264 MediaType contentType = (payload instanceof String) ? this.resolveContentType((String) payload, this.charset)
265 : this.resolveContentType(payload);
266 httpHeaders.setContentType(contentType);
267 }
268 if (MediaType.APPLICATION_FORM_URLENCODED.equals(httpHeaders.getContentType()) ||
269 MediaType.MULTIPART_FORM_DATA.equals(httpHeaders.getContentType())) {
270 if (!(payload instanceof MultiValueMap)) {
268271 payload = this.convertToMultiValueMap((Map) payload);
269272 }
270273 }
271 httpHeaders.setContentType(contentType);
272274 if (HttpMethod.POST.equals(this.httpMethod) || HttpMethod.PUT.equals(this.httpMethod)) {
273275 return new HttpEntity<Object>(payload, httpHeaders);
274276 }
292292 else if (content instanceof Source) {
293293 contentType = MediaType.TEXT_XML;
294294 }
295 else if (content instanceof Map){
296 /*
297 * We need to check separately for MULTIPART as well as URLENCODED simply because
298 * MultiValueMap<Object, Object> is actually valid content for serialization
299 */
300 if (this.isFormData((Map<Object, ?>) content)){
301 if (this.isMultipart((Map<String, ?>)content)){
295 else if (content instanceof Map) {
296 // We need to check separately for MULTIPART as well as URLENCODED simply because
297 // MultiValueMap<Object, Object> is actually valid content for serialization
298 if (this.isFormData((Map<Object, ?>) content)) {
299 if (this.isMultipart((Map<String, ?>)content)) {
302300 contentType = MediaType.MULTIPART_FORM_DATA;
303301 }
304302 else {
313313 private MediaType resolveContentType(String content, String charset) {
314314 return new MediaType("text", "plain", Charset.forName(charset));
315315 }
316
317
316
318317 @SuppressWarnings("unchecked")
319 private MultiValueMap<Object, Object> convertToMultiValueMap(Map<Object, Object> simpleContentMap){
320
318 private MultiValueMap<Object, Object> convertToMultiValueMap(Map<Object, Object> simpleMap) {
321319 LinkedMultiValueMap<Object, Object> multipartValueMap = new LinkedMultiValueMap<Object, Object>();
322 for (Object key : simpleContentMap.keySet()) {
323 Object value = simpleContentMap.get(key);
324 if (value instanceof Object[]){
320 for (Object key : simpleMap.keySet()) {
321 Object value = simpleMap.get(key);
322 if (value instanceof Object[]) {
325323 Object[] valueArray = (Object[]) value;
326324 value = Arrays.asList(valueArray);
327 }
328 if (value instanceof Collection){
329 multipartValueMap.put(key, (List<Object>) value);
330 }
325 }
326 if (value instanceof Collection) {
327 multipartValueMap.put(key, new ArrayList<Object>((Collection<?>) value));
328 }
331329 else {
332330 multipartValueMap.add(key, value);
333331 }
334332 }
335333 return multipartValueMap;
336334 }
335
337336 /**
338337 * If all keys are Strings, and some values are not Strings we'll consider
339338 * the Map to be multipart/form-data

Comments

Add a new comment:

Login or create an account to post a comment

Add your comment