Class DirectServlet

  • All Implemented Interfaces:
    Serializable, Servlet, ServletConfig

    public abstract class DirectServlet
    extends HttpServlet
    This is the core abstract DirectServlet class which is meant to extended, extend this to plugin whatever system you have for initiating/retrieving the EB services and for handling logins

    Direct servlet allows unfettered access to entity URLs within the EB system, it also can handle authentication (login) if required (without breaking an entity URL)
    Author:
    Aaron Zeckoski (aaron@caret.cam.ac.uk)
    See Also:
    Serialized Form
    • Constructor Detail

      • DirectServlet

        public DirectServlet()
        Default constructor
      • DirectServlet

        public DirectServlet​(EntityRequestHandler entityRequestHandler)
        Allow the request handler to be set on this servlet, probably best to only use this for testing
        Parameters:
        entityRequestHandler - the entity request handler service object
    • Method Detail

      • setEntityRequestHandler

        public void setEntityRequestHandler​(EntityRequestHandler entityRequestHandler)
      • initializeEntityRequestHandler

        protected abstract EntityRequestHandler initializeEntityRequestHandler()
        This runs on servlet initialization (it is the first thing to run) This must be implemented to provide the entity request handler itself
        This needs to at least load up the entityRequestHandler service (from the entity broker core) in order for things to work, if that service is not loaded then nothing will work, this can be done using a service manager of some kind or by loading it up manually, the default is to create and load it manually by calling this method with the service
        Can also call the servlet constructor to set this value but that is really for testing
        Returns:
        the entity request handler service object
      • getCurrentLoggedInUserId

        protected abstract String getCurrentLoggedInUserId()
        This should return the userId for the currently logged in user if there is one, if not user is logged in then this should return null
        Returns:
        the user identifier for the currently logged in user
      • handleUserLogin

        protected abstract void handleUserLogin​(HttpServletRequest req,
                                                HttpServletResponse res,
                                                String path)
        Handle the user authentication (login) in a system specific way, by default this will simply fail as entity-broker has no way to authenticate
        Parameters:
        req - the http request (from the client)
        res - the http response (back to the client)
        path - current request path, set ONLY if we want this to be where to redirect the user after a successful login
      • initialize

        protected void initialize()
        Initializes the servlet, executed automatically by the servlet container
        This basically just calls the initializeEntityRequestHandler() method and throws exceptions if something is missing
      • sendError

        protected void sendError​(HttpServletResponse res,
                                 int code,
                                 String message)
        handles sending back servlet errors to the client, feel free to override this if you like to handle errors in a particular way
        Parameters:
        res - the http servlet response (back to the client)
        code - servlet error response code
        message - extra info about the error