Package eu.webtoolkit.jwt
Class WtServlet
- java.lang.Object
-
- jakarta.servlet.GenericServlet
-
- jakarta.servlet.http.HttpServlet
-
- eu.webtoolkit.jwt.WtServlet
-
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,java.io.Serializable
public abstract class WtServlet extends jakarta.servlet.http.HttpServletThe 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 newWApplicationobject 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 aWResource.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringAuthStrings_xml
-
Constructor Summary
Constructors Constructor Description WtServlet()Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddResource(WResource staticResource, java.lang.String path)Binds a resource to a fixed path.abstract WApplicationcreateApplication(WEnvironment env)Creates a new application for a new session.protected voiddoGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp)Implement the GET request.protected voiddoPost(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp)Implement the POST request.ConfigurationgetConfiguration()Returns the JWt configuration.static WtServletgetInstance()static ServletApigetServletApi()This function is only to be used by JWt internals.voidinit(jakarta.servlet.ServletConfig config)Initiate the internal servlet api.static booleanisAsyncSupported()Returns whether asynchronous I/O is supported.voidpost(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).voidpostAll(java.lang.Runnable function)Posts a task to be run within the scope of all currently active sessions.java.lang.StringreadConfigurationProperty(java.lang.String name, java.lang.String value)voidremoveResource(WResource staticResource)voidsetConfiguration(Configuration configuration)Sets the JWt configuration.-
Methods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPatch, doPut, doTrace, getLastModified, isSensitiveHeader, service, service
-
-
-
-
Field Detail
-
AuthStrings_xml
public static final java.lang.String AuthStrings_xml
- See Also:
- Constant Field Values
-
-
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.ServletExceptionInitiate 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:
initin interfacejakarta.servlet.Servlet- Overrides:
initin classjakarta.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.IOExceptionImplement the GET request.- Overrides:
doGetin classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionjava.io.IOException
-
doPost
protected void doPost(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) throws jakarta.servlet.ServletException, java.io.IOExceptionImplement the POST request.- Overrides:
doPostin classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionjava.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.UpdateLockexplicitly, 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 lockedfunction- the task to be runfallBackFunction- the task to be run in case the application has been quit or its session expired.
-
postAll
public void postAll(java.lang.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:
post(eu.webtoolkit.jwt.WApplication,java.lang.Runnable,java.lang.Runnable)
-
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()
-
-