org.universAAL.ri.servicegateway
Class GatewayPort

Package class diagram package GatewayPort
java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.universAAL.ri.servicegateway.GatewayPort
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
HTTPHandlerService

public abstract class GatewayPort
extends javax.servlet.http.HttpServlet

Base class for HTTP servlets. To create a servlet, create a subclass and overwrite one of the methods HttpServlet.doGet(HttpServletRequest, HttpServletResponse) or HttpServlet.doPost(HttpServletRequest, HttpServletResponse). Then set the module context and call register(). When done, call unregister().

Author:
, Carsten Stockloew
See Also:
Serialized Form

Field Summary
protected  Hashtable<String,User> loggedUsers
          Table that Associates usernames with Users.
static String REALM
           
 
Constructor Summary
GatewayPort()
          Simply initialize the logger and the user table for the security
GatewayPort(ModuleContext mcontext)
           
 
Method Summary
abstract  String dataDir()
          The symbolic data directory where all the resources reside.
 ModuleContext getContext()
           
 String[] getUserAndPass(String auth)
           
 boolean handleAuthorization(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Handle the login phase
 void logout(User usr)
           
 boolean register()
           
protected  void requireCredentials(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Set the HTTP Basic Authentication response with the realm.
 void setContext(ModuleContext mcontext)
           
 boolean unregister()
           
abstract  String url()
          The URL where the servlet is registered and accessed by the web client.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loggedUsers

protected Hashtable<String,User> loggedUsers
Table that Associates usernames with Users.


REALM

public static final String REALM
See Also:
Constant Field Values
Constructor Detail

GatewayPort

public GatewayPort()
Simply initialize the logger and the user table for the security


GatewayPort

public GatewayPort(ModuleContext mcontext)
Method Detail

requireCredentials

protected void requireCredentials(javax.servlet.http.HttpServletRequest req,
                                  javax.servlet.http.HttpServletResponse resp)
Set the HTTP Basic Authentication response with the realm.

Parameters:
req - The request from goGet method
resp - The response from doGet method, used to set the header to WWW-Authenticate and the status to 401

getUserAndPass

public String[] getUserAndPass(String auth)
Parameters:
auth - The BASE64 encoded user:pass values. If null or empty, returns false
Returns:
A String array of two elements containing the user and pass as first and second element

handleAuthorization

public boolean handleAuthorization(javax.servlet.http.HttpServletRequest req,
                                   javax.servlet.http.HttpServletResponse resp)
Handle the login phase

Parameters:
req - The request from goGet method, used to retrieve the "Authorization" header
resp - The response from doGet method, used to redirect to the correct url()

logout

public void logout(User usr)

setContext

public void setContext(ModuleContext mcontext)

getContext

public ModuleContext getContext()

url

public abstract String url()
The URL where the servlet is registered and accessed by the web client.

Returns:
A string starting with "/" to access the service. For example "/myservlet"

dataDir

public abstract String dataDir()
The symbolic data directory where all the resources reside. Each image, html, javascript used in html, javascript must use the symbolic name returned by this method. The bundle containing the servlet must also have the resources in the same symbolic name. For example, if this method returns /myservicedir, an html code that uses a script tag will be :

<script type="text/javascript" src="/myservicedir/script.js">

Returns:
The string representing the symbolic datadir, null if no data directory is needed

register

public boolean register()

unregister

public boolean unregister()


Copyright © 2014 universAAL Consortium. All Rights Reserved.