Spring MissingServletRequestParameterException error despite parameters being in the POST
Asked Answered
B

2

8

I have an application where occasionally Spring throws the error: org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'action' is not present

Naturally you would expect the action param to be missing, however it is definitely being POSTed by the browser. I've even gone as far as watching the network traffic with Wireshark, and it is there!

Here is an example of the raw post taken from Chromes dev tools - Note the &action=accept is there:

 imageId=1445&customReason=&action=accept&image=iVBORw0K...

The &image is a base64 encoded image (taken from a canvas element), and the whole POST is approx 4Mb.

This is running inside Tomcat 6.0 with Spring 3.2.8.

The Spring MVC controller that is throwing this is:

public String saveApprove(
      HttpServletRequest request,
      Model model,
      @RequestParam(value="action", required=true) String action,
      @RequestParam("imageId") int imageId,
      @RequestParam(value="image", required=false) String imageBase64Encoded,
      @RequestParam(value="rejectReasons", required=false) String rejectReasons[],
      @RequestParam(value="customReason", required=false) String customReason

  )

What could be causing this? Most photos are OK, but approx 10% throw this error. It's reproducible for a photo that throws it.

Is this a bug in Spring?

Bistre answered 1/7, 2014 at 12:20 Comment(3)
Post the full stack trace.Caraviello
Yes, full stack trace needed...have you tried to change the request method from POST to GET, to see if everything works? If yes, maybe the POST request you are performing is not built properly... If you use a tool like Postman give us a screenshot of the request body too, it could be useful. ThanksBloodstain
Can you enable logging levels for the following packages and share the logs. logging: level: springframework: beans: factory: suport: TRACE core: env: TRACE context: TRACE web: TRACE boot: INFO util: DEBUGElemi
C
5

Does this error correlate with wholde url length

Http url, as far as i know, are limmited in size You can try sending image through request body with multipart data header or search for methods to split your parameter into chunks

Hope this will help

Clercq answered 14/2 at 10:47 Comment(0)
R
1

You are running into tomcat's default form-urlencoded body size limit, which is 2 megabytes. For a non spring-boot app, that limit can be increased by setting the maxPostSize attribute in the Connector component. Refer this answer for more details. For a spring boot app, you can increase the limit by setting the server.tomcat.maxHttpFormPostSize config in application.yml file:

server:
  tomcat:
    maxHttpFormPostSize: 10 MB
Rachellrachelle answered 17/2 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.