SWS-490 - log Exceptions in SoapFaultMappingExceptionResolver (like spring webmvc SimpleMappingExceptionResolver)

This commit is contained in:
Arjen Poutsma
2009-05-13 10:38:57 +00:00
parent 2004935f89
commit 35f2e8ecd6

View File

@@ -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. <p>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.
* <p/>
* 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.
* <p/>
@@ -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.
* <p/>
* 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}.
*