Results 1 to 3 of 3

Thread: Handling MaxUploadSizeExceededException in Spring

Threaded View

  1. #1
    Join Date
    Jun 2012
    Posts
    13

    Default Handling MaxUploadSizeExceededException in Spring

    I'm using Spring 3.2.0. I have implemented the resolveException() method in my annotated controller which implements the HandlerExceptionResolver interface such as,

    Code:
    @Controller
    public final class ProductImageController implements HandlerExceptionResolver
    {
          public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object    handler, Exception exception)
          {
              Map<String, Object> model = new HashMap<String, Object>(0);
              if(exception instanceof MaxUploadSizeExceededException)
              {
                   model.put("msg", exception.toString());
                   model.put("status", "-1");
              }
              else
              {
                   model.put("msg", "Unexpected error : "+exception.toString());
                   model.put("status", "-1");
              }
              return new ModelAndView("admin_side/ProductImage");
         }
    }
    and the Spring configuration includes,

    Code:
    <bean id="filterMultipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize">
            <value>10000</value>
        </property>
    </bean>
    as specified here.

    When the file size exceeds, the method in the controller class should be invoked and it should automatically handle the exception but it doesn't happen at all. What I'm getting is the full stack trace on the browser. The method resolveException() is never called even though the exception occurs. What is the way to handle this exception? Am I missing something?

    I have also tried registering a separate bean annotated with @Component in application-context.xml but nothing worked.
    Last edited by Tiny; Jan 13th, 2013 at 03:08 PM.

Posting Permissions

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