Class DHtmlUpdateServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.zkoss.zk.au.http.DHtmlUpdateServlet
All Implemented Interfaces:
Serializable, jakarta.servlet.Servlet, jakarta.servlet.ServletConfig

public class DHtmlUpdateServlet extends jakarta.servlet.http.HttpServlet
Used to receive command from the server and send result back to client. Though it is called DHtmlUpdateServlet, it is used to serve all kind of HTTP-based clients, including ajax (HTML+Ajax), mil (Mobile Interactive Language), and others (see Desktop.getDeviceType().

Init parameters:

compress
It specifies whether to compress the output if the browser supports the compression (Accept-Encoding).
extension0, extension1...
It specifies an AU extension (AuExtension). The extension0 parameter specifies the first AU extension, the extension1 parameter the second AU extension, and so on.
The syntax of the value is
/prefix=class

By default: there are three extensions are associated with "/upload", "/view" and "/dropupload" (see addAuExtension(org.zkoss.zk.ui.WebApp, java.lang.String, org.zkoss.zk.au.http.AuExtension). Also, "/web" is reserved. Don't associate to any AU extension.

Author:
tomyeh
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    addAuExtension(String prefix, AuExtension extension)
    Adds an AU extension and associates it with the specified prefix.
    static final AuExtension
    addAuExtension(WebApp wapp, String prefix, AuExtension extension)
    Adds an AU extension and associates it with the specified prefix, even before DHtmlUpdateServlet is started.
    void
    denoteSessionTimeout(WebApp wapp, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean compress)
    Responds to an AU request that arrived without an active session.
    void
     
    protected void
    doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
     
    protected void
    doPost(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
     
    Returns the AU extension associated with the specified prefix, or null if no AU extension associated.
    static final AuExtension
    getAuExtension(WebApp wapp, String prefix)
    Returns the AU extension that is associated the specified prefix.
    protected Desktop
    getDesktop(Session sess, String dtid)
    Returns the desktop of the specified ID, or null if not found.
    protected long
    getLastModified(jakarta.servlet.http.HttpServletRequest request)
     
    Returns the update servlet of the specified application, or null if not loaded yet.
    void
     
    boolean
     
    void
    process(Session sess, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean compress)
    Process asynchronous update requests from the client.
    protected Desktop
    recoverDesktop(Session sess, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, WebAppCtrl wappc, String dtid)
    Recovers the desktop if possible.
    void
    setCompress(boolean compress)
     

    Methods inherited from class jakarta.servlet.http.HttpServlet

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

    Methods inherited from class jakarta.servlet.GenericServlet

    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 Details

    • DHtmlUpdateServlet

      public DHtmlUpdateServlet()
  • Method Details

    • getUpdateServlet

      public static DHtmlUpdateServlet getUpdateServlet(WebApp wapp)
      Returns the update servlet of the specified application, or null if not loaded yet. Note: if the update servlet is not loaded, it returns null.
      Since:
      3.0.2
    • init

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

      public void destroy()
      Specified by:
      destroy in interface jakarta.servlet.Servlet
      Overrides:
      destroy in class jakarta.servlet.GenericServlet
    • isCompress

      public boolean isCompress()
    • setCompress

      public void setCompress(boolean compress)
    • getAuExtension

      public static final AuExtension getAuExtension(WebApp wapp, String prefix)
      Returns the AU extension that is associated the specified prefix.
      Since:
      5.0.0
    • getAuExtension

      public AuExtension getAuExtension(String prefix)
      Returns the AU extension associated with the specified prefix, or null if no AU extension associated.
      Since:
      5.0.0
    • addAuExtension

      public static final AuExtension addAuExtension(WebApp wapp, String prefix, AuExtension extension) throws jakarta.servlet.ServletException
      Adds an AU extension and associates it with the specified prefix, even before DHtmlUpdateServlet is started.

      Unlike addAuExtension(String, AuExtension), it can be called even if the update servlet is not loaded yet (getUpdateServlet(org.zkoss.zk.ui.WebApp) returns null).

      If there was an AU extension associated with the same name, the the old AU extension will be replaced.

      Throws:
      jakarta.servlet.ServletException
      Since:
      5.0.0
    • addAuExtension

      public AuExtension addAuExtension(String prefix, AuExtension extension) throws jakarta.servlet.ServletException
      Adds an AU extension and associates it with the specified prefix.

      If there was an AU extension associated with the same name, the the old AU extension will be replaced.

      If you want to add an Au extension, even before DHtmlUpdateServlet is started, use addAuExtension(WebApp, String, AuExtension) instead.

      Parameters:
      prefix - the prefix. It must start with "/", but it cannot be "/" nor "/web" (which are reserved).
      extension - the AU extension (never null).
      Returns:
      the previous AU extension associated with the specified prefix, or null if the prefix was not associated before.
      Throws:
      jakarta.servlet.ServletException
      Since:
      5.0.0
      See Also:
    • getLastModified

      protected long getLastModified(jakarta.servlet.http.HttpServletRequest request)
      Overrides:
      getLastModified in class jakarta.servlet.http.HttpServlet
    • doGet

      protected void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException
      Overrides:
      doGet in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • doPost

      protected void doPost(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException
      Overrides:
      doPost in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • denoteSessionTimeout

      public void denoteSessionTimeout(WebApp wapp, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean compress) throws jakarta.servlet.ServletException, IOException
      Responds to an AU request that arrived without an active session.

      A genuine ZK AU request whose session expired carries a desktop id - for a multipart upload the desktop id lives inside the request body, so it is parsed first (the same way the async-update path does). Such a request is answered with HTTP 200 and the ZK-Error: 410 header (plus the obsolete-page / redirect body) so the client can handle the timeout. A request that carries no desktop id - i.e. an incomplete/invalid request no genuine ZK client would send - is answered with HTTP 467 "Incomplete request", consistent with the async-update path, so monitoring and security tools that inspect the HTTP status can detect it.

      Throws:
      jakarta.servlet.ServletException
      IOException
      Since:
      6.5.2
    • process

      public void process(Session sess, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean compress) throws jakarta.servlet.ServletException, IOException
      Process asynchronous update requests from the client.
      Throws:
      jakarta.servlet.ServletException
      IOException
      Since:
      3.0.0
    • getDesktop

      protected Desktop getDesktop(Session sess, String dtid)
      Parameters:
      sess - the session (never null)
      dtid - the desktop ID to look for
      Since:
      5.0.3
    • recoverDesktop

      protected Desktop recoverDesktop(Session sess, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, WebAppCtrl wappc, String dtid)
      Recovers the desktop if possible. It is called if getDesktop(org.zkoss.zk.ui.Session, java.lang.String) returns null.

      The default implementation will look for any failover manager (FailoverManager) is registered, and forward the invocation to it if found.

      Returns:
      the recovered desktop, or null if failed to recover
      Since:
      5.0.3