Class DebugRequestInterceptor

  • All Implemented Interfaces:
    ConnectorRequestInterceptor

    public class DebugRequestInterceptor
    extends java.lang.Object
    implements ConnectorRequestInterceptor

    A dummy debug connector, which saves the ConnectorRequest (getRequest()) and the raw request (getTarget()) for debugging purpose.

    The boolean constructor flag determines whether the request invocation should be continued or aborted after this interceptor. Also it is possible to add a response object which will returned without further passing the interceptor chain;

    Author:
    Sebastian Menski
    • Field Detail

      • response

        protected java.lang.Object response
      • proceed

        protected boolean proceed
    • Constructor Detail

      • DebugRequestInterceptor

        public DebugRequestInterceptor()
      • DebugRequestInterceptor

        public DebugRequestInterceptor​(boolean proceed)
      • DebugRequestInterceptor

        public DebugRequestInterceptor​(java.lang.Object response)
    • Method Detail

      • handleInvocation

        public java.lang.Object handleInvocation​(ConnectorInvocation invocation)
                                          throws java.lang.Exception
        Description copied from interface: ConnectorRequestInterceptor

        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();
          }
         
        Specified by:
        handleInvocation in interface ConnectorRequestInterceptor
        Parameters:
        invocation - the invocation
        Returns:
        the result of the invocation
        Throws:
        java.lang.Exception
      • setProceed

        public void setProceed​(boolean proceed)
      • isProceed

        public boolean isProceed()
      • setResponse

        public void setResponse​(java.lang.Object response)
      • getResponse

        public <T> T getResponse()
      • getTarget

        public <T> T getTarget()