You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exceptions thrown from a controller due to an ActionRequest are not handled via the AnnotationMethodHandlerExceptionResolver.
This seems to be because the 'handler' argument is never passed to the resolveException method.
I changed org.springframework.web.portlet.DispatcherPortlet.doRenderService(RenderRequest, RenderResponse) to call getHandler()
before the processing of the ACTION_EXCEPTION_RENDER_PARAMETER and this seemed to fix the problem (though I'm not sure of any other ramifications of this change).
Please ignore my patch as it really doesn't cater for all usage scenarios, specifically when two or more controllers are defined for the one portlet. In this case the getHandler() method returned in the doRenderService is not guaranteed to be the same one returned in the doActionService(). Therefore the @ExceptionHandler method will not be invoked.
Here's a use case
Two controllers (A & B) and defined in a spring portlet XML file.
@Controller
class A {
@RenderMapping
public String defaultRender() {}
}
@Controller
class B {
@RenderMapping(params="action=stuff")
public String renderStuff() {}
@ActionMapping(params="action=stuff")
public String actionStuff() {}
@ExceptionHandler
public ModelAndView handleException() {}
}
If an exception is thrown in actionStuff then handleException is never executed. Even with the patch I supplied, the handler returned by getHandler is for A not B
As of Spring 3.0.2, we are passing the handler instance into HandlerExceptionResolver even for an action exception, and we're also applying the HandlerInterceptor preHandleRender phase in such a case (which we didn't before).
However, this is always going to be about the handler instance that defines the render handler method that is about to be invoked. @ExceptionHandler only applies to render and resource phases, which is also explicitly defined in its javadoc now. Note that this is equivalent to the HandlerExceptionResolver interface. The rationale behind that is that exception handling in a web environment primarily means rendering error pages, or sending back some other kind of error response - which can only be done in the render phase. In other words, the kind of exceptions that you are applying @ExceptionHandler to should have an immediate rendering effect; if it's rather a control flow exception that you're dealing with, use a try-catch block within the action handler method instead.
Peter Oxenham opened SPR-6959 and commented
Exceptions thrown from a controller due to an ActionRequest are not handled via the AnnotationMethodHandlerExceptionResolver.
This seems to be because the 'handler' argument is never passed to the resolveException method.
I changed org.springframework.web.portlet.DispatcherPortlet.doRenderService(RenderRequest, RenderResponse) to call getHandler()
before the processing of the ACTION_EXCEPTION_RENDER_PARAMETER and this seemed to fix the problem (though I'm not sure of any other ramifications of this change).
Affects: 3.0.1
Attachments:
Referenced from: commits b67b5ec, 65e8844
The text was updated successfully, but these errors were encountered: