Class WebSocketUpgradeFilter

java.lang.Object
org.eclipse.jetty.websocket.servlet.WebSocketUpgradeFilter
All Implemented Interfaces:
jakarta.servlet.Filter, Dumpable

@ManagedObject("WebSocket Upgrade Filter") public class WebSocketUpgradeFilter extends Object implements jakarta.servlet.Filter, Dumpable
Inline Servlet Filter to capture WebSocket upgrade requests.

The configuration applied to this filter via init params will be used as the the default configuration of any websocket upgraded by this filter, prior to the configuration of the websocket applied by the WebSocketMappings.

Configuration / Init-Parameters:

idleTimeout
set the time in ms that a websocket may be idle before closing
maxTextMessageSize
set the size in UTF-8 bytes that a websocket may be accept as a Text Message before closing
maxBinaryMessageSize
set the size in bytes that a websocket may be accept as a Binary Message before closing
inputBufferSize
set the size in bytes of the buffer used to read raw bytes from the network layer
outputBufferSize
set the size in bytes of the buffer used to write bytes to the network layer
maxFrameSize
The maximum frame size sent or received.
autoFragment
If true, frames are automatically fragmented to respect the maximum frame size.
  • Constructor Details

    • WebSocketUpgradeFilter

      public WebSocketUpgradeFilter()
  • Method Details

    • getFilter

      public static FilterHolder getFilter(jakarta.servlet.ServletContext servletContext)
      Return the default WebSocketUpgradeFilter if present on the ServletContext.
      Parameters:
      servletContext - the ServletContext to use.
      Returns:
      the configured default WebSocketUpgradeFilter instance.
    • ensureFilter

      public static FilterHolder ensureFilter(jakarta.servlet.ServletContext servletContext)
      Ensure a WebSocketUpgradeFilter is available on the provided ServletContext, a new filter will added if one does not already exist.

      The default WebSocketUpgradeFilter is also available via the ServletContext attribute named org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter

      Parameters:
      servletContext - the ServletContext to use.
      Returns:
      the configured default WebSocketUpgradeFilter instance.
    • doFilter

      public void doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException
      Specified by:
      doFilter in interface jakarta.servlet.Filter
      Throws:
      IOException
      jakarta.servlet.ServletException
    • dump

      public void dump(Appendable out, String indent) throws IOException
      Description copied from interface: Dumpable
      Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
      Specified by:
      dump in interface Dumpable
      Parameters:
      out - The appendable to dump to
      indent - The indent to apply after any new lines.
      Throws:
      IOException - if unable to write to Appendable
    • init

      public void init(jakarta.servlet.FilterConfig config) throws jakarta.servlet.ServletException
      Specified by:
      init in interface jakarta.servlet.Filter
      Throws:
      jakarta.servlet.ServletException
    • destroy

      public void destroy()
      Specified by:
      destroy in interface jakarta.servlet.Filter