diff --git a/core/src/main/java/org/springframework/ws/server/endpoint/AbstractEndpointExceptionResolver.java b/core/src/main/java/org/springframework/ws/server/endpoint/AbstractEndpointExceptionResolver.java index 45daa028..95d5c893 100644 --- a/core/src/main/java/org/springframework/ws/server/endpoint/AbstractEndpointExceptionResolver.java +++ b/core/src/main/java/org/springframework/ws/server/endpoint/AbstractEndpointExceptionResolver.java @@ -43,6 +43,8 @@ public abstract class AbstractEndpointExceptionResolver implements EndpointExcep private Set mappedEndpoints; + private Log warnLogger; + /** * Specify the set of endpoints that this exception resolver should map.
The exception mappings and the default * fault will only apply to the specified endpoints. @@ -55,6 +57,21 @@ public abstract class AbstractEndpointExceptionResolver implements EndpointExcep this.mappedEndpoints = mappedEndpoints; } + /** + * Set the log category for warn logging. The name will be passed to the underlying logger implementation through + * 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) + */ + public void setWarnLogCategory(String loggerName) { + this.warnLogger = LogFactory.getLog(loggerName); + } + /** * Specify the order value for this mapping. * @@ -81,9 +98,44 @@ public abstract class AbstractEndpointExceptionResolver implements EndpointExcep if (mappedEndpoints != null && !mappedEndpoints.contains(mappedEndpoint)) { return false; } + // Log exception, both at debug log level and at warn level, if desired. + if (logger.isDebugEnabled()) { + logger.debug("Resolving exception from endpoint [" + endpoint + "]: " + ex); + } + logException(ex, messageContext); return resolveExceptionInternal(messageContext, endpoint, ex); } + /** + * 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 messageContext current message context request + * @see #setWarnLogCategory + * @see #buildLogMessage + * @see org.apache.commons.logging.Log#warn(Object, Throwable) + */ + protected void logException(Exception ex, MessageContext messageContext) { + if (this.warnLogger != null && this.warnLogger.isWarnEnabled()) { + this.warnLogger.warn(buildLogMessage(ex, messageContext), ex); + } + } + + /** + * Build a log message for the given exception, occured during processing the given message context. + * + * @param ex the exception that got thrown during handler execution + * @param messageContext the message context + * @return the log message to use + */ + protected String buildLogMessage(Exception ex, MessageContext messageContext) { + return "Endpoint execution resulted in exception"; + } + /** * Template method for resolving exceptions that is called by {@link #resolveException}. *