Hi,
Firstly, apologies if this is not the right area to post this. I did have a good look around for a a Portlet MVC area, but couldn't see anything.
OK, to my problem.
I have an annotation based Liferay Portlet application for uploading files. This all works fine, I have been looking at the validation of the uploaded file and need to restrict based on size. This can be done in Spring config with the following:
This is great, however, when posting to the Controller with a file larger than 10MB, the portlet returns a HTTP Response code 400. I'm assuming that Spring is throwing the exception, and just deciding to post that back. This is not what I want to do. I want to decide on how I return the error, as I would like to populate a JSON object.Code:<bean id="portletMultipartResolver" class="org.springframework.web.portlet.multipart.CommonsPortletMultipartResolver"> <!-- one of the properties available; the maximum file size in bytes --> <property name="maxUploadSize" value="9437000"/> <property name="uploadTempDir" value="/branches/"/> </bean>
I have found a few threads online.
The first option I have found that is supposed to fix the problem is to include this annotation in my controller:
This would allow me to redirect to a jsp page and produce the JSON I want, would be perfect, and the suggestion is that you can do this for any exception, which would be even better.Code:@ExceptionHandler public ModelAndView onException(Exception e) { ModelAndView mav = new ModelAndView(AJAX_IMAGE_UPLOAD_RESULT); mav.addObject("fileUploadError", e.getMessage()); return mav; }
Sadly, this doesn't seem to work!
The second option I found that does work, but seems wrong, as I don't want to have to deal with all exceptions manually is to implement an HandlerExceptionResolver interface and implement it's methods! I can do it this way, but will loose default exception handling, and to be honest I don't really want to do that!
Can any of you Spring experts out there let me know reasons why the first solution may not be working?
As it's annotation based I have assumed that there is no application.xml config to add! But I maybe wrong.
Thanks in advance


Reply With Quote
