0

I have a post method in my Spring controller that takes one request parameter called wkt. Here is my method signature:

@RequestMapping(value="/getNumberOfProperties", method=RequestMethod.POST)
public String getEstimateForNumberOfProperties(@RequestParam("wkt") String wkt) {
    //code
}

In my jQuery, I am calling this method like this.

$.post(webroot + "/project/getNumberOfProperties", {wkt : wktGeomFromServer})

This works great. However, I was getting this error for wkt strings that are too long.

org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'wkt' is not present
at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:255) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:95) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:79) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:157) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:124) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) ~[spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749) ~[spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690) ~[spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) ~[spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) [servlet-api.jar:?]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) [servlet-api.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) [catalina.jar:7.0.41]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.41]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]

So how long is too long? After doing some testing, I have discovered that if the length of the string is 1,971,324 or less everything works. Otherwise, I get the above exception. I don't know if this is something with Spring, or tomcat, etc. Also, I have verified with Chrome that wkt parameter is getting sent in all cases, regardless of length. So the Spring error message when it is too long does not make much sense to me. Is 1,971,324 some magic number somewhere?

Any suggestions?

jlars62
  • 6,366
  • 7
  • 34
  • 56
  • inspect your HTTP request being sent – jmj Jul 10 '14 at 19:55
  • I don't know jquery very well. Is the parameter sent in the body or as part of the URL? – Sotirios Delimanolis Jul 10 '14 at 19:56
  • @Sotirios It is sent in the body (which is actually why I switched to post method, to handle longer parameters) – jlars62 Jul 10 '14 at 19:57
  • @JigarJoshi According to the Chrome network tab, the parameter is definitely there, regardless of length – jlars62 Jul 10 '14 at 19:57
  • Do you have a `Content-Length` header in the request? – Sotirios Delimanolis Jul 10 '14 at 19:59
  • @SotiriosDelimanolis Yes, `Content-Length` header is being sent correctly – jlars62 Jul 10 '14 at 20:00
  • I can't test this right now. It shouldn't happen. I will investigate later if no one has figured it out. – Sotirios Delimanolis Jul 10 '14 at 20:03
  • 2
    There is a limit on POST parameters size. You can check in the server configuration xml file - an attribute on the lines:maxPostSize. Its 2MB(2097152 bytes) for tomcat, JBoss by default. One can configure it to unlimited by changing this parameter to neagtive value. For Weblogic, this is unlimited by default. You can find this info for some servers here: http://tomcat.apache.org/tomcat-8.0-doc/config/http.html http://docs.oracle.com/cd/E17904_01/apirefs.1111/e13951/core/index.html – Prasad Jul 10 '14 at 20:26
  • Wow, it was the `maxPostSize` parameter of tomcat! I assumed differently because of my error message. I had looked at this question http://stackoverflow.com/questions/2943477/is-there-a-max-size-for-post-parameter-content which lead me to believe it was something else. – jlars62 Jul 10 '14 at 20:39

1 Answers1

1

Could it be server configuration issue? For example Tomcat has 2MB maximum post request content size by default.

Dkr
  • 26
  • 2