Class ExceptionHandlingServiceWrapper
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.services.exception.ExceptionHandlingServiceWrapper
-
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,EventHandlerAware
,MessageEventGenerator
,Service
,ServiceWrapper
,StateManagedComponent
@ComponentProfile(summary="Handle exceptions from one service via a separate service", tag="service,error-handling") public class ExceptionHandlingServiceWrapper extends ServiceImp implements EventHandlerAware, ServiceWrapper
Wraps services so that errors are intercepted and processed by a different service.This Service wraps a
Service
; if this wrapped Service throws a ServiceException the configured exceptionHandlingService is applied. Normal message error handling is not triggered unless an exception is thrown from the service handling the exception.This Service is intended for use where an exception processing a message should generate a synchronous reply e.g. when processing web service requests. It could be used where detailed information about the error is required to be sent as part of the reply. This can be acheived by configuring services as part of the exceptionHandlingService.
Note that the exception handling service will process the message IN THE STATE AT WHICH IT FAILED (i.e. the payload of the message may have been modified). It might not be possible to recover any meaningful data from this if say, an exception is triggered after encrypting the data with a remote party's public key. If you wish to use process the original message then you should configure a
StandardProcessingExceptionHandler
at the workflow level.StandardProcessingExceptionHandler
allows you to configure arbitrary services to perform operations on messages that have failed.In the adapter configuration file this class is aliased as exception-handling-service-wrapper which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_EXCEPTION_MESSAGE_METADATA_KEY
-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description ExceptionHandlingServiceWrapper()
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeService()
void
doService(AdaptrisMessage msg)
Apply the service to the message.Service
getExceptionHandlingService()
Returns the Service to call if an exception is encountered calling the wrapped Service.java.lang.String
getExceptionMessageMetadataKey()
Returns the metadata key to store the exception message against.Service
getService()
Returns the Service to wrap.protected void
initService()
void
prepare()
Prepare for initialisation.void
registerEventHandler(EventHandler eh)
Register the current event handler against this component.void
setExceptionHandlingService(Service s)
Sets the Service to call if an exception is encountered calling the wrapped Service.void
setExceptionMessageMetadataKey(java.lang.String s)
Sets the metadata key to store the exception message against.void
setService(Service s)
Sets the Service to wrap.void
start()
Starts the component.void
stop()
Stop the componentService[]
wrappedServices()
Return all the services that are wrapped by this service.-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.adaptris.core.AdaptrisComponent
getUniqueId
-
Methods inherited from interface com.adaptris.core.ComponentLifecycle
close, init
-
Methods inherited from interface com.adaptris.core.MessageEventGenerator
createName, createQualifier, isTrackingEndpoint
-
Methods inherited from interface com.adaptris.core.Service
continueOnFailure, isBranching, setUniqueId
-
Methods inherited from interface com.adaptris.core.StateManagedComponent
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
-
-
-
-
Field Detail
-
DEFAULT_EXCEPTION_MESSAGE_METADATA_KEY
public static final java.lang.String DEFAULT_EXCEPTION_MESSAGE_METADATA_KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
registerEventHandler
public void registerEventHandler(EventHandler eh)
Description copied from interface:EventHandlerAware
Register the current event handler against this component.- Specified by:
registerEventHandler
in interfaceEventHandlerAware
- Parameters:
eh
- the event handler currently in use.
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:Service
Apply the service to the message.
- Specified by:
doService
in interfaceService
- Parameters:
msg
- theAdaptrisMessage
to process- Throws:
ServiceException
- wrapping any underlyingException
s- See Also:
Service.doService(com.adaptris.core.AdaptrisMessage)
-
initService
protected void initService() throws CoreException
- Specified by:
initService
in classServiceImp
- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeService
in classServiceImp
-
start
public void start() throws CoreException
Description copied from interface:ComponentLifecycle
Starts the component.Once a component is started it should be ready to process messages. In the case of
AdaptrisMessageConsumer
, calling start will begin message delivery.- Specified by:
start
in interfaceComponentLifecycle
- Overrides:
start
in classServiceImp
- Throws:
CoreException
- wrapping any underlyingException
s
-
stop
public void stop()
Description copied from interface:ComponentLifecycle
Stop the componentA stopped component is not expected to be ready to process messages. In the case of
AdaptrisMessageConsumer
, calling stop will pause message delivery. Throwing aRuntimeException
may cause unintended consequences- Specified by:
stop
in interfaceComponentLifecycle
- Overrides:
stop
in classServiceImp
- See Also:
ServiceImp.stop()
-
getService
public Service getService()
Returns the Service to wrap.- Returns:
- the Service to wrap
-
setService
public void setService(Service s)
Sets the Service to wrap.- Parameters:
s
- the Service to wrap
-
getExceptionHandlingService
public Service getExceptionHandlingService()
Returns the Service to call if an exception is encountered calling the wrapped Service.- Returns:
- the Service to call if an exception is encountered calling the wrapped Service
-
setExceptionHandlingService
public void setExceptionHandlingService(Service s)
Sets the Service to call if an exception is encountered calling the wrapped Service.- Parameters:
s
- the Service to call if an exception is encountered calling the wrapped Service
-
getExceptionMessageMetadataKey
public java.lang.String getExceptionMessageMetadataKey()
Returns the metadata key to store the exception message against. Default isadp.exception.wrapper.message
.- Returns:
- the metadata key to store the exception message against
-
setExceptionMessageMetadataKey
public void setExceptionMessageMetadataKey(java.lang.String s)
Sets the metadata key to store the exception message against.- Parameters:
s
- the metadata key to store the exception message against
-
prepare
public void prepare() throws CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Specified by:
prepare
in interfaceComponentLifecycleExtension
- Throws:
CoreException
-
wrappedServices
public Service[] wrappedServices()
Description copied from interface:ServiceWrapper
Return all the services that are wrapped by this service.- Specified by:
wrappedServices
in interfaceServiceWrapper
- Returns:
- an array of wrapped services.
-
-