org.springframework.web.multipart.MultipartException: Current request is not a multipart request

  1. 0

    Could WSO2 API Manager mediation break our multipart requests?

    Stack Overflow | 3 months ago | Bram Vandewalle
    org.springframework.web.multipart.MultipartException: Current request is not a multipart request
  2. 0

    Given the following bean configuration: {code:xml} <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:component-scan base-package="test" /> <mvc:annotation-driven/> </beans> {code} and the following controller: {code:java} package test; // ... @Controller public class TestController { @RequestMapping("/home") @ResponseBody public String home(@RequestParam String param) { return param; } {code} and using them in a Servlet 2.5 environment (e.g. Tomcat 6) will result in the following exception when a request is made to {{/home}}: {noformat} org.springframework.web.multipart.MultipartException: Current request is not a multipart request at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:188) at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:104) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) ... {noformat} This only occurs when Spring chooses to use the {{RequestMappingHandlerAdapter}} (as opposed to the deprecated {{AnnotationMethodHandlerAdapter}}). The root cause of this seems to be in the (somewhat recent) {{MultipartResolutionDelegate}} class. Its {{servletPartClass}} field remains {{null}} in pre Servlet 3.0 environments, and some equality checks yield false positives due to that. For instance: {code:java} private static boolean isPartCollection(MethodParameter methodParam) { return (servletPartClass == getCollectionParameterType(methodParam)); } private static Class<?> getCollectionParameterType(MethodParameter methodParam) { Class<?> paramType = methodParam.getNestedParameterType(); if (Collection.class == paramType || List.class.isAssignableFrom(paramType)){ Class<?> valueType = GenericCollectionTypeResolver.getCollectionParameterType(methodParam); if (valueType != null) { return valueType; } } return null; } {code} {{getCollectionParameterType}} returns {{null}} for non-collection parameters, which makes {{isPartCollection}} return {{true}}. The {{isPartArray}} method is plagued by the same issue (and maybe other places are too).

    Spring JIRA | 6 months ago | Dmitri Gabbasov
    org.springframework.web.multipart.MultipartException: Current request is not a multipart request
  3. 0

    Given the following bean configuration: {code:xml} <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:component-scan base-package="test" /> <mvc:annotation-driven/> </beans> {code} and the following controller: {code:java} package test; // ... @Controller public class TestController { @RequestMapping("/home") @ResponseBody public String home(@RequestParam String param) { return param; } {code} and using them in a Servlet 2.5 environment (e.g. Tomcat 6) will result in the following exception when a request is made to {{/home}}: {noformat} org.springframework.web.multipart.MultipartException: Current request is not a multipart request at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:188) at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:104) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) ... {noformat} This only occurs when Spring chooses to use the {{RequestMappingHandlerAdapter}} (as opposed to the deprecated {{AnnotationMethodHandlerAdapter}}). The root cause of this seems to be in the (somewhat recent) {{MultipartResolutionDelegate}} class. Its {{servletPartClass}} field remains {{null}} in pre Servlet 3.0 environments, and some equality checks yield false positives due to that. For instance: {code:java} private static boolean isPartCollection(MethodParameter methodParam) { return (servletPartClass == getCollectionParameterType(methodParam)); } private static Class<?> getCollectionParameterType(MethodParameter methodParam) { Class<?> paramType = methodParam.getNestedParameterType(); if (Collection.class == paramType || List.class.isAssignableFrom(paramType)){ Class<?> valueType = GenericCollectionTypeResolver.getCollectionParameterType(methodParam); if (valueType != null) { return valueType; } } return null; } {code} {{getCollectionParameterType}} returns {{null}} for non-collection parameters, which makes {{isPartCollection}} return {{true}}. The {{isPartArray}} method is plagued by the same issue (and maybe other places are too).

    Spring JIRA | 6 months ago | Dmitri Gabbasov
    org.springframework.web.multipart.MultipartException: Current request is not a multipart request
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    The current request is not a multipart request - Spring MVC

    Stack Overflow | 4 years ago | Philippxp
    org.springframework.web.multipart.MultipartException: The current request is not a multipart request
  6. 0

    Submission of form containing Object and Multipart File data

    Stack Overflow | 2 years ago | Kleber Mota
    org.springframework.web.multipart.MultipartException: The current request is not a multipart request

  1. kjhdofjosvs 1 times, last 3 weeks ago
  2. wendellpereira 4 times, last 2 months ago
  3. dafman 2 times, last 2 months ago
  4. qavid 4 times, last 6 months ago
  5. Arthur Neutrino 1 times, last 9 months ago
28 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.springframework.web.multipart.MultipartException

    Current request is not a multipart request

    at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue()
  2. Spring
    InvocableHandlerMethod.invokeForRequest
    1. org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:188)[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    2. org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:104)[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    3. org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    4. org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    5. org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128)[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    5 frames
  3. Spring MVC
    RequestMappingHandlerAdapter.handleInternal
    1. org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    2. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    3. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    3 frames