Servlet, ServletConfigpublic abstract class WebSocketServlet extends HttpServlet
To use this servlet, you will be required to register your websockets with the WebSocketServletFactory so that it can create your websockets under the
appropriate conditions.
The most basic implementation would be as follows.
package my.example;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
public class MyEchoServlet extends WebSocketServlet
{
@Override
public void configure(WebSocketServletFactory factory)
{
// set a 10 second idle timeout
factory.getPolicy().setIdleTimeout(10000);
// register my socket
factory.register(MyEchoSocket.class);
}
}
Note: that only request that conforms to a "WebSocket: Upgrade" handshake request will trigger the WebSocketServletFactory handling of creating
WebSockets.
Configuration / Init-Parameters:
Note: If you use the @WebSocket annotation, these configuration settings can be specified on a per WebSocket basis, vs a per Servlet
basis.
| Constructor | Description |
|---|---|
WebSocketServlet() |
| Modifier and Type | Method | Description |
|---|---|---|
abstract void |
configure(WebSocketServletFactory factory) |
|
void |
destroy() |
|
void |
init() |
|
protected void |
service(HttpServletRequest request,
HttpServletResponse response) |
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, logdoDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, servicepublic abstract void configure(WebSocketServletFactory factory)
public void destroy()
destroy in interface Servletdestroy in class GenericServletpublic void init()
throws ServletException
init in class GenericServletServletExceptionGenericServlet.init()protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException
service in class HttpServletServletExceptionjava.io.IOExceptionHttpServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)Copyright © 1995–2018 Webtide. All rights reserved.