diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/multipart/MultipartHttpInputMessage.java b/spring-integration-http/src/main/java/org/springframework/integration/http/multipart/MultipartHttpInputMessage.java index 14110cfa1b..9463ce9962 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/multipart/MultipartHttpInputMessage.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/multipart/MultipartHttpInputMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,4 +67,18 @@ public class MultipartHttpInputMessage extends ServletServerHttpRequest implemen return this.multipartServletRequest.getParameterMap(); } + /** + * Once we depend upon Spring 3.1 as a minimum, this code can be changed to: + * this.multipartServletRequest.getMultipartContentType(String paramOrFileName) + */ + public String getMultipartContentType(String paramOrFileName) { + MultipartFile file = getFile(paramOrFileName); + if (file != null) { + return file.getContentType(); + } + else { + throw new UnsupportedOperationException("unable to retrieve multipart content-type for parameter"); + } + } + } diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletRequest.java b/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletRequest.java index 4b46ce5783..fea8b4ca44 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletRequest.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package org.springframework.integration.http; +import org.springframework.core.SpringVersion; + /** * Modified version of the MockHttpServletRequest that sets the "Content-Type" * header so that it will be available from a ServletServerHttpRequest instance. @@ -36,7 +38,13 @@ public class MockHttpServletRequest extends org.springframework.mock.web.MockHtt @Override public void setContentType(String contentType) { - this.addHeader("Content-Type", contentType); + String springVersion = SpringVersion.getVersion(); + if (springVersion != null && springVersion.startsWith("3.0")) { + this.addHeader("Content-Type", contentType); + } + else { + super.setContentType(contentType); + } } @Override diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletResponse.java b/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletResponse.java index 5cbe49b127..d500d2a0ec 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletResponse.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package org.springframework.integration.http; +import org.springframework.core.SpringVersion; + /** * Modified version of the MockHttpServletResponse that sets the "Content-Type" * header so that it will be available from a ServletServerHttpResponse instance. @@ -32,7 +34,13 @@ public class MockHttpServletResponse extends org.springframework.mock.web.MockHt @Override public void setContentType(String contentType) { - this.addHeader("Content-Type", contentType); + String springVersion = SpringVersion.getVersion(); + if (springVersion != null && springVersion.startsWith("3.0")) { + this.addHeader("Content-Type", contentType); + } + else { + super.setContentType(contentType); + } } @Override