Browse Source

Expose handled exception as request attribute

This change exposes exceptions handled in the DispatcherServlet with a
HandlerExceptionResolver as a request attribute. This is done only when
the resolver returns an empty ModelAndView indicating the exception was
resolved but not view is required (e.g. status code was set). In such
cases the exception may be useful to any handlers in an ERRPR dispatch
by the servlet container.

Issue: SPR-11686
pull/563/merge
Rossen Stoyanchev 11 years ago
parent
commit
476864f3e9
  1. 8
      spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

8
spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

@ -232,6 +232,13 @@ public class DispatcherServlet extends FrameworkServlet {
*/ */
public static final String FLASH_MAP_MANAGER_ATTRIBUTE = DispatcherServlet.class.getName() + ".FLASH_MAP_MANAGER"; public static final String FLASH_MAP_MANAGER_ATTRIBUTE = DispatcherServlet.class.getName() + ".FLASH_MAP_MANAGER";
/**
* Name of request attribute that exposes an Exception resolved with an
* {@link HandlerExceptionResolver} but where no view was rendered
* (e.g. setting the status code).
*/
public static final String EXCEPTION_ATTRIBUTE = DispatcherServlet.class.getName() + ".EXCEPTION";
/** Log category to use when no mapped handler is found for a request. */ /** Log category to use when no mapped handler is found for a request. */
public static final String PAGE_NOT_FOUND_LOG_CATEGORY = "org.springframework.web.servlet.PageNotFound"; public static final String PAGE_NOT_FOUND_LOG_CATEGORY = "org.springframework.web.servlet.PageNotFound";
@ -1165,6 +1172,7 @@ public class DispatcherServlet extends FrameworkServlet {
} }
if (exMv != null) { if (exMv != null) {
if (exMv.isEmpty()) { if (exMv.isEmpty()) {
request.setAttribute(EXCEPTION_ATTRIBUTE, ex);
return null; return null;
} }
// We might still need view name translation for a plain error model... // We might still need view name translation for a plain error model...

Loading…
Cancel
Save