Interface RequestInterceptor

  • All Superinterfaces:
    OrderedService
    All Known Implementing Classes:
    RequestInterceptorExample, SystemEventService.EventRequestInterceptor

    public interface RequestInterceptor
    extends OrderedService
    Executes at the beginning and/or end of system requests.

    Note that the ordering of these must be set specifically higher than 0 or an exception will occur. If you do not really care what the order is you are encouraged to use 10.

    Note that the highest priority interceptor will be executed first in request start and last on request end. The lowest priority interceptor would be executed last on request start and first on request end. If you need an interceptor which can execute first on request start and first on request end (or vice versa) then create 2 interceptors. :-)

    Author:
    Aaron Zeckoski (azeckoski @ gmail.com)
    • Method Detail

      • onStart

        void onStart​(String requestId)
        Take actions before the request is handled for an operation. This will be called just before each request is sent to the correct request handler. For example: starting a transaction would happen at this point.

        If you want to interrupt the handling of this request (stop it) then throw a RequestInterceptor.RequestInterruptionException.

        Parameters:
        requestId - the unique id of the request
        Throws:
        RequestInterceptor.RequestInterruptionException - if this interceptor wants to stop the request
      • onEnd

        void onEnd​(String requestId,
                   boolean succeeded,
                   Exception failure)
        Take actions after the request is handled for an operation. This will be called just before each operation is totally completed. For example: closing a transaction would happen at this point.

        If you want to interrupt the handling of this request (stop it) then throw a RequestInterceptor.RequestInterruptionException.

        NOTE: it is important to realize that this will be called even if the request fails. Please check the incoming success param to see if this request was successful or not. This is your cue to rollback or commit, for example.

        Parameters:
        requestId - the unique id of the request
        succeeded - true if the request operations were successful, false if there was a failure
        failure - this is the exception associated with the failure, it is null if there is no associated exception