Class WtServlet

  • All Implemented Interfaces:
    jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, java.io.Serializable

    public abstract class WtServlet
    extends jakarta.servlet.http.HttpServlet
    The abstract JWt servlet class.

    This servlet processes all requests for a JWt application. You need to specialize this class to provide an entry point for your web application.

    For each new session createApplication(WEnvironment) is called to create a new WApplication object for that session. The web controller that is implemented by this servlet validates each incoming request, and takes the appropriate action by either notifying the application of an event, or serving a WResource.

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String AuthStrings_xml  
      • Fields inherited from class jakarta.servlet.http.HttpServlet

        LEGACY_DO_HEAD
    • Constructor Summary

      Constructors 
      Constructor Description
      WtServlet()
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addResource​(WResource staticResource, java.lang.String path)
      Binds a resource to a fixed path.
      abstract WApplication createApplication​(WEnvironment env)
      Creates a new application for a new session.
      protected void doGet​(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp)
      Implement the GET request.
      protected void doPost​(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp)
      Implement the POST request.
      Configuration getConfiguration()
      Returns the JWt configuration.
      static WtServlet getInstance()  
      static ServletApi getServletApi()
      This function is only to be used by JWt internals.
      void init​(jakarta.servlet.ServletConfig config)
      Initiate the internal servlet api.
      static boolean isAsyncSupported()
      Returns whether asynchronous I/O is supported.
      void post​(WApplication app, java.lang.Runnable function, java.lang.Runnable fallBackFunction)
      Posts a task to be run within the scope of a session (and using the session lock).
      void postAll​(java.lang.Runnable function)
      Posts a task to be run within the scope of all currently active sessions.
      java.lang.String readConfigurationProperty​(java.lang.String name, java.lang.String value)  
      void removeResource​(WResource staticResource)  
      void setConfiguration​(Configuration configuration)
      Sets the JWt configuration.
      • Methods inherited from class jakarta.servlet.http.HttpServlet

        doDelete, doHead, doOptions, doPatch, doPut, doTrace, getLastModified, isSensitiveHeader, 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 Detail

    • Constructor Detail

      • WtServlet

        public WtServlet()
        Constructor.

        Instantiates the servlet using the default configuration.

        See Also:
        getConfiguration()
    • Method Detail

      • getServletApi

        public static ServletApi getServletApi()
        This function is only to be used by JWt internals.
        Returns:
        the servlet API interface
      • init

        public void init​(jakarta.servlet.ServletConfig config)
                  throws jakarta.servlet.ServletException
        Initiate the internal servlet api. If you want to override this function, make sure to call the super function, to ensure the initialization of the servlet api.
        Specified by:
        init in interface jakarta.servlet.Servlet
        Overrides:
        init in class jakarta.servlet.http.HttpServlet
        Throws:
        jakarta.servlet.ServletException
      • doGet

        protected void doGet​(jakarta.servlet.http.HttpServletRequest req,
                             jakarta.servlet.http.HttpServletResponse resp)
                      throws jakarta.servlet.ServletException,
                             java.io.IOException
        Implement the GET request.
        Overrides:
        doGet in class jakarta.servlet.http.HttpServlet
        Throws:
        jakarta.servlet.ServletException
        java.io.IOException
      • doPost

        protected void doPost​(jakarta.servlet.http.HttpServletRequest req,
                              jakarta.servlet.http.HttpServletResponse resp)
                       throws jakarta.servlet.ServletException,
                              java.io.IOException
        Implement the POST request.
        Overrides:
        doPost in class jakarta.servlet.http.HttpServlet
        Throws:
        jakarta.servlet.ServletException
        java.io.IOException
      • getConfiguration

        public Configuration getConfiguration()
        Returns the JWt configuration.

        The Configuration is only definitively constructed after WtServlet#init() is invoked. You should only modify the configuration from this method.

        Returns:
        the configuration.
      • setConfiguration

        public void setConfiguration​(Configuration configuration)
        Sets the JWt configuration.

        You should only set the configuration from the servlet constructor.

        Parameters:
        configuration -
      • createApplication

        public abstract WApplication createApplication​(WEnvironment env)
        Creates a new application for a new session.
        Parameters:
        env - the environment that describes the new user (agent) and initial parameters
        Returns:
        a new application object.
      • isAsyncSupported

        public static boolean isAsyncSupported()
        Returns whether asynchronous I/O is supported. This is only the case when the servlet container implements the Servlet 3.0 API, and when this application is configured to support asynchronous processing. Asynchronous I/O is required for recursive event loops, and encouraged for scalable server push (although JWt doesn't strictly require it).
        Returns:
        whether asynchronous I/O is supported.
      • post

        public void post​(WApplication app,
                         java.lang.Runnable function,
                         java.lang.Runnable fallBackFunction)
        Posts a task to be run within the scope of a session (and using the session lock). Rather than taking an #WApplication.UpdateLock explicitly, which may stall the current thread and also creates the risk of a dead lock scenario, it's usually better to post the task asynchronously to an application session. This will either run the task immediately (within the current thread if the other session is currently unlocked), or queue the event to be run (by the thread currently holding the session lock) when it is releasing the lock. Multiple posted events to the same session are thus guaranteed to be run sequentially in the order they were posted.
        Parameters:
        app - the application instance which needs to be locked
        function - the task to be run
        fallBackFunction - the task to be run in case the application has been quit or its session expired.
      • readConfigurationProperty

        public java.lang.String readConfigurationProperty​(java.lang.String name,
                                                          java.lang.String value)
      • addResource

        public void addResource​(WResource staticResource,
                                java.lang.String path)
        Binds a resource to a fixed path. Resources may either be private to a single session or public. Use this method to add a public resource with a fixed path. When the path contains the application context's path, the path should start with a '/', if not the '/' should be omitted.
      • removeResource

        public void removeResource​(WResource staticResource)
      • getInstance

        public static WtServlet getInstance()