org.mycore.frontend.servlets
Class MCRServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.mycore.frontend.servlets.MCRServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig
Direct Known Subclasses:
MCRACLEditorServlet_v2, MCRBroadcastingServlet, MCRCheckBase, MCRCheckClassACLServlet, MCRClassExportServlet, MCRClassificationBrowser, MCRClassificationBrowser2, MCRDerivateLinkServlet, MCREditorServlet, MCRFileNodeServlet, MCRFileViewWorkflowServlet, MCRFSMapperServlet, MCRGoogleSitemapServlet, MCRImageServiceServlet, MCRIndexBrowserServlet, MCRIndexServlet, MCRIViewServlet, MCRLinkServlet, MCRListWorkflowServlet, MCRLoginServlet, MCROAIProvider, MCRObjectServlet, MCRRedundancyMapServlet, MCRRemoteFileServlet, MCRSearchServlet, MCRSessionListingServlet, MCRStartClassEditorServlet, MCRStartEditorServlet, MCRStaticXMLFileServlet, MCRUploadServlet, MCRURNResolver, MCRUserAdminGUICommons, MCRUserAjaxServlet, MCRUserServlet, MCRWCMSServlet, MCRWebCLIServlet, MCRZ3950Servlet, MCRZipFileNodeServlet, MCRZipServlet

public class MCRServlet
extends HttpServlet

This is the superclass of all MyCoRe servlets. It provides helper methods for logging and managing the current session data. Part of the code has been taken from MilessServlet.java written by Frank Lützenkirchen.

Version:
$Revision: 15202 $ $Date: 2008-02-06 17:27:24 +0000 (Mi, 06 Feb 2008) $
Author:
Detlev Degenhardt, Frank Lützenkirchen, Thomas Scheffler (yagee)
See Also:
Serialized Form

Field Summary
static String BASE_URL_ATTRIBUTE
           
protected static Set<String> trustedProxies
          The IP addresses of trusted web proxies
 
Constructor Summary
MCRServlet()
           
 
Method Summary
protected  String buildRedirectURL(String baseURL, Properties parameters)
          This method builds a URL that can be used to redirect the client browser to another page, thereby including http request parameters.
 void doGet(HttpServletRequest req, HttpServletResponse res)
           
protected  void doGet(MCRServletJob job)
           
protected  void doGetPost(MCRServletJob job)
          This method should be overwritten by other servlets.
 void doPost(HttpServletRequest req, HttpServletResponse res)
           
protected  void doPost(MCRServletJob job)
           
protected  void generateActiveLinkErrorpage(HttpServletRequest request, HttpServletResponse response, String msg, MCRActiveLinkException activeLinks)
           
protected  void generateErrorPage(HttpServletRequest request, HttpServletResponse response, int error, String msg, Exception ex, boolean xmlstyle)
           
static String getBaseURL()
          returns the base URL of the mycore system
protected  long getLastModified(HttpServletRequest request)
          allows browser to cache requests.
static MCRLayoutService getLayoutService()
           
static String getProperty(HttpServletRequest request, String name)
           
static String getRemoteAddr(HttpServletRequest req)
          Returns the IP address of the client that made the request.
static String getServletBaseURL()
          returns the servlet base URL of the mycore system
static MCRSession getSession(HttpServletRequest req, String servletName)
           
protected  void handleException(Exception ex)
          Handles an exception by reporting it and its embedded exception
 void init()
           
protected static void initTrustedProxies()
          Builds a list of trusted proxy IPs from MCR.Request.TrustedProxies.
protected  void render(MCRServletJob job, Exception ex)
          2nd phase of doGetPost This method has a seperate transaction and gets the same MCRServletJob from the first phase (think) and any exception that occurs at the first phase.
protected  void reportException(Exception ex)
          Reports an exception to the log
protected  void think(MCRServletJob job)
          1st phase of doGetPost.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, service, 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

BASE_URL_ATTRIBUTE

public static final String BASE_URL_ATTRIBUTE
See Also:
Constant Field Values

trustedProxies

protected static Set<String> trustedProxies
The IP addresses of trusted web proxies

Constructor Detail

MCRServlet

public MCRServlet()
Method Detail

getLayoutService

public static MCRLayoutService getLayoutService()

init

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

getBaseURL

public static String getBaseURL()
returns the base URL of the mycore system


getServletBaseURL

public static String getServletBaseURL()
returns the servlet base URL of the mycore system


doGet

public void doGet(HttpServletRequest req,
                  HttpServletResponse res)
           throws ServletException,
                  IOException
Overrides:
doGet in class HttpServlet
Throws:
ServletException
IOException

doGet

protected void doGet(MCRServletJob job)
              throws Exception
Throws:
Exception

doPost

public void doPost(HttpServletRequest req,
                   HttpServletResponse res)
            throws ServletException,
                   IOException
Overrides:
doPost in class HttpServlet
Throws:
ServletException
IOException

doPost

protected void doPost(MCRServletJob job)
               throws Exception
Throws:
Exception

getSession

public static MCRSession getSession(HttpServletRequest req,
                                    String servletName)

think

protected void think(MCRServletJob job)
              throws Exception
1st phase of doGetPost. This method has a seperate transaction. Per default id does nothing as a fallback to the old behaviour.

Parameters:
job -
Throws:
Exception
See Also:
render(MCRServletJob, Exception)

render

protected void render(MCRServletJob job,
                      Exception ex)
               throws Exception
2nd phase of doGetPost This method has a seperate transaction and gets the same MCRServletJob from the first phase (think) and any exception that occurs at the first phase. By default this method calls doGetPost(MCRServletJob) as a fallback to the old behaviour.

Parameters:
job - same instance as of think(MCRServlet job)
ex - any exception thrown by think(MCRServletJob) or transaction commit
Throws:
Exception - if render could not handle ex to produce a nice user page

doGetPost

protected void doGetPost(MCRServletJob job)
                  throws Exception
This method should be overwritten by other servlets. As a default response we indicate the HTTP 1.1 status code 501 (Not Implemented).

Throws:
Exception

handleException

protected void handleException(Exception ex)
Handles an exception by reporting it and its embedded exception


reportException

protected void reportException(Exception ex)
                        throws Exception
Reports an exception to the log

Throws:
Exception

generateErrorPage

protected void generateErrorPage(HttpServletRequest request,
                                 HttpServletResponse response,
                                 int error,
                                 String msg,
                                 Exception ex,
                                 boolean xmlstyle)
                          throws IOException
Throws:
IOException

buildRedirectURL

protected String buildRedirectURL(String baseURL,
                                  Properties parameters)
This method builds a URL that can be used to redirect the client browser to another page, thereby including http request parameters. The request parameters will be encoded as http get request.

Parameters:
baseURL - the base url of the target webpage
parameters - the http request parameters

generateActiveLinkErrorpage

protected void generateActiveLinkErrorpage(HttpServletRequest request,
                                           HttpServletResponse response,
                                           String msg,
                                           MCRActiveLinkException activeLinks)
                                    throws IOException
Throws:
IOException

getLastModified

protected long getLastModified(HttpServletRequest request)
allows browser to cache requests. This method is usefull as it allows browsers to cache content that is not changed. Please overwrite this method in every Servlet that depends on "remote" data.

Overrides:
getLastModified in class HttpServlet

getProperty

public static String getProperty(HttpServletRequest request,
                                 String name)

initTrustedProxies

protected static void initTrustedProxies()
Builds a list of trusted proxy IPs from MCR.Request.TrustedProxies. The IP address of the local host is automatically added to this list.


getRemoteAddr

public static String getRemoteAddr(HttpServletRequest req)
Returns the IP address of the client that made the request. When a trusted proxy server was used, e. g. a local Apache mod_proxy in front of Tomcat, the value of the last entry in the HTTP header X_FORWARDED_FOR is returned, otherwise the REMOTE_ADDR is returned. The list of trusted proxy IPs can be configured using the property MCR.Request.TrustedProxies, which is a List of IP addresses separated by blanks and/or comma.