Spring Web Services Framework

org.springframework.ws.server.endpoint
Class AbstractLoggingInterceptor

java.lang.Object
  extended by org.springframework.xml.transform.TransformerObjectSupport
      extended by org.springframework.ws.server.endpoint.AbstractLoggingInterceptor
All Implemented Interfaces:
EndpointInterceptor
Direct Known Subclasses:
PayloadLoggingInterceptor, SoapEnvelopeLoggingInterceptor

public abstract class AbstractLoggingInterceptor
extends TransformerObjectSupport
implements EndpointInterceptor

Abstract base class for EndpointInterceptor instances that log a part of a WebServiceMessage. By default, both request and response messages are logged, but this behaviour can be changed using the logRequest and logResponse properties.

Since:
1.0.0
Author:
Arjen Poutsma

Field Summary
protected  Log logger
          The default Log instance used to write trace messages.
 
Constructor Summary
AbstractLoggingInterceptor()
           
 
Method Summary
protected abstract  Source getSource(WebServiceMessage message)
          Abstract template method that returns the Source for the given WebServiceMessage.
 boolean handleFault(MessageContext messageContext, Object endpoint)
          Does nothing by default.
 boolean handleRequest(MessageContext messageContext, Object endpoint)
          Logs the request message payload.
 boolean handleResponse(MessageContext messageContext, Object endpoint)
          Logs the response message payload.
protected  boolean isLogEnabled()
          Determine whether the logger field is enabled.
protected  void logMessage(String message)
          Logs the given string message.
protected  void logMessageSource(String logMessage, Source source)
          Logs the given source to the logger, using the message as a prefix.
 void setLoggerName(String loggerName)
          Set the name of the logger to use.
 void setLogRequest(boolean logRequest)
          Indicates whether the request should be logged.
 void setLogResponse(boolean logResponse)
          Indicates whether the response should be logged.
 
Methods inherited from class org.springframework.xml.transform.TransformerObjectSupport
createTransformer, getTransformerFactory, newTransformerFactory, setTransformerFactoryClass, transform
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected transient Log logger
The default Log instance used to write trace messages. This instance is mapped to the implementing Class.

Constructor Detail

AbstractLoggingInterceptor

public AbstractLoggingInterceptor()
Method Detail

setLogRequest

public final void setLogRequest(boolean logRequest)
Indicates whether the request should be logged. Default is true.


setLogResponse

public final void setLogResponse(boolean logResponse)
Indicates whether the response should be logged. Default is true.


setLoggerName

public void setLoggerName(String loggerName)
Set the name of the logger to use. The name will be passed to the underlying logger implementation through Commons Logging, getting interpreted as log category according to the logger's configuration.

This can be specified to not log into the category of a class but rather into a specific named category.

See Also:
LogFactory.getLog(String), org.apache.log4j.Logger#getLogger(String), Logger

handleRequest

public final boolean handleRequest(MessageContext messageContext,
                                   Object endpoint)
                            throws TransformerException
Logs the request message payload. Logging only ocurs if logRequest is set to true, which is the default.

Specified by:
handleRequest in interface EndpointInterceptor
Parameters:
messageContext - the message context
endpoint - chosen endpoint to invoke
Returns:
true
Throws:
TransformerException - when the payload cannot be transformed to a string
See Also:
MessageContext.getRequest()

handleResponse

public boolean handleResponse(MessageContext messageContext,
                              Object endpoint)
                       throws Exception
Logs the response message payload. Logging only ocurs if logResponse is set to true, which is the default.

Specified by:
handleResponse in interface EndpointInterceptor
Parameters:
messageContext - the message context
endpoint - chosen endpoint to invoke
Returns:
true
Throws:
TransformerException - when the payload cannot be transformed to a string
Exception - in case of errors
See Also:
MessageContext.getRequest(), MessageContext.hasResponse(), MessageContext.getResponse()

handleFault

public boolean handleFault(MessageContext messageContext,
                           Object endpoint)
                    throws Exception
Does nothing by default. Faults are not logged.

Specified by:
handleFault in interface EndpointInterceptor
Parameters:
messageContext - contains both request and response messages, the response should contains a Fault
endpoint - chosen endpoint to invoke
Returns:
true to continue processing of the reponse interceptor chain; false to indicate blocking of the response handler chain.
Throws:
Exception

isLogEnabled

protected boolean isLogEnabled()
Determine whether the logger field is enabled.

Default is true when the "debug" level is enabled. Subclasses can override this to change the level under which logging occurs.


logMessageSource

protected void logMessageSource(String logMessage,
                                Source source)
                         throws TransformerException
Logs the given source to the logger, using the message as a prefix.

By default, this message creates a string representation of the given source, and delegates to logMessage(String).

Parameters:
logMessage - the log message
source - the source to be logged
Throws:
TransformerException - in case of errors

logMessage

protected void logMessage(String message)
Logs the given string message.

By default, this method uses a "debug" level of logging. Subclasses can override this method to change the level of loging used by the logger.

Parameters:
message - the message

getSource

protected abstract Source getSource(WebServiceMessage message)
Abstract template method that returns the Source for the given WebServiceMessage.

Parameters:
message - the message
Returns:
the source of the message

Spring Web Services Framework

Copyright © 2005-2010 The Spring Web Services Framework. All Rights Reserved.