You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We recently upgraded from Spring framework 3.2.2 to 4.1.6 for our RESTful Services. We have a custom HTTP message reader for multipart request parsing using Apache Commons FileUpload. The code is like this:
It works fine while we were using Spring framework 3.2.2. However, after we upgraded to the Spring framework 4.1.6, the multipart request failed as the 1st part was dropped.
After debugging into the Spring code, we found that org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor has been changed that, in Spring 3.2.2, it wraps the servlet request's inputstream as a PushbackInputStream only when @RequestBody is not required.
RequestBodyannot = methodParam.getParameterAnnotation(RequestBody.class);
if (!annot.required()) {
...
inputMessage = newServletServerHttpRequest(servletRequest) {
@OverridepublicInputStreamgetBody() throwsIOException {
// Form POST should not get herereturnpushbackInputStream;
}
};
And in Spring 4.1.6, it always wraps the inputstream. This makes our code failed because Commons FileUpload takes the HttpServletRequest as the input parameter, and the wrapped inputstream is just ignored.
To make it work, we have to workaround our code, like below:
Good point. RequestResponseBodyMethodProcessor decorates HttpServletRequest.getInputStream() as well now and exposes that decorated HttpServletRequest through the passed-on ServletServerHttpRequest.
This will be available in the next 4.1.7.BUILD-SNAPSHOT snapshot. Feel free to give it a try...
william zhou opened SPR-13014 and commented
We recently upgraded from Spring framework 3.2.2 to 4.1.6 for our RESTful Services. We have a custom HTTP message reader for multipart request parsing using Apache Commons FileUpload. The code is like this:
It works fine while we were using Spring framework 3.2.2. However, after we upgraded to the Spring framework 4.1.6, the multipart request failed as the 1st part was dropped.
After debugging into the Spring code, we found that org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor has been changed that, in Spring 3.2.2, it wraps the servlet request's inputstream as a PushbackInputStream only when
@RequestBody
is not required.And in Spring 4.1.6, it always wraps the inputstream. This makes our code failed because Commons FileUpload takes the HttpServletRequest as the input parameter, and the wrapped inputstream is just ignored.
To make it work, we have to workaround our code, like below:
However, this should really be fixed by Spring code.
Affects: 4.1.6
Issue Links:
Referenced from: commits a899e06
The text was updated successfully, but these errors were encountered: