org.aselect.system.servlet
Class ASelectHttpServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.aselect.system.servlet.ASelectHttpServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
ASelectServer, AuthSPServlet, DBAuthSP, IPAuthSP, LDAPAuthSP, NullAuthSP, RadiusAuthSP

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

Base servlet for A-Select (core) components.

Description:
This base servlet contains functionality for restartable and initialisable Servlets. In addition it contains some helpfull methods which are shared among different A-Select Servlet components.

Concurrency issues:
You must use the isRestartInProgress() method in your service() (or other request handling methods) to ensure that the servlet is not currently restarting. If it is, then you should halt processing. It is possible to process events during a restart, but it is very dangerous since a restart can potentially change the entire state of your servlet.

Other than that, this class is thread-safe.

Author:
Alfa & Ariss
See Also:
Serialized Form

Constructor Summary
ASelectHttpServlet()
           
 
Method Summary
protected  java.lang.String getModuleName()
          Retrieve the modulename.
protected  java.lang.String getWorkingDir()
          Retrieve the working directory.
protected  java.lang.String handleRestartRequest(javax.servlet.http.HttpServletRequest oRequest, java.lang.String sMySharedSecret, java.io.PrintWriter pwOut, SystemLogger systemLogger)
          Handles the restart request.
 void init(javax.servlet.ServletConfig config)
          Initialises the Servlet.
protected  boolean isReinit()
          Determine whether this is a first-time init or a re-initialization

Description:
This method can be used in your init() method to check whether it is a first-time initialization, or a re-initialization after a restart API call.
protected abstract  boolean isRestartableServlet()
          Determines whether or not a Servlet is restartable.
protected  boolean isRestartInProgress()
          Check if a restart is currently in progress.
protected  boolean restartServlets(SystemLogger logger)
          Restart all restartable servlets within this context.
protected  void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          This method returns a "Server Busy" if restarting is in progress.
 void setDisableCachingHttpHeaders(javax.servlet.http.HttpServletRequest oRequest, javax.servlet.http.HttpServletResponse oResponse)
          Set HTTP headers that disable browser caching.
 void showErrorPage(java.io.PrintWriter pwOut, java.lang.String sTemplate, java.lang.String sError, java.lang.String sErrorMessage)
          Show an HTML error page.
 
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
 

Constructor Detail

ASelectHttpServlet

public ASelectHttpServlet()
Method Detail

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Initialises the Servlet.

Description:
Performs the following steps:

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException
See Also:
Servlet.init(javax.servlet.ServletConfig)

setDisableCachingHttpHeaders

public void setDisableCachingHttpHeaders(javax.servlet.http.HttpServletRequest oRequest,
                                         javax.servlet.http.HttpServletResponse oResponse)
Set HTTP headers that disable browser caching.

Description:
Sets HTTP 1.0 or HTTP 1.1 disable caching headers depending on the request.

Preconditions:
Postconditions:
oResponse contains caching disable headers.

Parameters:
oRequest - The HTTP request.
oResponse - The HTTP response.

showErrorPage

public void showErrorPage(java.io.PrintWriter pwOut,
                          java.lang.String sTemplate,
                          java.lang.String sError,
                          java.lang.String sErrorMessage)
Show an HTML error page.

Description:
The following tags will be replaced in the error template:

Parameters:
pwOut - the PrintWriter that is the target for displaying the html error page.
sTemplate - The base HTML error template.
sError - The error that should be shown in the error page.
sErrorMessage - The error message that should be shown in the error page.

isRestartableServlet

protected abstract boolean isRestartableServlet()
Determines whether or not a Servlet is restartable.

Description:
This method should return true if the Servlet is restartable, false otherwise.

Returns:
true if the Servlet is restartable, otherwise false.

isReinit

protected boolean isReinit()
Determine whether this is a first-time init or a re-initialization

Description:
This method can be used in your init() method to check whether it is a first-time initialization, or a re-initialization after a restart API call.

Returns:
true if this is a re-initialization, false otherwise.

getModuleName

protected java.lang.String getModuleName()
Retrieve the modulename.

Description:
Constructs a module name form the class name. This method strips package prefix and the "Servlet" postfix.

Returns:
The constructed module name.

getWorkingDir

protected java.lang.String getWorkingDir()
Retrieve the working directory.

Description:
Return the working directory which A-Select uses for logging, configuration, and other data storage.

The working dir is read as an Init paramater from the servlets Deployment Descriptor. e.g.:

 
  
   <servlet>
        ...
        <init-param>
                <param-name>working_dir</param-name>
                <param-value>[param value]</param-value>
        </init-param>
        ...
    </servlet>
        
  
 

Preconditions:
The working dir is set in the Servlet its Deployment Descriptor.

Postconditions:
-

Returns:
The working directory.

handleRestartRequest

protected java.lang.String handleRestartRequest(javax.servlet.http.HttpServletRequest oRequest,
                                                java.lang.String sMySharedSecret,
                                                java.io.PrintWriter pwOut,
                                                SystemLogger systemLogger)
Handles the restart request.

Description:
This method should be called if a sub class receives a restart request. This methods calls restartServlets(SystemLogger)which restarts all restartable servlets in the servlet context.

Note: The restart request should be handled by one Servlet in the context.

Concurrency issues:
This method should be called serial.

Preconditions:
Postconditions:
All restartable servlets in the context are restarted.

Parameters:
oRequest - The HTTP request.
sMySharedSecret - The shared secret on which the received Shared_secret is validated upon.
pwOut - The ouput.
systemLogger - The logger for system logging.
Returns:
A-Select result code.

restartServlets

protected boolean restartServlets(SystemLogger logger)
Restart all restartable servlets within this context.

Description:
Restarts all servlets in the Servlet context:
Note: this method logs possible errors.

Preconditions:
-

Postconditions:
All restartable servlets in the context are restarted.

Parameters:
logger - The system logger.
Returns:
false if one or more restart requests fail, otherwise true.

isRestartInProgress

protected boolean isRestartInProgress()
Check if a restart is currently in progress.

Description:
This method reads the servlet configuration attribute "restarting_servlets". If this attribute is true then all restartable servlets within this context are in the process of being restarted.
Concurrency issues:
-
Be careful in handling requests during a restart. A restart may potentially change the entire state of the servlets within the context.

Returns:
true if servlets in the context are restarting, otherwise false.

service

protected void service(javax.servlet.http.HttpServletRequest request,
                       javax.servlet.http.HttpServletResponse response)
                throws javax.servlet.ServletException,
                       java.io.IOException
This method returns a "Server Busy" if restarting is in progress.

Note: If this method is overwritten in a sub class, it should be called explicitly, or you must use the isRestartInProgress() method

Overrides:
service in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException
See Also:
HttpServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)


Copyright © 2008 SURFnet BV. All Rights Reserved.