Consistent warn logging without stacktrace in Portlet HandlerExceptionResolver
Issue: SPR-13611
This commit is contained in:
parent
76d7f4527a
commit
ce20268597
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -39,6 +39,7 @@ import org.springframework.web.portlet.ModelAndView;
|
||||||
* and the {@link Ordered} implementation.
|
* and the {@link Ordered} implementation.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
* @author Juergen Hoeller
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractHandlerExceptionResolver implements HandlerExceptionResolver, Ordered {
|
public abstract class AbstractHandlerExceptionResolver implements HandlerExceptionResolver, Ordered {
|
||||||
|
|
@ -67,13 +68,12 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the set of handlers that this exception resolver should map.
|
* Specify the set of handlers that this exception resolver should apply to.
|
||||||
* The exception mappings and the default error view will only apply
|
* <p>The exception mappings and the default error view will only apply to the specified handlers.
|
||||||
* to the specified handlers.
|
* <p>If no handlers or handler classes are set, the exception mappings and the default error
|
||||||
* <p>If no handlers set, both the exception mappings and the default error
|
* view will apply to all handlers. This means that a specified default error view will be used
|
||||||
* view will apply to all handlers. This means that a specified default
|
* as a fallback for all exceptions; any further HandlerExceptionResolvers in the chain will be
|
||||||
* error view will be used as fallback for all exceptions; any further
|
* ignored in this case.
|
||||||
* HandlerExceptionResolvers in the chain will be ignored in this case.
|
|
||||||
*/
|
*/
|
||||||
public void setMappedHandlers(Set<?> mappedHandlers) {
|
public void setMappedHandlers(Set<?> mappedHandlers) {
|
||||||
this.mappedHandlers = mappedHandlers;
|
this.mappedHandlers = mappedHandlers;
|
||||||
|
|
@ -81,26 +81,23 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the set of classes that this exception resolver should apply to.
|
* Specify the set of classes that this exception resolver should apply to.
|
||||||
* The exception mappings and the default error view will only apply
|
* <p>The exception mappings and the default error view will only apply to handlers of the
|
||||||
* to handlers of the specified type; the specified types may be interfaces
|
* specified types; the specified types may be interfaces or superclasses of handlers as well.
|
||||||
* and superclasses of handlers as well.
|
* <p>If no handlers or handler classes are set, the exception mappings and the default error
|
||||||
* <p>If no handlers and handler classes are set, the exception mappings
|
* view will apply to all handlers. This means that a specified default error view will be used
|
||||||
* and the default error view will apply to all handlers. This means that
|
* as a fallback for all exceptions; any further HandlerExceptionResolvers in the chain will be
|
||||||
* a specified default error view will be used as fallback for all exceptions;
|
* ignored in this case.
|
||||||
* any further HandlerExceptionResolvers in the chain will be ignored in
|
|
||||||
* this case.
|
|
||||||
*/
|
*/
|
||||||
public void setMappedHandlerClasses(Class<?>[] mappedHandlerClasses) {
|
public void setMappedHandlerClasses(Class<?>... mappedHandlerClasses) {
|
||||||
this.mappedHandlerClasses = mappedHandlerClasses;
|
this.mappedHandlerClasses = mappedHandlerClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the log category for warn logging. The name will be passed to the
|
* Set the log category for warn logging. The name will be passed to the underlying logger
|
||||||
* underlying logger implementation through Commons Logging, getting
|
* implementation through Commons Logging, getting interpreted as a log category according
|
||||||
* interpreted as log category according to the logger's configuration.
|
* to the logger's configuration.
|
||||||
* <p>Default is no warn logging. Specify this setting to activate
|
* <p>Default is no warn logging. Specify this setting to activate warn logging into a specific
|
||||||
* warn logging into a specific category. Alternatively, override
|
* category. Alternatively, override the {@link #logException} method for custom logging.
|
||||||
* the {@link #logException} method for custom logging.
|
|
||||||
* @see org.apache.commons.logging.LogFactory#getLog(String)
|
* @see org.apache.commons.logging.LogFactory#getLog(String)
|
||||||
* @see org.apache.log4j.Logger#getLogger(String)
|
* @see org.apache.log4j.Logger#getLogger(String)
|
||||||
* @see java.util.logging.Logger#getLogger(String)
|
* @see java.util.logging.Logger#getLogger(String)
|
||||||
|
|
@ -183,8 +180,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
|
||||||
/**
|
/**
|
||||||
* Log the given exception at warn level, provided that warn logging has been
|
* Log the given exception at warn level, provided that warn logging has been
|
||||||
* activated through the {@link #setWarnLogCategory "warnLogCategory"} property.
|
* activated through the {@link #setWarnLogCategory "warnLogCategory"} property.
|
||||||
* <p>Calls {@link #buildLogMessage} in order to determine the concrete message
|
* <p>Calls {@link #buildLogMessage} in order to determine the concrete message to log.
|
||||||
* to log. Always passes the full exception to the logger.
|
|
||||||
* @param ex the exception that got thrown during handler execution
|
* @param ex the exception that got thrown during handler execution
|
||||||
* @param request current portlet request (useful for obtaining metadata)
|
* @param request current portlet request (useful for obtaining metadata)
|
||||||
* @see #setWarnLogCategory
|
* @see #setWarnLogCategory
|
||||||
|
|
@ -193,19 +189,18 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
|
||||||
*/
|
*/
|
||||||
protected void logException(Exception ex, PortletRequest request) {
|
protected void logException(Exception ex, PortletRequest request) {
|
||||||
if (this.warnLogger != null && this.warnLogger.isWarnEnabled()) {
|
if (this.warnLogger != null && this.warnLogger.isWarnEnabled()) {
|
||||||
this.warnLogger.warn(buildLogMessage(ex, request), ex);
|
this.warnLogger.warn(buildLogMessage(ex, request));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a log message for the given exception, occured during processing
|
* Build a log message for the given exception, occurred during processing the given request.
|
||||||
* the given request.
|
|
||||||
* @param ex the exception that got thrown during handler execution
|
* @param ex the exception that got thrown during handler execution
|
||||||
* @param request current portlet request (useful for obtaining metadata)
|
* @param request current portlet request (useful for obtaining metadata)
|
||||||
* @return the log message to use
|
* @return the log message to use
|
||||||
*/
|
*/
|
||||||
protected String buildLogMessage(Exception ex, PortletRequest request) {
|
protected String buildLogMessage(Exception ex, PortletRequest request) {
|
||||||
return "Handler execution resulted in exception";
|
return "Handler execution resulted in exception: " + ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
|
||||||
* as a fallback for all exceptions; any further HandlerExceptionResolvers in the chain will be
|
* as a fallback for all exceptions; any further HandlerExceptionResolvers in the chain will be
|
||||||
* ignored in this case.
|
* ignored in this case.
|
||||||
*/
|
*/
|
||||||
public void setMappedHandlerClasses(Class<?>[] mappedHandlerClasses) {
|
public void setMappedHandlerClasses(Class<?>... mappedHandlerClasses) {
|
||||||
this.mappedHandlerClasses = mappedHandlerClasses;
|
this.mappedHandlerClasses = mappedHandlerClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,6 +116,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
|
||||||
this.preventResponseCaching = preventResponseCaching;
|
this.preventResponseCaching = preventResponseCaching;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether this resolver is supposed to apply (i.e. if the supplied handler
|
* Check whether this resolver is supposed to apply (i.e. if the supplied handler
|
||||||
* matches any of the configured {@linkplain #setMappedHandlers handlers} or
|
* matches any of the configured {@linkplain #setMappedHandlers handlers} or
|
||||||
|
|
@ -220,6 +221,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
|
||||||
response.addHeader(HEADER_CACHE_CONTROL, "no-store");
|
response.addHeader(HEADER_CACHE_CONTROL, "no-store");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actually resolve the given exception that got thrown during handler execution,
|
* Actually resolve the given exception that got thrown during handler execution,
|
||||||
* returning a {@link ModelAndView} that represents a specific error page if appropriate.
|
* returning a {@link ModelAndView} that represents a specific error page if appropriate.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue