Class RequestHandler<C>

  • Type Parameters:
    C - request component type
    Direct Known Subclasses:
    BackendRequestHandler, FrontendRequestHandler, PubApiRequestHandler, ToolsRequestHandler

    public class RequestHandler<C>
    extends java.lang.Object
    Dagger-based request processor.

    This class creates an HTTP request processor from a Dagger component. It routes requests from your servlet to an @Action annotated handler class.

    Component Definition

    Action instances are supplied on a per-request basis by invoking the methods on C. For example:

     @Component
     interface ServerComponent {
       HelloAction helloAction();
     }

    The rules for component methods are as follows:

    1. Methods whose raw return type does not implement Runnable will be ignored
    2. Methods whose raw return type does not have an @Action annotation are ignored

    Security Features

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected RequestHandler​(javax.inject.Provider<? extends RequestComponentBuilder<C>> requestComponentBuilderProvider, RequestAuthenticator requestAuthenticator)
      Constructor for subclasses to create a new request handler for a specific request component.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <C> RequestHandler<C> createForTest​(java.lang.Class<C> component, javax.inject.Provider<? extends RequestComponentBuilder<C>> requestComponentBuilderProvider, RequestAuthenticator requestAuthenticator)
      Creates a new RequestHandler with an explicit component class for test purposes.
      void handleRequest​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp)
      Runs the appropriate action for a servlet request.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RequestHandler

        protected RequestHandler​(javax.inject.Provider<? extends RequestComponentBuilder<C>> requestComponentBuilderProvider,
                                 RequestAuthenticator requestAuthenticator)
        Constructor for subclasses to create a new request handler for a specific request component.

        This operation will generate a routing map for the component's @Action-returning methods using reflection, which is moderately expensive, so a given servlet should construct a single RequestHandler and re-use it across requests.

        Parameters:
        requestComponentBuilderProvider - a Dagger Provider of builder instances that can be used to construct new instances of the request component (with the required request-derived modules provided by this class)
        requestAuthenticator - an instance of the RequestAuthenticator class
    • Method Detail

      • createForTest

        public static <C> RequestHandler<C> createForTest​(java.lang.Class<C> component,
                                                          javax.inject.Provider<? extends RequestComponentBuilder<C>> requestComponentBuilderProvider,
                                                          RequestAuthenticator requestAuthenticator)
        Creates a new RequestHandler with an explicit component class for test purposes.
      • handleRequest

        public void handleRequest​(javax.servlet.http.HttpServletRequest req,
                                  javax.servlet.http.HttpServletResponse rsp)
                           throws java.io.IOException
        Runs the appropriate action for a servlet request.
        Throws:
        java.io.IOException