- edited description
Form parameters aren't available in Spring MVC
When I try to POST application/x-www-form-urlencoded
with form parameter foo=aaa
to a Spring MVC controller, the request handler isn’t able to find the corresponding @RequestParam
. I’ve done some digging, and I suspect the ResettableRequestServletWrapper
is getting in the way.
At first I thought Spring MVC’s FormContentFilter
was getting in the way, but that no-ops for POSTs.
FWIW, this also happens if you set validation.request.path.missing
to IGNORE
and remove the request from the spec. So the problem’s probably unrelated to the OpenAPI spec itself.
I’ve created a minimal Kotlin/RestAssured/Spring Boot project to help you replicate this: https://github.com/emersonf/openapi-test. The README has more details.
Side note: I’m not sure if the custom ResettableRequestServletWrapper
has benefits over org.springframework.web.util.ContentCachingRequestWrapper
, but it might be worth looking into.
Comments (13)
-
reporter -
reporter - edited description
-
Thanks for raising the issue. I will look into it.
The spring-mvc module started with the
ContentCachingRequestWrapper
. It was replaced by the customResettableRequestServletWrapper
for several reasons:- slow especially if the
Content-Length
header is not set - high garbage collection pressure
- big bodies >2.1GB are not supported
The
ContentCachingRequestWrapper
purpose and strength is on caching the first n bytes of a request - e.g. for request logging. - slow especially if the
-
reporter Thanks.
Coincidentally I’m adding request and response validation to a system that does request and response logging. Being able to plug in and reuse the caching mechanism across filters (strategy pattern or template method pattern) would also help make this more efficient, but that would just be a nice-to-have.
-
I can follow that. I’ve created a new issue
#304for that matter. -
I found the issue. Tomcats
RequestFacade
merges thex-www-form-urlencoded
body data into the parameters. But it does this only if the body hasn’t been read, yet… and theOpenApiValidationService
does that.The solution will be to wrap those kind of requests into a
ContentCachingRequestWrapper
instead of theResettableRequestServletWrapper
- what a coincidence.
(Of course it will only wrap the request if it isn’t already wrapped into aContentCachingRequestWrapper
.) -
The Pull Request 179 has been added handling this issue and
#304.Your openapi-test runs successful with this change.
-
reporter Thank you so much! I skimmed the PR too, looks great.
-
Thanks @Sven Döring - I will review your PR next week when I return from parental leave. Appreciate it as always!
-
Congrats to your little Mini-Me.
-
Thanks
-
- changed status to open
-
- changed status to resolved
Available in v2.11.1
- Log in to comment