Class 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 Detail

      • DEFAULT_EXCEPTION_MESSAGE_METADATA_KEY

        public static final java.lang.String DEFAULT_EXCEPTION_MESSAGE_METADATA_KEY
        See Also:
        Constant Field Values
    • Constructor Detail

      • ExceptionHandlingServiceWrapper

        public ExceptionHandlingServiceWrapper()
        Creates a new instance.
    • Method Detail

      • 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 is adp.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
      • wrappedServices

        public Service[] wrappedServices()
        Description copied from interface: ServiceWrapper
        Return all the services that are wrapped by this service.
        Specified by:
        wrappedServices in interface ServiceWrapper
        Returns:
        an array of wrapped services.