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, ServiceWrapperWraps 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
StandardProcessingExceptionHandlerat the workflow level.StandardProcessingExceptionHandlerallows 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.StringDEFAULT_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 voidcloseService()voiddoService(AdaptrisMessage msg)Apply the service to the message.ServicegetExceptionHandlingService()Returns the Service to call if an exception is encountered calling the wrapped Service.java.lang.StringgetExceptionMessageMetadataKey()Returns the metadata key to store the exception message against.ServicegetService()Returns the Service to wrap.protected voidinitService()voidprepare()Prepare for initialisation.voidregisterEventHandler(EventHandler eh)Register the current event handler against this component.voidsetExceptionHandlingService(Service s)Sets the Service to call if an exception is encountered calling the wrapped Service.voidsetExceptionMessageMetadataKey(java.lang.String s)Sets the metadata key to store the exception message against.voidsetService(Service s)Sets the Service to wrap.voidstart()Starts the component.voidstop()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:EventHandlerAwareRegister the current event handler against this component.- Specified by:
registerEventHandlerin interfaceEventHandlerAware- Parameters:
eh- the event handler currently in use.
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:ServiceApply the service to the message.
- Specified by:
doServicein interfaceService- Parameters:
msg- theAdaptrisMessageto process- Throws:
ServiceException- wrapping any underlyingExceptions- See Also:
Service.doService(com.adaptris.core.AdaptrisMessage)
-
initService
protected void initService() throws CoreException- Specified by:
initServicein classServiceImp- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeServicein classServiceImp
-
start
public void start() throws CoreExceptionDescription copied from interface:ComponentLifecycleStarts 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:
startin interfaceComponentLifecycle- Overrides:
startin classServiceImp- Throws:
CoreException- wrapping any underlyingExceptions
-
stop
public void stop()
Description copied from interface:ComponentLifecycleStop 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 aRuntimeExceptionmay cause unintended consequences- Specified by:
stopin interfaceComponentLifecycle- Overrides:
stopin 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 CoreExceptionDescription copied from interface:ComponentLifecycleExtensionPrepare for initialisation.- Specified by:
preparein interfaceComponentLifecycleExtension- Throws:
CoreException
-
wrappedServices
public Service[] wrappedServices()
Description copied from interface:ServiceWrapperReturn all the services that are wrapped by this service.- Specified by:
wrappedServicesin interfaceServiceWrapper- Returns:
- an array of wrapped services.
-
-