Package eu.webtoolkit.jwt
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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Posts a task to be run within the scope of all currently active sessions.readConfigurationProperty
(String name, String value) void
setConfiguration
(Configuration configuration) 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
-
Field Details
-
AuthStrings_xml
- See Also:
-
-
Constructor Details
-
WtServlet
public WtServlet()Constructor.Instantiates the servlet using the default configuration.
- See Also:
-
-
Method Details
-
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 interfacejavax.servlet.Servlet
- Overrides:
init
in classjavax.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 classjavax.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 classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
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
Sets the JWt configuration.You should only set the configuration from the servlet constructor.
- Parameters:
configuration
-
-
createApplication
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
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 lockedfunction
- the task to be runfallBackFunction
- the task to be run in case the application has been quit or its session expired.
-
postAll
Posts a task to be run within the scope of all currently active sessions.- Parameters:
function
- the task to be run- See Also:
-
readConfigurationProperty
-
addResource
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
-