org.sakaiproject.entitybroker.util.servlet
Class DirectServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.sakaiproject.entitybroker.util.servlet.DirectServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public abstract class DirectServlet
extends javax.servlet.http.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

Field Summary
protected  EntityRequestHandler entityRequestHandler
           
 
Constructor Summary
DirectServlet()
          Default constructor
DirectServlet(EntityRequestHandler entityRequestHandler)
          Allow the request handler to be set on this servlet, probably best to only use this for testing
 
Method Summary
 void dispatch(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          handle all communication from the user not related to login
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
protected  void handleRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Handle the incoming request (get and post handled in the same way), passes control to the dispatch method or calls the login helper, override this to control it
protected abstract  void handleUserLogin(javax.servlet.http.HttpServletRequest req, javax.servlet.http.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
 void init()
           
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
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
protected  void sendError(javax.servlet.http.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
protected  void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
 void setEntityRequestHandler(EntityRequestHandler entityRequestHandler)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entityRequestHandler

protected transient EntityRequestHandler entityRequestHandler
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(javax.servlet.http.HttpServletRequest req,
                                        javax.servlet.http.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

init

public void init()
          throws javax.servlet.ServletException
Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

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


service

protected void service(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse res)
                throws javax.servlet.ServletException,
                       IOException
Overrides:
service in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

handleRequest

protected void handleRequest(javax.servlet.http.HttpServletRequest req,
                             javax.servlet.http.HttpServletResponse res)
                      throws javax.servlet.ServletException,
                             IOException
Handle the incoming request (get and post handled in the same way), passes control to the dispatch method or calls the login helper, override this to control it

Parameters:
req - (from the client)
res - (back to the client)
Throws:
javax.servlet.ServletException
IOException

dispatch

public void dispatch(javax.servlet.http.HttpServletRequest req,
                     javax.servlet.http.HttpServletResponse res)
              throws javax.servlet.ServletException
handle all communication from the user not related to login

Parameters:
req - (from the client)
res - (back to the client)
Throws:
javax.servlet.ServletException

sendError

protected void sendError(javax.servlet.http.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


Copyright © 2007-2013 CARET, University of Cambridge. All Rights Reserved.