Skip to content

Commit ce20268

Browse files
committed
Consistent warn logging without stacktrace in Portlet HandlerExceptionResolver
Issue: SPR-13611
1 parent 76d7f45 commit ce20268

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/handler/AbstractHandlerExceptionResolver.java

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@
3939
* and the {@link Ordered} implementation.
4040
*
4141
* @author Arjen Poutsma
42+
* @author Juergen Hoeller
4243
* @since 3.0
4344
*/
4445
public abstract class AbstractHandlerExceptionResolver implements HandlerExceptionResolver, Ordered {
@@ -67,40 +68,36 @@ public int getOrder() {
6768
}
6869

6970
/**
70-
* Specify the set of handlers that this exception resolver should map.
71-
* The exception mappings and the default error view will only apply
72-
* to the specified handlers.
73-
* <p>If no handlers set, both the exception mappings and the default error
74-
* view will apply to all handlers. This means that a specified default
75-
* error view will be used as fallback for all exceptions; any further
76-
* HandlerExceptionResolvers in the chain will be ignored in this case.
71+
* Specify the set of handlers that this exception resolver should apply to.
72+
* <p>The exception mappings and the default error view will only apply to the specified handlers.
73+
* <p>If no handlers or handler classes are set, the exception mappings and the default error
74+
* view will apply to all handlers. This means that a specified default error view will be used
75+
* as a fallback for all exceptions; any further HandlerExceptionResolvers in the chain will be
76+
* ignored in this case.
7777
*/
7878
public void setMappedHandlers(Set<?> mappedHandlers) {
7979
this.mappedHandlers = mappedHandlers;
8080
}
8181

8282
/**
8383
* Specify the set of classes that this exception resolver should apply to.
84-
* The exception mappings and the default error view will only apply
85-
* to handlers of the specified type; the specified types may be interfaces
86-
* and superclasses of handlers as well.
87-
* <p>If no handlers and handler classes are set, the exception mappings
88-
* and the default error view will apply to all handlers. This means that
89-
* a specified default error view will be used as fallback for all exceptions;
90-
* any further HandlerExceptionResolvers in the chain will be ignored in
91-
* this case.
84+
* <p>The exception mappings and the default error view will only apply to handlers of the
85+
* specified types; the specified types may be interfaces or superclasses of handlers as well.
86+
* <p>If no handlers or handler classes are set, the exception mappings and the default error
87+
* view will apply to all handlers. This means that a specified default error view will be used
88+
* as a fallback for all exceptions; any further HandlerExceptionResolvers in the chain will be
89+
* ignored in this case.
9290
*/
93-
public void setMappedHandlerClasses(Class<?>[] mappedHandlerClasses) {
91+
public void setMappedHandlerClasses(Class<?>... mappedHandlerClasses) {
9492
this.mappedHandlerClasses = mappedHandlerClasses;
9593
}
9694

9795
/**
98-
* Set the log category for warn logging. The name will be passed to the
99-
* underlying logger implementation through Commons Logging, getting
100-
* interpreted as log category according to the logger's configuration.
101-
* <p>Default is no warn logging. Specify this setting to activate
102-
* warn logging into a specific category. Alternatively, override
103-
* the {@link #logException} method for custom logging.
96+
* Set the log category for warn logging. The name will be passed to the underlying logger
97+
* implementation through Commons Logging, getting interpreted as a log category according
98+
* to the logger's configuration.
99+
* <p>Default is no warn logging. Specify this setting to activate warn logging into a specific
100+
* category. Alternatively, override the {@link #logException} method for custom logging.
104101
* @see org.apache.commons.logging.LogFactory#getLog(String)
105102
* @see org.apache.log4j.Logger#getLogger(String)
106103
* @see java.util.logging.Logger#getLogger(String)
@@ -183,8 +180,7 @@ protected boolean shouldApplyTo(PortletRequest request, Object handler) {
183180
/**
184181
* Log the given exception at warn level, provided that warn logging has been
185182
* activated through the {@link #setWarnLogCategory "warnLogCategory"} property.
186-
* <p>Calls {@link #buildLogMessage} in order to determine the concrete message
187-
* to log. Always passes the full exception to the logger.
183+
* <p>Calls {@link #buildLogMessage} in order to determine the concrete message to log.
188184
* @param ex the exception that got thrown during handler execution
189185
* @param request current portlet request (useful for obtaining metadata)
190186
* @see #setWarnLogCategory
@@ -193,19 +189,18 @@ protected boolean shouldApplyTo(PortletRequest request, Object handler) {
193189
*/
194190
protected void logException(Exception ex, PortletRequest request) {
195191
if (this.warnLogger != null && this.warnLogger.isWarnEnabled()) {
196-
this.warnLogger.warn(buildLogMessage(ex, request), ex);
192+
this.warnLogger.warn(buildLogMessage(ex, request));
197193
}
198194
}
199195

200196
/**
201-
* Build a log message for the given exception, occured during processing
202-
* the given request.
197+
* Build a log message for the given exception, occurred during processing the given request.
203198
* @param ex the exception that got thrown during handler execution
204199
* @param request current portlet request (useful for obtaining metadata)
205200
* @return the log message to use
206201
*/
207202
protected String buildLogMessage(Exception ex, PortletRequest request) {
208-
return "Handler execution resulted in exception";
203+
return "Handler execution resulted in exception: " + ex;
209204
}
210205

211206

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void setMappedHandlers(Set<?> mappedHandlers) {
8888
* as a fallback for all exceptions; any further HandlerExceptionResolvers in the chain will be
8989
* ignored in this case.
9090
*/
91-
public void setMappedHandlerClasses(Class<?>[] mappedHandlerClasses) {
91+
public void setMappedHandlerClasses(Class<?>... mappedHandlerClasses) {
9292
this.mappedHandlerClasses = mappedHandlerClasses;
9393
}
9494

@@ -116,6 +116,7 @@ public void setPreventResponseCaching(boolean preventResponseCaching) {
116116
this.preventResponseCaching = preventResponseCaching;
117117
}
118118

119+
119120
/**
120121
* Check whether this resolver is supposed to apply (i.e. if the supplied handler
121122
* matches any of the configured {@linkplain #setMappedHandlers handlers} or
@@ -220,6 +221,7 @@ protected void preventCaching(HttpServletResponse response) {
220221
response.addHeader(HEADER_CACHE_CONTROL, "no-store");
221222
}
222223

224+
223225
/**
224226
* Actually resolve the given exception that got thrown during handler execution,
225227
* returning a {@link ModelAndView} that represents a specific error page if appropriate.

0 commit comments

Comments
 (0)