diff --git a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/handler/AbstractHandlerExceptionResolver.java b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/handler/AbstractHandlerExceptionResolver.java index 37bae30edc..c03ab5c507 100644 --- a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/handler/AbstractHandlerExceptionResolver.java +++ b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/handler/AbstractHandlerExceptionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,8 +33,10 @@ import org.springframework.web.portlet.ModelAndView; import org.springframework.core.Ordered; /** - * Abstract base class for {@link HandlerExceptionResolver} implementations.
Provides a set of mapped handlers that - * the resolver should map to, and the {@link Ordered} implementation. + * Abstract base class for {@link HandlerExceptionResolver} implementations. + * + *
Provides a set of mapped handlers that the resolver should map to, + * and the {@link Ordered} implementation. * * @author Arjen Poutsma * @since 3.0 @@ -54,6 +56,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti private boolean renderWhenMinimized = false; + public void setOrder(int order) { this.order = order; } @@ -115,14 +118,13 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti this.renderWhenMinimized = renderWhenMinimized; } + /** * Checks whether this resolver is supposed to apply (i.e. the handler * matches in case of "mappedHandlers" having been specified), then * delegates to the {@link #doResolveException} template method. */ - public ModelAndView resolveException( - RenderRequest request, RenderResponse response, Object handler, Exception ex) { - + public ModelAndView resolveException(RenderRequest request, RenderResponse response, Object handler, Exception ex) { if (shouldApplyTo(request, handler)) { return doResolveException(request, response, handler, ex); } @@ -131,9 +133,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti } } - public ModelAndView resolveException( - ResourceRequest request, ResourceResponse response, Object handler, Exception ex) { - + public ModelAndView resolveException(ResourceRequest request, ResourceResponse response, Object handler, Exception ex) { if (shouldApplyTo(request, handler)) { return doResolveException(request, response, handler, ex); } @@ -205,14 +205,14 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti return "Handler execution resulted in exception"; } + /** * Actually resolve the given exception that got thrown during on handler execution, * returning a ModelAndView that represents a specific error page if appropriate. - * - *
Must be overridden in subclasses, in order to apply specific exception checks. Note that this template method - * will be invoked after checking whether this resolved applies ("mappedHandlers" etc), so an implementation - * may simply proceed with its actual exception handling. - + *
Must be overridden in subclasses, in order to apply specific exception checks. + * Note that this template method will be invoked after checking whether this + * resolved applies ("mappedHandlers" etc), so an implementation may simply proceed + * with its actual exception handling. * @param request current portlet request * @param response current portlet response * @param handler the executed handler, or null if none chosen at the time of @@ -220,9 +220,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti * @param ex the exception that got thrown during handler execution * @return a corresponding ModelAndView to forward to, or null for default processing */ - protected abstract ModelAndView doResolveException(PortletRequest request, - MimeResponse response, - Object handler, - Exception ex); + protected abstract ModelAndView doResolveException(PortletRequest request, MimeResponse response, + Object handler, Exception ex); } diff --git a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java index a4bf4277c4..92f8a8fe9d 100644 --- a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java +++ b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java @@ -245,10 +245,9 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc Class paramType = methodParameter.getParameterType(); Object value = resolveStandardArgument(paramType, webRequest, thrownException); if (value != WebArgumentResolver.UNRESOLVED && !ClassUtils.isAssignableValue(paramType, value)) { - throw new IllegalStateException( - "Standard argument type [" + paramType.getName() + "] resolved to incompatible value of type [" + - (value != null ? value.getClass() : null) + - "]. Consider declaring the argument type in a less specific fashion."); + throw new IllegalStateException("Standard argument type [" + paramType.getName() + + "] resolved to incompatible value of type [" + (value != null ? value.getClass() : null) + + "]. Consider declaring the argument type in a less specific fashion."); } return value; } @@ -266,7 +265,10 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc protected Object resolveStandardArgument(Class parameterType, NativeWebRequest webRequest, Exception thrownException) throws Exception { - if (WebRequest.class.isAssignableFrom(parameterType)) { + if (parameterType.isInstance(thrownException)) { + return thrownException; + } + else if (WebRequest.class.isAssignableFrom(parameterType)) { return webRequest; } @@ -330,9 +332,6 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc } return ((EventRequest) request).getEvent(); } - else if (parameterType.isInstance(thrownException)) { - return thrownException; - } else { return WebArgumentResolver.UNRESOLVED; } diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java index a32f626da1..c6fdec3ae8 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,10 @@ import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.ModelAndView; /** - * Abstract base class for {@link HandlerExceptionResolver} implementations.
Provides a set of mapped handlers that - * the resolver should map to, and the {@link Ordered} implementation. + * Abstract base class for {@link HandlerExceptionResolver} implementations. + * + *
Provides a set of mapped handlers that the resolver should map to, + * and the {@link Ordered} implementation. * * @author Arjen Poutsma * @since 3.0 @@ -47,6 +49,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti private Log warnLogger; + public void setOrder(int order) { this.order = order; } @@ -82,7 +85,6 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti * Commons Logging, getting interpreted as log category according to the logger's configuration.
Default is no warn * logging. Specify this setting to activate warn logging into a specific category. Alternatively, override the {@link * #logException} method for custom logging. - * * @see org.apache.commons.logging.LogFactory#getLog(String) * @see org.apache.log4j.Logger#getLogger(String) * @see java.util.logging.Logger#getLogger(String) @@ -91,14 +93,14 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti this.warnLogger = LogFactory.getLog(loggerName); } + /** - * Checks whether this resolver is supposed to apply (i.e. the handler matches in case of "mappedHandlers" having been - * specified), then delegates to the {@link #doResolveException} template method. + * Checks whether this resolver is supposed to apply (i.e. the handler matches + * in case of "mappedHandlers" having been specified), then delegates to the + * {@link #doResolveException} template method. */ - public ModelAndView resolveException(HttpServletRequest request, - HttpServletResponse response, - Object handler, - Exception ex) { + public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, + Object handler, Exception ex) { if (shouldApplyTo(request, handler)) { // Log exception, both at debug log level and at warn level, if desired. @@ -114,13 +116,14 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti } /** - * Check whether this resolver is supposed to apply to the given handler.
The default implementation checks against - * the specified mapped handlers and handler classes, if any. - * + * Check whether this resolver is supposed to apply to the given handler. + *
The default implementation checks against the specified mapped handlers
+ * and handler classes, if any.
* @param request current HTTP request
- * @param handler the executed handler, or null
if none chosen at the time of the exception (for example,
- * if multipart resolution failed)
- * @return whether this resolved should proceed with resolving the exception for the given request and handler
+ * @param handler the executed handler, or null
if none chosen
+ * at the time of the exception (for example, if multipart resolution failed)
+ * @return whether this resolved should proceed with resolving the exception
+ * for the given request and handler
* @see #setMappedHandlers
* @see #setMappedHandlerClasses
*/
@@ -142,10 +145,10 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
}
/**
- * Log the given exception at warn level, provided that warn logging has been activated through the {@link
- * #setWarnLogCategory "warnLogCategory"} property.
Calls {@link #buildLogMessage} in order to determine the - * concrete message to log. Always passes the full exception to the logger. - * + * Log the given exception at warn level, provided that warn logging has been + * activated through the {@link #setWarnLogCategory "warnLogCategory"} property. + *
Calls {@link #buildLogMessage} in order to determine the concrete message to log. + * Always passes the full exception to the logger. * @param ex the exception that got thrown during handler execution * @param request current HTTP request (useful for obtaining metadata) * @see #setWarnLogCategory @@ -160,7 +163,6 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti /** * Build a log message for the given exception, occured during processing the given request. - * * @param ex the exception that got thrown during handler execution * @param request current HTTP request (useful for obtaining metadata) * @return the log message to use @@ -170,21 +172,20 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti } /** - * Actually resolve the given exception that got thrown during on handler execution, returning a ModelAndView that - * represents a specific error page if appropriate.
May be overridden in subclasses, in order to apply specific - * exception checks. Note that this template method will be invoked after checking whether this resolved applies - * ("mappedHandlers" etc), so an implementation may simply proceed with its actual exception handling. - * + * Actually resolve the given exception that got thrown during on handler execution, + * returning a ModelAndView that represents a specific error page if appropriate. + *
May be overridden in subclasses, in order to apply specific exception checks.
+ * Note that this template method will be invoked after checking whether this
+ * resolved applies ("mappedHandlers" etc), so an implementation may simply proceed
+ * with its actual exception handling.
* @param request current HTTP request
* @param response current HTTP response
- * @param handler the executed handler, or null
if none chosen at the time of the exception (for example,
- * if multipart resolution failed)
+ * @param handler the executed handler, or null
if none chosen at the time
+ * of the exception (for example, if multipart resolution failed)
* @param ex the exception that got thrown during handler execution
* @return a corresponding ModelAndView to forward to, or null
for default processing
*/
protected abstract ModelAndView doResolveException(HttpServletRequest request,
- HttpServletResponse response,
- Object handler,
- Exception ex);
+ HttpServletResponse response, Object handler, Exception ex);
}
diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java
index a91a6b72d3..93ff5e7e01 100644
--- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java
+++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java
@@ -82,21 +82,23 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc
private WebArgumentResolver[] customArgumentResolvers;
private HttpMessageConverter>[] messageConverters =
- new HttpMessageConverter[]{new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(),
+ new HttpMessageConverter[] {new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(),
new FormHttpMessageConverter(), new SourceHttpMessageConverter()};
/**
- * Set a custom ArgumentResolvers to use for special method parameter types. Such a custom ArgumentResolver will kick
- * in first, having a chance to resolve an argument value before the standard argument handling kicks in.
+ * Set a custom ArgumentResolvers to use for special method parameter types.
+ *
Such a custom ArgumentResolver will kick in first, having a chance to resolve + * an argument value before the standard argument handling kicks in. */ public void setCustomArgumentResolver(WebArgumentResolver argumentResolver) { this.customArgumentResolvers = new WebArgumentResolver[]{argumentResolver}; } /** - * Set one or more custom ArgumentResolvers to use for special method parameter types. Any such custom ArgumentResolver - * will kick in first, having a chance to resolve an argument value before the standard argument handling kicks in. + * Set one or more custom ArgumentResolvers to use for special method parameter types. + *
Any such custom ArgumentResolver will kick in first, having a chance to resolve + * an argument value before the standard argument handling kicks in. */ public void setCustomArgumentResolvers(WebArgumentResolver[] argumentResolvers) { this.customArgumentResolvers = argumentResolvers; @@ -288,7 +290,10 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc protected Object resolveStandardArgument(Class parameterType, NativeWebRequest webRequest, Exception thrownException) throws Exception { - if (WebRequest.class.isAssignableFrom(parameterType)) { + if (parameterType.isInstance(thrownException)) { + return thrownException; + } + else if (WebRequest.class.isAssignableFrom(parameterType)) { return webRequest; } @@ -322,9 +327,6 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc else if (Writer.class.isAssignableFrom(parameterType)) { return response.getWriter(); } - else if (parameterType.isInstance(thrownException)) { - return thrownException; - } else { return WebArgumentResolver.UNRESOLVED;