Results 1 to 7 of 7

Thread: MultipartFile upload yields 500 when no file

  1. #1
    Join Date
    Jul 2010
    Posts
    5

    Default MultipartFile upload yields 500 when no file

    I have a MVC controller uploads multiple files. It works fine if I specify at least one file,
    but fails if no files are specified. The server is Tomcat 7 and returns a 500 (internal server error)
    status code. The controller method (which never gets called) is:

    Code:
    	public @ResponseBody ExecuteQueryResult executeQuery( @RequestParam("ksUrl") String ksUrl,
    			@RequestParam("serviceName") String serviceName,
    			@RequestParam(value="file",required=false) MultipartFile[] file,
    			@RequestParam("query") String query,
    			HttpServletResponse response) {
    According to Firebug the request looks like:

    Headers
    Code:
    Connection	close
    Content-Length	1000
    Content-Type	text/html;charset=utf-8
    Date	Fri, 20 Jul 2012 00:06:26 GMT
    Server	Apache-Coyote/1.1
    Request Headers
    Accept	application/json, text/javascript, */*; q=0.01
    Accept-Encoding	gzip, deflate
    Accept-Language	en-us,en;q=0.5
    Connection	keep-alive
    Content-Length	888
    Content-Type	multipart/form-data; boundary=---------------------------23805158906729
    Host	localhost:8080
    Referer	http://localhost:8080/queryserver-1.0.1/
    User-Agent	Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1
    X-Requested-With	XMLHttpRequest
    Source
    Code:
    -----------------------------23805158906729 Content-Disposition: form-data; name="ksUrlId" 5 -----------------------------23805158906729 Content-Disposition: form-data; name="ksUrl" http://localhost:8080/sadlserver-cxf-service-1.0.3/SadlService -----------------------------23805158906729 Content-Disposition: form-data; name="serviceName" InScope-CFM56-7 -----------------------------23805158906729 Content-Disposition: form-data; name="file" -----------------------------23805158906729 Content-Disposition: form-data; name="savedQueryId" 3 -----------------------------23805158906729 Content-Disposition: form-data; name="query" select ?cw where {<Transfer_Gearbox_Module-111111> <candidate_Workscope> ?cw } -----------------------------23805158906729 Content-Disposition: form-data; name="queryName" -----------------------------23805158906729--
    Any ideas?
    Thanks in advance.

    Barry

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Post the stacktrace from the logging (using [ code][/code ] tags) that should hold the key to your solution.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jul 2010
    Posts
    5

    Default

    Quote Originally Posted by Marten Deinum View Post
    Post the stacktrace from the logging (using [ code][/code ] tags) that should hold the key to your solution.
    There was no stacktrace since the request never got to my code.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    There must be something an 500 indicates in general that there is a stacktrace somewhere. The fact that it doesn't reach your controller doesn't matter, I suspect the error comes from the MultipartResolver however I want to be sure. So enable some more logging to see what is happening, simply the code and the requests that are send aren't giving any information...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Jul 2010
    Posts
    5

    Default

    After turning on full debugging in Spring I got the following messages:

    Code:
    2012-07-20 10:19:54,475 DEBUG [org.springframework.web.servlet.DispatcherServlet] [http-bio-8080-exec-10] DispatcherServlet with name 'appServlet' processing POST request for [/queryserver-1.0.1/execute-query]
    2012-07-20 10:19:54,506 DEBUG [org.springframework.web.servlet.handler.AbstractHandlerMethodMapping] [http-bio-8080-exec-10] Looking up handler method for path /execute-query
    2012-07-20 10:19:54,506 DEBUG [org.springframework.web.servlet.handler.AbstractHandlerMethodMapping] [http-bio-8080-exec-10] Returning handler method [public com.ge.research.sadl.queryserver.webapp.controller.ExecuteQueryResult com.ge.research.sadl.queryserver.webapp.controller.QueryController.executeQuery(java.lang.String,java.lang.String,org.springframework.web.multipart.MultipartFile[],java.lang.String,javax.servlet.http.HttpServletResponse)]
    2012-07-20 10:19:54,506 DEBUG [org.springframework.beans.factory.support.AbstractBeanFactory] [http-bio-8080-exec-10] Returning cached instance of singleton bean 'queryController'
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.AbstractEnvironment] [http-bio-8080-exec-10] Initializing new StandardEnvironment
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.MutablePropertySources] [http-bio-8080-exec-10] Adding [systemProperties] PropertySource with lowest search precedence
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.MutablePropertySources] [http-bio-8080-exec-10] Adding [systemEnvironment] PropertySource with lowest search precedence
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.AbstractEnvironment] [http-bio-8080-exec-10] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.AbstractEnvironment] [http-bio-8080-exec-10] Initializing new StandardEnvironment
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.MutablePropertySources] [http-bio-8080-exec-10] Adding [systemProperties] PropertySource with lowest search precedence
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.MutablePropertySources] [http-bio-8080-exec-10] Adding [systemEnvironment] PropertySource with lowest search precedence
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.AbstractEnvironment] [http-bio-8080-exec-10] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.AbstractEnvironment] [http-bio-8080-exec-10] Initializing new StandardEnvironment
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.MutablePropertySources] [http-bio-8080-exec-10] Adding [systemProperties] PropertySource with lowest search precedence
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.MutablePropertySources] [http-bio-8080-exec-10] Adding [systemEnvironment] PropertySource with lowest search precedence
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.AbstractEnvironment] [http-bio-8080-exec-10] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.AbstractEnvironment] [http-bio-8080-exec-10] Initializing new StandardEnvironment
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.MutablePropertySources] [http-bio-8080-exec-10] Adding [systemProperties] PropertySource with lowest search precedence
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.MutablePropertySources] [http-bio-8080-exec-10] Adding [systemEnvironment] PropertySource with lowest search precedence
    2012-07-20 10:19:54,506 DEBUG [org.springframework.core.env.AbstractEnvironment] [http-bio-8080-exec-10] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
    2012-07-20 10:19:54,522 DEBUG [org.springframework.core.env.AbstractEnvironment] [http-bio-8080-exec-10] Initializing new StandardEnvironment
    2012-07-20 10:19:54,522 DEBUG [org.springframework.core.env.MutablePropertySources] [http-bio-8080-exec-10] Adding [systemProperties] PropertySource with lowest search precedence
    2012-07-20 10:19:54,522 DEBUG [org.springframework.core.env.MutablePropertySources] [http-bio-8080-exec-10] Adding [systemEnvironment] PropertySource with lowest search precedence
    2012-07-20 10:19:54,522 DEBUG [org.springframework.core.env.AbstractEnvironment] [http-bio-8080-exec-10] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
    2012-07-20 10:19:54,522 DEBUG [org.springframework.beans.BeanUtils] [http-bio-8080-exec-10] No property editor [org.springframework.web.multipart.MultipartFileEditor] found for type org.springframework.web.multipart.MultipartFile according to 'Editor' suffix convention
    2012-07-20 10:19:54,522 DEBUG [org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver] [http-bio-8080-exec-10] Resolving exception from handler [public com.ge.research.sadl.queryserver.webapp.controller.ExecuteQueryResult com.ge.research.sadl.queryserver.webapp.controller.QueryController.executeQuery(java.lang.String,java.lang.String,org.springframework.web.multipart.MultipartFile[],java.lang.String,javax.servlet.http.HttpServletResponse)]: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'org.springframework.web.multipart.MultipartFile[]'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found
    2012-07-20 10:19:54,522 DEBUG [org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver] [http-bio-8080-exec-10] Resolving exception from handler [public com.ge.research.sadl.queryserver.webapp.controller.ExecuteQueryResult com.ge.research.sadl.queryserver.webapp.controller.QueryController.executeQuery(java.lang.String,java.lang.String,org.springframework.web.multipart.MultipartFile[],java.lang.String,javax.servlet.http.HttpServletResponse)]: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'org.springframework.web.multipart.MultipartFile[]'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found
    2012-07-20 10:19:54,522 DEBUG [org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver] [http-bio-8080-exec-10] Resolving exception from handler [public com.ge.research.sadl.queryserver.webapp.controller.ExecuteQueryResult com.ge.research.sadl.queryserver.webapp.controller.QueryController.executeQuery(java.lang.String,java.lang.String,org.springframework.web.multipart.MultipartFile[],java.lang.String,javax.servlet.http.HttpServletResponse)]: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'org.springframework.web.multipart.MultipartFile[]'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found
    2012-07-20 10:19:54,522 DEBUG [org.springframework.web.servlet.DispatcherServlet] [http-bio-8080-exec-10] Null ModelAndView returned to DispatcherServlet with name 'appServlet': assuming HandlerAdapter completed request handling
    2012-07-20 10:19:54,522 DEBUG [org.springframework.web.servlet.FrameworkServlet] [http-bio-8080-exec-10] Successfully completed request

  6. #6
    Join Date
    Jul 2010
    Posts
    5

    Default

    Does anyone have any ideas as to why a null input type="file" element is not getting mapped into a MultipartFile[]?
    Also, why is Spring looking for a MultpartFileEditor? Thanks.

    Barry

  7. #7
    Join Date
    Jul 2010
    Posts
    5

    Default

    I figured this out myself. I believe this is a Spring bug. When I specify a method parameter of "@RequestParam(value="file",required=false) MultipartFile[] file"
    and no file is attached to the POST then Spring should be able to map the empty request parameter for "file" to null and not throw its hands up. I got around this by removing the parameter from the method and adding a "MultipartHttpServletRequest request" parameter. I then "List<MultipartFile> file = request.getFiles("file");" which correctly sets up "file". I would have thought that the RequestParam annotation could have done the same thing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •