Class OpenCmsServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.opencms.main.OpenCmsServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig, I_CmsRequestHandler
Direct Known Subclasses:
OpenCmsServletErrorHandler

public class OpenCmsServlet extends javax.servlet.http.HttpServlet implements I_CmsRequestHandler
This the main servlet of the OpenCms system.

From here, all operations that are results of HTTP requests are invoked. Any incoming request is handled in multiple steps:

  1. The requesting CmsUser is authenticated and a CmsObject with this users context information is created. This CmsObject is used to access all functions of OpenCms, limited by the authenticated users permissions. If the user is not identified, it is set to the default user, usually named "Guest".
  2. The requested CmsResource is loaded into OpenCms and depending on its type (and the users persmissions to display or modify it), it is send to one of the OpenCms I_CmsResourceLoader implementations do be processed.
  3. The I_CmsResourceLoader will then decide what to do with the contents of the requested CmsResource. In case of a JSP resource the JSP handling mechanism is invoked with the CmsJspLoader, in case of an image (or another static resource) this will be returned by the CmsDumpLoader etc.
Since:
6.0.0
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getRequestCache

      Gets a thread-local, request-specific context object for requests made to the OpenCms servlet.
      Returns:
      the thread context
    • withRequestCache

      public static void withRequestCache(Consumer<OpenCmsServlet.RequestCache> handler)
      Helper method used to conveniently access the request cache, does nothing if the request cache isn't set.
      Parameters:
      handler - the handler to pass the request cache to
    • doGet

      public void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws IOException, javax.servlet.ServletException
      OpenCms servlet main request handling method.

      Overrides:
      doGet in class javax.servlet.http.HttpServlet
      Throws:
      IOException
      javax.servlet.ServletException
      See Also:
      • HttpServlet.doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    • doPost

      public void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws IOException, javax.servlet.ServletException
      OpenCms servlet POST request handling method, will just call doGet(HttpServletRequest, HttpServletResponse).

      Overrides:
      doPost in class javax.servlet.http.HttpServlet
      Throws:
      IOException
      javax.servlet.ServletException
      See Also:
      • HttpServlet.doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    • getHandlerNames

      public String[] getHandlerNames()
      Description copied from interface: I_CmsRequestHandler
      Returns the handler name.

      Specified by:
      getHandlerNames in interface I_CmsRequestHandler
      Returns:
      the handler name
      See Also:
    • handle

      public void handle(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String name) throws IOException, javax.servlet.ServletException
      Description copied from interface: I_CmsRequestHandler
      Handles an OpenCms request.

      Specified by:
      handle in interface I_CmsRequestHandler
      Parameters:
      req - the current request
      res - the current response
      name - the handler name to invoke
      Throws:
      IOException - in case an error occurs
      javax.servlet.ServletException - in case an error occurs
      See Also:
    • init

      public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException
      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)
    • invokeHandler

      protected void invokeHandler(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws IOException, javax.servlet.ServletException
      Manages requests to internal OpenCms request handlers.

      Parameters:
      req - the current request
      res - the current response
      Throws:
      javax.servlet.ServletException - in case an error occurs
      javax.servlet.ServletException - in case an error occurs
      IOException - in case an error occurs
    • openErrorHandler

      protected void openErrorHandler(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int errorCode) throws IOException, javax.servlet.ServletException
      Displays an error code handler loaded from the OpenCms VFS, or if such a page does not exist, displays the default servlet container error code.

      Parameters:
      req - the current request
      res - the current response
      errorCode - the error code to display
      Throws:
      IOException - if something goes wrong
      javax.servlet.ServletException - if something goes wrong