Class MCRServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.mycore.frontend.servlets.MCRServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable
Direct Known Subclasses:
MCRActionMappingServlet, MCRBasketServlet, MCRCASServlet, MCRClassificationBrowser2, MCRCompressServlet, MCRContainerLoginFormServlet, MCRContainerLoginServlet, MCRContentServlet, MCRCreateDerivateServlet, MCRCreateObjectServlet, MCRDeleteDerivateServlet, MCRDeleteObjectServlet, MCRDerivateLinkServlet, MCRDerivateServlet, MCRDFGLinkServlet, MCRDisplayHideDerivateServlet, MCRExportServlet, MCRGoogleSitemapServlet, MCRLockServlet, MCRLoginServlet, MCRMailer, MCRMETSServlet, MCROAIDataProvider, MCROAuthServlet, MCRPackerServlet, MCRQLSearchServlet, MCRRoleServlet, MCRShibbolethLoginServlet, MCRSolrProxyServlet, MCRSolrSearchServlet, MCRStaticXMLFileServlet, MCRThumbnailServlet, MCRTileCombineServlet, MCRUpdateDerivateServlet, MCRUpdateObjectServlet, MCRUploadViaFormServlet, MCRUserServlet, MCRXEditorServlet, MCRXSLInfoServlet

public class MCRServlet extends jakarta.servlet.http.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$ $Date$
Author:
Detlev Degenhardt, Frank Lützenkirchen, Thomas Scheffler (yagee)
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    Returns true if this servlet allows Cross-domain requests.
    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.
    static void
    cleanupMCRSession(jakarta.servlet.http.HttpServletRequest req, String servletName)
    Code to cleanup a MyCoRe Session may be reused in ServletFilter, MVC controller, etc.
    void
    doGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res)
     
    protected void
     
    protected void
    This method should be overwritten by other servlets.
    void
    doPost(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res)
     
    protected void
     
    protected String
    getErrorI18N(String prefix, String subIdentifier, Object... args)
    returns a translated error message for the current Servlet.
    protected long
    getLastModified(jakarta.servlet.http.HttpServletRequest request)
    allows browser to cache requests.
     
    static String
    getProperty(jakarta.servlet.http.HttpServletRequest request, String name)
     
    protected URL
    getReferer(jakarta.servlet.http.HttpServletRequest request)
    Returns the referer of the given request.
    static String
    Returns the servlet base URL of the mycore system
    static MCRSession
    getSession(jakarta.servlet.http.HttpServletRequest req)
     
    protected void
    Handles an exception by reporting it and its embedded exception
    void
     
    static void
    initializeMCRSession(jakarta.servlet.http.HttpServletRequest req, String servletName)
    Code to initialize a MyCoRe Session may be reused in ServletFilter, MVC controller, etc.
    protected void
    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
    Reports an exception to the log
    protected void
    1st phase of doGetPost.
    protected void
    toReferrer(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    If a referrer is available this method redirects to the url given by the referrer otherwise method redirects to the application base url.
    protected void
    toReferrer(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String altURL)
    If a referrer is available this method redirects to the url given by the referrer otherwise method redirects to the alternative-url.

    Methods inherited from class jakarta.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPut, doTrace, service, service

    Methods inherited from class jakarta.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 Details

  • Constructor Details

    • MCRServlet

      public MCRServlet()
  • Method Details

    • getLayoutService

      public static MCRLayoutService getLayoutService()
    • init

      public void init() throws jakarta.servlet.ServletException
      Overrides:
      init in class jakarta.servlet.GenericServlet
      Throws:
      jakarta.servlet.ServletException
    • getServletBaseURL

      public static String getServletBaseURL()
      Returns the servlet base URL of the mycore system
    • doGet

      public void doGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws jakarta.servlet.ServletException, IOException
      Overrides:
      doGet in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • doGet

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

      public void doPost(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws jakarta.servlet.ServletException, IOException
      Overrides:
      doPost in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • doPost

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

      public static MCRSession getSession(jakarta.servlet.http.HttpServletRequest req)
    • initializeMCRSession

      public static void initializeMCRSession(jakarta.servlet.http.HttpServletRequest req, String servletName) throws IOException
      Code to initialize a MyCoRe Session may be reused in ServletFilter, MVC controller, etc.
      Parameters:
      req - - the HTTP request
      servletName - - the servletName
      Throws:
      IOException
    • cleanupMCRSession

      public static void cleanupMCRSession(jakarta.servlet.http.HttpServletRequest req, String servletName)
      Code to cleanup a MyCoRe Session may be reused in ServletFilter, MVC controller, etc.
      Parameters:
      req - - the HTTP Request
      servletName - - the Servlet name
    • 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.
      Throws:
      Exception
      See Also:
    • allowCrossDomainRequests

      protected boolean allowCrossDomainRequests()
      Returns true if this servlet allows Cross-domain requests. The default value defined by MCRServlet is false.
    • 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
    • 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
    • getLastModified

      protected long getLastModified(jakarta.servlet.http.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 jakarta.servlet.http.HttpServlet
    • getProperty

      public static String getProperty(jakarta.servlet.http.HttpServletRequest request, String name)
    • getErrorI18N

      protected String getErrorI18N(String prefix, String subIdentifier, Object... args)
      returns a translated error message for the current Servlet. I18N keys are of form {prefix}'.'{SimpleServletClassName}'.'{subIdentifier}
      Parameters:
      prefix - a prefix of the message property like component.base.error
      subIdentifier - last part of I18n key
      args - any arguments that should be passed to MCRTranslation.translate(String, Object...)
    • getReferer

      protected URL getReferer(jakarta.servlet.http.HttpServletRequest request)
      Returns the referer of the given request.
    • toReferrer

      protected void toReferrer(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException
      If a referrer is available this method redirects to the url given by the referrer otherwise method redirects to the application base url.
      Throws:
      IOException
    • toReferrer

      protected void toReferrer(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String altURL) throws IOException
      If a referrer is available this method redirects to the url given by the referrer otherwise method redirects to the alternative-url.
      Throws:
      IOException