Request body not available if ContentCachingRequestWrapper is added by external filter in Spring MVC

Issue #383 new
Former user created an issue

I have a setup where I wrap the request with ContentCachingRequestWrapper for logging purposes.

When I try POST to an endpoint with a required request body I always get an error saying that "A request body is required but none found".

I believe this is because OpenApiValidationService expects that if the request is a ContentCachingRequestWrapper then getContentAsByteArray can be called because it has just parsed the application/x-www-form-urlencoded params. But if the request is application/json there will be no cached content at this stage.

If I look in OpenApiValidationFilter I can see that it only uses ContentCachingRequestWrapper if the request is a form-data content type. This check is not done in OpenApiValidationService.

Comments (2)

  1. Sven Döring

    Thanks for raising this.

    It’s correct that only form-data is wrapped within an ContentCachingRequestWrapper. All other requests will be wrapped within a custom request wrapper with massively better performance.

    However it would be wise to use the already wrapped request if it’s a ContentCachingRequestWrapper. That wrapper might be slow but caching the request twice doubles the memory usage.

    I’ll look into it.

  2. Log in to comment