Interface ConnectorRequestInterceptor

  • All Known Implementing Classes:
    DebugRequestInterceptor

    public interface ConnectorRequestInterceptor

    A request interceptor. An interceptor allows intercepting the request created by a connector. See handleInvocation(ConnectorInvocation) for more details and usage patters.

    The interceptor is invoked for every request created by a connector. As such, an interceptor implementation must be thread-safe.

    Author:
    Daniel Meyer
    • Method Detail

      • handleInvocation

        java.lang.Object handleInvocation​(ConnectorInvocation invocation)
                                   throws java.lang.Exception

        Intercept and handle the actual invocation. An implementation of this method *must* call invocation.proceed(); and return the result:

          public Object handleInvocation(ConnectorInvocation invocation) throws Exception {
            // do something before the request
            try {
              Object result = invocation.proceed();
              // do something after a successful request
              return result;
            } catch(Exception e) {
              // do something after a failed request
              throw e;
            }
          }
         

        This may be useful for "management" use cases such as logging, failure tracking etc... and modifying the Thread context of the request thread (Security Context, Transactions, ...).

        It is also possible for an implementation to access and modify the low level "raw" request object before it is executed by the connector:

          public Object handleInvocation(ConnectorInvocation invocation) throws Exception {
            Object rawRequest = invocation.getTarget();
            // cast rawRequest to the low-level connector implementation object and work with it.
        
            // finally
            return invocation.proceed();
          }
         
        Parameters:
        invocation - the invocation
        Returns:
        the result of the invocation
        Throws:
        java.lang.Exception