How can I handle Tomcat's MaxUploadSizeExceededException in Spring?
Asked Answered
L

1

6

I have done some research around this with conflicting results. To handle this error, some say that I need to implement HandlerExceptionResolver in one of my controllers.

Here are some links for that:

On the other hand, other people are saying that this approach is futile such that the Exception is occuring outside the request handling flow:

I have tried the above solutions but they do not work for me. It appears that the Exception occurs outside of Spring, as expected. I am unable to catch this even with HandlerExceptionResolver.

Lindsay answered 23/2, 2015 at 22:3 Comment(11)
Are you using Standalone Tomcat distribution or Embedded Tomcat that comes with Spring?Beutner
I am using standalone :)Lindsay
Your question is confusing... What do you want, do you want to have spring handle your exception or spring web flow or ???Ca
Hello, so my issue is that on the web page, I have a file uploading form. The user can then add the over sized file to the form. Tomcat will then stack out. Following the stacktrace, we can see that the exception is being thrown by tomcat. Since tomcat is outside of the application's control, how can we catch the exception and then print a error message on the same page?Lindsay
Th exception will eventually always be thrown by tomcat as that is your container. As stated your question is confusing, first you mention Spring then out of the blue Spring Web Flow pops up...Ca
Ah, my apologies. I did not realise "Web Flow" was a used term in Spring. Computer Science and its many acronyms and reserved words! I was speaking from a more general sense as in the logic flow.Lindsay
Spring Web Flow is a spring project hence the confusion, you might better rephrase it with the request handling flow instead.Ca
Post your configuration (including web.xml) and HandlerExceptionResolver and also please state which specific spring version you are using.Ca
Are you talking about MultiPartUpload in Spring-MVC?? Cant you just set size by declaring a bean like this : <beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <beans:property name="maxUploadSize" value="52428800"/> </beans:bean>. And you can always list to MultiPartException in your Controller wherever there is file upload. Is this what you are looking for, I dont understand the relevance of tomcat here.. :-(Cosenza
Have a look at this : #2690489Whiffle
with the correct bean and HandlerExceptionResolver the expection should be handled correctly, see here please add your current implementation so we can check what is wrongProphesy
B
2

Trying following the approach specified in the link below. Basically, you configure an error page for any un handled exception and then define a handler for the error page. Looks like a decent workaround.

Here is the link http://www.javacodegeeks.com/2013/11/how-to-custom-error-pages-in-tomcat-with-spring-mvc.html

Hope this helps.

Beutner answered 23/6, 2015 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.