Class WtServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
eu.webtoolkit.jwt.WtServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public abstract class WtServlet extends javax.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:
  • Field Summary

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

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addResource(WResource staticResource, String path)
    Binds a resource to a fixed path.
    abstract WApplication
    Creates a new application for a new session.
    protected void
    doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
    Implement the GET request.
    protected void
    doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
    Implement the POST request.
    Returns the JWt configuration.
    static WtServlet
     
    static ServletApi
    This function is only to be used by JWt internals.
    void
    init(javax.servlet.ServletConfig config)
    Initiate the internal servlet api.
    static boolean
    Returns whether asynchronous I/O is supported.
    void
    post(WApplication app, Runnable function, Runnable fallBackFunction)
    Posts a task to be run within the scope of a session (and using the session lock).
    void
    postAll(Runnable function)
    Posts a task to be run within the scope of all currently active sessions.
     
    void
    Sets the JWt configuration.

    Methods inherited from class javax.servlet.http.HttpServlet

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

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

    • WtServlet

      public WtServlet()
      Constructor.

      Instantiates the servlet using the default configuration.

      See Also:
  • Method Details

    • getServletApi

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

      public void init(javax.servlet.ServletConfig config) throws javax.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 javax.servlet.Servlet
      Overrides:
      init in class javax.servlet.GenericServlet
      Throws:
      javax.servlet.ServletException
    • doGet

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

      protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
      Implement the POST request.
      Overrides:
      doPost in class javax.servlet.http.HttpServlet
      Throws:
      javax.servlet.ServletException
      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, Runnable function, 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.
    • postAll

      public void postAll(Runnable function)
      Posts a task to be run within the scope of all currently active sessions.
      Parameters:
      function - the task to be run
      See Also:
    • readConfigurationProperty

      public String readConfigurationProperty(String name, String value)
    • addResource

      public void addResource(WResource staticResource, 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.
    • getInstance

      public static WtServlet getInstance()