Skip to content

ServletRequestDataBinder.bind should also consider wrapped ServletRequests when checking for Multipart, to comply with HiddenHttpMethodFilter. [SPR-8040] #12695

@spring-projects-issues

Description

@spring-projects-issues

Stefan Ocke opened SPR-8040 and commented

When using HiddenHttpMethodFilter, like for example Spring Roo generated apps do, the ServletRequest is wrappd into a HttpMethodRequestWrapper (at least in cases, where wrapping is necessary, for example for PUT requests emulated with POST and httpMethod parameter).

Later, when it comes to data binding the ServletRequestDataBinder.bind method checks for multipart requests:

MutablePropertyValues mpvs = new ServletRequestParameterPropertyValues(request);
		if (request instanceof MultipartRequest) {
			MultipartRequest multipartRequest = (MultipartRequest) request;
			bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
		}
		doBind(mpvs);

But if the multipart request has been wrapped into a HttpMethodRequestWrapper , this won't work anymore, since it is not an instance of MultipartRequest. Thus, no databinding for the Multipart files occurs.

NOTE: My setup ist the following:

  • I am using a MultipartFilter in front of the WebMethodFilter, as suggested in bold letters in the Javadoc of HiddenHttpMethodFilter
  • I am using binding for the uploaded files, instead of "injecting" them as parameters in the controller mehtods. For this, I register an according converter / bean editor from MultipartFile to byte array
  • For POST request, this setup works fine. For PUT (emulated by POST and httpMethod parameter), the problem described above arises.

Affects: 3.0.5

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions