Class ExceptionHandlingServiceWrapper

java.lang.Object
com.adaptris.core.ServiceImp
com.adaptris.core.services.exception.ExceptionHandlingServiceWrapper
All Implemented Interfaces:
AdaptrisComponent, ComponentLifecycle, ComponentLifecycleExtension, ConfigComment, 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 Details

    • DEFAULT_EXCEPTION_MESSAGE_METADATA_KEY

      public static final String DEFAULT_EXCEPTION_MESSAGE_METADATA_KEY
      See Also:
  • Constructor Details

    • ExceptionHandlingServiceWrapper

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

    • registerEventHandler

      public void registerEventHandler(EventHandler eh)
      Description copied from interface: EventHandlerAware
      Register the current event handler against this component.
      Specified by:
      registerEventHandler in interface EventHandlerAware
      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 interface Service
      Parameters:
      msg - the AdaptrisMessage to process
      Throws:
      ServiceException - wrapping any underlying Exceptions
      See Also:
    • initService

      protected void initService() throws CoreException
      Specified by:
      initService in class ServiceImp
      Throws:
      CoreException
    • closeService

      protected void closeService()
      Specified by:
      closeService in class ServiceImp
    • 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 interface ComponentLifecycle
      Overrides:
      start in class ServiceImp
      Throws:
      CoreException - wrapping any underlying Exceptions
    • stop

      public void stop()
      Description copied from interface: ComponentLifecycle
      Stop the component

      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

      Specified by:
      stop in interface ComponentLifecycle
      Overrides:
      stop in class ServiceImp
      See Also:
    • 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 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(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 interface ComponentLifecycleExtension
      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 interface ServiceWrapper
      Returns:
      an array of wrapped services.