@ComponentProfile(summary="Handle exceptions from one service via a separate service", tag="service,error-handling") public class ExceptionHandlingServiceWrapper extends ServiceImp implements EventHandlerAware, ServiceWrapper
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.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_EXCEPTION_MESSAGE_METADATA_KEY |
log
CONFIRMATION_ID_KEY
Constructor and Description |
---|
ExceptionHandlingServiceWrapper()
Creates a new instance.
|
Modifier and Type | Method and 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 component
|
Service[] |
wrappedServices()
Return all the services that are wrapped by this service.
|
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getLookupName, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setLookupName, setUniqueId
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
continueOnFailure, isBranching, setUniqueId
createName, createQualifier, isTrackingEndpoint
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
getUniqueId
close, init
getLookupName
public static final java.lang.String DEFAULT_EXCEPTION_MESSAGE_METADATA_KEY
public ExceptionHandlingServiceWrapper()
public void registerEventHandler(EventHandler eh)
EventHandlerAware
registerEventHandler
in interface EventHandlerAware
eh
- the event handler currently in use.public void doService(AdaptrisMessage msg) throws ServiceException
Service
Apply the service to the message.
doService
in interface Service
msg
- the AdaptrisMessage
to processServiceException
- wrapping any underlying Exception
sService.doService(com.adaptris.core.AdaptrisMessage)
protected void initService() throws CoreException
initService
in class ServiceImp
CoreException
protected void closeService()
closeService
in class ServiceImp
public void start() throws CoreException
ComponentLifecycle
Once a component is started it should be ready to process messages. In the case of
AdaptrisMessageConsumer
, calling start will begin message delivery.
start
in interface ComponentLifecycle
start
in class ServiceImp
CoreException
- wrapping any underlying Exception
spublic void stop()
ComponentLifecycle
A stopped component is not expected to be ready to process messages. In the case of
AdaptrisMessageConsumer
, calling stop will pause message delivery. Throwing a
RuntimeException
may cause unintended consequences
stop
in interface ComponentLifecycle
stop
in class ServiceImp
ServiceImp.stop()
public Service getService()
public void setService(Service s)
s
- the Service to wrappublic Service getExceptionHandlingService()
public void setExceptionHandlingService(Service s)
s
- the Service to call if an exception is encountered calling the wrapped Servicepublic java.lang.String getExceptionMessageMetadataKey()
adp.exception.wrapper.message
.public void setExceptionMessageMetadataKey(java.lang.String s)
s
- the metadata key to store the exception message againstpublic void prepare() throws CoreException
ComponentLifecycleExtension
prepare
in interface ComponentLifecycleExtension
CoreException
public Service[] wrappedServices()
ServiceWrapper
wrappedServices
in interface ServiceWrapper