Interface RequestService

  • All Known Implementing Classes:
    StatelessRequestServiceImpl

    public interface RequestService
    Allows for the managing of requests in the system in a way which is independent of any underlying system or code.
    Author:
    Aaron Zeckoski (azeckoski @ gmail.com)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String AUTHENTICATED_EPERSON
      Request attribute name for the current authenticated user
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      String endRequest​(Exception failure)
      Ends the current running request, this can indicate success or failure of the request, this will trigger the interceptors and normally would be caused by a servlet request ending, note that a request cannot be ended twice, once it is ended this will just return null
      Request getCurrentRequest()
      Finds out of there is a request running in this thread and if so returns it
      String getCurrentRequestId()
      Finds out of there is a request running in this thread and if so what the id of that request is.
      String getCurrentUserId()
      Access the current user id for the current session.
      void registerRequestInterceptor​(RequestInterceptor interceptor)
      Allows developers to perform actions on the start and end of the request cycle, if you decide you do not need to use your interceptor anymore then simply destroy it (dereference it) and the service will stop calling it, along those lines you should not register an interceptor that you do not keep a reference to (like an inline class or registerRequestListener(new YourInterceptor())) as this will be destroyed immediately, this registration is ClassLoader safe
      void setCurrentUserId​(UUID epersonId)
      Set the ID of the current authenticated user
      String startRequest()
      Initiates a request in the system.
      String startRequest​(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
      Initiates a request in the system, normally this would be triggered by a servlet request starting
      Only one request can be associated with the current thread so if another one is running it will be destroyed and a new one will be created
      Note that requests are expected to be manually ended somehow and will not be closed out automatically
    • Field Detail

      • AUTHENTICATED_EPERSON

        static final String AUTHENTICATED_EPERSON
        Request attribute name for the current authenticated user
        See Also:
        Constant Field Values
    • Method Detail

      • startRequest

        String startRequest()
        Initiates a request in the system. Normally this would be triggered by a servlet request starting.

        Only one request can be associated with the current thread, so if another one is running it will be destroyed and a new one will be created.

        Note that requests are expected to be manually ended somehow and will not be closed out automatically.

        Returns:
        the unique generated id for the new request
        Throws:
        IllegalArgumentException - if the session is null, invalid, or there is no current session
      • startRequest

        String startRequest​(javax.servlet.ServletRequest request,
                            javax.servlet.ServletResponse response)
        Initiates a request in the system, normally this would be triggered by a servlet request starting
        Only one request can be associated with the current thread so if another one is running it will be destroyed and a new one will be created
        Note that requests are expected to be manually ended somehow and will not be closed out automatically
        Parameters:
        request - servlet request
        response - servlet response
        Returns:
        the unique generated id for the new request
        Throws:
        IllegalArgumentException - if the session is null, invalid, or there is no current session
      • endRequest

        String endRequest​(Exception failure)
        Ends the current running request, this can indicate success or failure of the request, this will trigger the interceptors and normally would be caused by a servlet request ending, note that a request cannot be ended twice, once it is ended this will just return null
        Parameters:
        failure - (optional) this is the exception associated with the failure. Leave as null if the request is ending successfully. You can make up a RuntimeException if you just need to indicate that the request failed.
        Returns:
        the request ID if the request closes successfully and is not already closed OR null if there is no current request.
      • getCurrentRequestId

        String getCurrentRequestId()
        Finds out of there is a request running in this thread and if so what the id of that request is.
        Returns:
        the id of the current request for this thread OR null if there is not one
      • getCurrentRequest

        Request getCurrentRequest()
        Finds out of there is a request running in this thread and if so returns it
        Returns:
        the current request for this thread OR null if there is not one
      • registerRequestInterceptor

        void registerRequestInterceptor​(RequestInterceptor interceptor)
        Allows developers to perform actions on the start and end of the request cycle, if you decide you do not need to use your interceptor anymore then simply destroy it (dereference it) and the service will stop calling it, along those lines you should not register an interceptor that you do not keep a reference to (like an inline class or registerRequestListener(new YourInterceptor())) as this will be destroyed immediately, this registration is ClassLoader safe
        Parameters:
        interceptor - an implementation of RequestInterceptor
        Throws:
        IllegalArgumentException - if this priority is invalid or the input is null
      • getCurrentUserId

        String getCurrentUserId()
        Access the current user id for the current session. (also available from the current session)
        Returns:
        the id of the user associated with the current thread OR null if there is no user
      • setCurrentUserId

        void setCurrentUserId​(UUID epersonId)
        Set the ID of the current authenticated user