Class DirectServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.sakaiproject.entitybroker.util.servlet.DirectServlet
-
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
public abstract class DirectServlet extends javax.servlet.http.HttpServletThis 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
Fields Modifier and Type Field Description protected org.sakaiproject.entitybroker.providers.EntityRequestHandlerentityRequestHandler
-
Constructor Summary
Constructors Constructor Description DirectServlet()Default constructorDirectServlet(org.sakaiproject.entitybroker.providers.EntityRequestHandler entityRequestHandler)Allow the request handler to be set on this servlet, probably best to only use this for testing
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voiddispatch(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)handle all communication from the user not related to loginprotected abstract StringgetCurrentLoggedInUserId()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 nullprotected voidhandleRequest(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 itprotected abstract voidhandleUserLogin(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 authenticatevoidinit()protected voidinitialize()Initializes the servlet, executed automatically by the servlet container
This basically just calls theinitializeEntityRequestHandler()method and throws exceptions if something is missingprotected abstract org.sakaiproject.entitybroker.providers.EntityRequestHandlerinitializeEntityRequestHandler()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 testingprotected voidsendError(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 wayprotected voidservice(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)voidsetEntityRequestHandler(org.sakaiproject.entitybroker.providers.EntityRequestHandler entityRequestHandler)-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
-
-
-
-
Constructor Detail
-
DirectServlet
public DirectServlet()
Default constructor
-
DirectServlet
public DirectServlet(org.sakaiproject.entitybroker.providers.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(org.sakaiproject.entitybroker.providers.EntityRequestHandler entityRequestHandler)
-
initializeEntityRequestHandler
protected abstract org.sakaiproject.entitybroker.providers.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:
initin classjavax.servlet.GenericServlet- Throws:
javax.servlet.ServletException
-
initialize
protected void initialize()
Initializes the servlet, executed automatically by the servlet container
This basically just calls theinitializeEntityRequestHandler()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:
servicein classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
handleRequest
protected void handleRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletException, IOExceptionHandle 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.ServletExceptionIOException
-
dispatch
public void dispatch(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletExceptionhandle 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 codemessage- extra info about the error
-
-