Class WebSocketServlet

  • All Implemented Interfaces:, javax.servlet.Servlet, javax.servlet.ServletConfig
    Direct Known Subclasses:

    public abstract class WebSocketServlet
    extends javax.servlet.http.HttpServlet
    Abstract Servlet used to bridge the Servlet API to the WebSocket API.

    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
         public void configure(WebSocketServletFactory factory)
             // set a 10 second idle timeout
             // register my socket
    Note: that only request that conforms to a "WebSocket: Upgrade" handshake request will trigger the WebSocketServletFactory handling of creating WebSockets.
    All other requests are treated as normal servlet requests.

    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.

    set the time in ms that a websocket may be idle before closing
    set the size in UTF-8 bytes that a websocket may be accept as a Text Message before closing
    set the size in bytes that a websocket may be accept as a Binary Message before closing
    set the size in bytes of the buffer used to read raw bytes from the network layer
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract void configure​(WebSocketServletFactory factory)  
      void destroy()  
      void init()  
      protected void service​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      • Methods inherited from class javax.servlet.http.HttpServlet

        doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
      • Methods inherited from class javax.servlet.GenericServlet

        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
    • Constructor Detail

      • WebSocketServlet

        public WebSocketServlet()
    • Method Detail

      • destroy

        public void destroy()
        Specified by:
        destroy in interface javax.servlet.Servlet
        destroy in class javax.servlet.GenericServlet
      • init

        public void init()
                  throws javax.servlet.ServletException
        init in class javax.servlet.GenericServlet
        See Also:
      • service

        protected void service​(javax.servlet.http.HttpServletRequest request,
                               javax.servlet.http.HttpServletResponse response)
                        throws javax.servlet.ServletException,
        service in class javax.servlet.http.HttpServlet
        See Also:
        HttpServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)