Class CmsFlexRequestDispatcher

java.lang.Object
org.opencms.flex.CmsFlexRequestDispatcher
All Implemented Interfaces:
javax.servlet.RequestDispatcher

public class CmsFlexRequestDispatcher extends Object implements javax.servlet.RequestDispatcher
Implementation of the RequestDispatcher interface to allow JSPs to be loaded from the OpenCms VFS.

This dispatcher will load data from 3 different data sources:

  1. Form the "real" os File system (e.g. for JSP pages)
  2. From the OpenCms VFS
  3. From the Flex cache

Since:
6.0.0
  • Field Summary

    Fields inherited from interface javax.servlet.RequestDispatcher

    ERROR_EXCEPTION, ERROR_EXCEPTION_TYPE, ERROR_MESSAGE, ERROR_REQUEST_URI, ERROR_SERVLET_NAME, ERROR_STATUS_CODE, FORWARD_CONTEXT_PATH, FORWARD_PATH_INFO, FORWARD_QUERY_STRING, FORWARD_REQUEST_URI, FORWARD_SERVLET_PATH, INCLUDE_CONTEXT_PATH, INCLUDE_PATH_INFO, INCLUDE_QUERY_STRING, INCLUDE_REQUEST_URI, INCLUDE_SERVLET_PATH
  • Constructor Summary

    Constructors
    Constructor
    Description
    CmsFlexRequestDispatcher(javax.servlet.RequestDispatcher rd, String vfs_target, String ext_target)
    Creates a new instance of CmsFlexRequestDispatcher.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    forward(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res)
    Wrapper for the standard servlet API call.
    void
    include(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res)
    Wrapper for dispatching to a file from the OpenCms VFS.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CmsFlexRequestDispatcher

      public CmsFlexRequestDispatcher(javax.servlet.RequestDispatcher rd, String vfs_target, String ext_target)
      Creates a new instance of CmsFlexRequestDispatcher.

      Parameters:
      rd - the "real" dispatcher, used for include call to file system
      vfs_target - the cms resource that represents the external target
      ext_target - the external target that the request will be dispatched to
  • Method Details

    • forward

      public void forward(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res) throws javax.servlet.ServletException, IOException
      Wrapper for the standard servlet API call.

      Forward calls are actually NOT wrapped by OpenCms as of now. So they should not be used in JSP pages or servlets.

      Specified by:
      forward in interface javax.servlet.RequestDispatcher
      Parameters:
      req - the servlet request
      res - the servlet response
      Throws:
      javax.servlet.ServletException - in case something goes wrong
      IOException - in case something goes wrong
      See Also:
      • RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
    • include

      public void include(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res) throws javax.servlet.ServletException, IOException
      Wrapper for dispatching to a file from the OpenCms VFS.

      This method will dispatch to cache, to real file system or to the OpenCms VFS, whatever is needed.

      This method is much more complex than it should be because of the internal standard buffering of JSP pages. Because of that I can not just intercept and buffer the stream, since I don't have access to it (it is wrapped internally in the JSP pages, which have their own buffer). That leads to a solution where the data is first written to the buffered stream, but without includes. Then it is parsed again later in the CmsFlexResponse, enriched with the included elements that have been omitted in the first case. I would love to see a simpler solution, but this works for now.

      Specified by:
      include in interface javax.servlet.RequestDispatcher
      Parameters:
      req - the servlet request
      res - the servlet response
      Throws:
      javax.servlet.ServletException - in case something goes wrong
      IOException - in case something goes wrong