Top Description Fields Constructors Methods
org.eclipse.jetty.ee10.websocket.servlet

public Class WebSocketUpgradeFilter

extends Object
implements Filter, Dumpable
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.component.Dumpable, jakarta.servlet.Filter
Annotations
@ManagedObject:WebSocket Upgrade Filter
Imports
java.io.IOException, java.time.Duration, java.util.EnumSet, .Objects, jakarta.servlet.DispatcherType, .Filter, .FilterChain, .FilterConfig, .ServletContext, .ServletException, .ServletRequest, .ServletResponse, org.eclipse.jetty.ee10.servlet.FilterHolder, .FilterMapping, .ServletContextHandler, .ServletContextRequest, .ServletContextResponse, .ServletHandler, org.eclipse.jetty.server.handler.ContextHandler, org.eclipse.jetty.util.FutureCallback, org.eclipse.jetty.util.annotation.ManagedObject, org.eclipse.jetty.util.component.Dumpable, .LifeCycle, org.eclipse.jetty.util.thread.AutoLock, org.eclipse.jetty.websocket.core.Configuration, .WebSocketConstants, org.eclipse.jetty.websocket.core.server.WebSocketMappings, org.slf4j.Logger, .LoggerFactory

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.

Field Summary

Modifier and TypeField and Description
private final Configuration.ConfigurationCustomizer
private static final AutoLock
private static final Logger
private WebSocketMappings

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
destroy()

Overrides default jakarta.servlet.Filter.destroy.

Called by the web container to indicate to a filter that it is being taken out of service.

public void
doFilter(ServletRequest
the ServletRequest object contains the client's request
request
,
ServletResponse
the ServletResponse object contains the filter's response
response
,
FilterChain
the FilterChain for invoking the next filter or the resource
chain
)

Implements jakarta.servlet.Filter.doFilter.

The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.

public void
dump(Appendable
The appendable to dump to
out
,
String
The indent to apply after any new lines.
indent
)

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines.

public static FilterHolder

Returns:

the configured default WebSocketUpgradeFilter instance.
ensureFilter
(ServletContext
the ServletContext to use.
servletContext
)

Ensure a WebSocketUpgradeFilter is available on the provided ServletContext, a new filter will added if one does not already exist.

public static FilterHolder

Returns:

the configured default WebSocketUpgradeFilter instance.
getFilter
(ServletContext
the ServletContext to use.
servletContext
)

Return the default WebSocketUpgradeFilter if present on the ServletContext.

public void
init(FilterConfig
a FilterConfig object containing the filter's configuration and initialization parameters
config
)

Overrides default jakarta.servlet.Filter.init.

Called by the web container to indicate to a filter that it is being placed into service.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultCustomizerback to summary
private final Configuration.ConfigurationCustomizer defaultCustomizer
LOCKback to summary
private static final AutoLock LOCK
LOGback to summary
private static final Logger LOG
mappingsback to summary
private WebSocketMappings mappings

Constructor Detail

WebSocketUpgradeFilterback to summary
public WebSocketUpgradeFilter()

Method Detail

destroyback to summary
public void destroy()

Overrides default jakarta.servlet.Filter.destroy.

Doc from jakarta.servlet.Filter.destroy.

Called by the web container to indicate to a filter that it is being taken out of service.

This method is only called once all threads within the filter's doFilter method have exited or after a timeout period has passed. After the web container calls this method, it will not call the doFilter method again on this instance of the filter.

This method gives the filter an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the filter's current state in memory.

Annotations
@Override
doFilterback to summary
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException

Implements jakarta.servlet.Filter.doFilter.

Doc from jakarta.servlet.Filter.doFilter.

The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. The FilterChain passed in to this method allows the Filter to pass on the request and response to the next entity in the chain.

A typical implementation of this method would follow the following pattern:

  1. Examine the request
  2. Optionally wrap the request object with a custom implementation to filter content or headers for input filtering
  3. Optionally wrap the response object with a custom implementation to filter content or headers for output filtering
    • Either invoke the next entity in the chain using the FilterChain object (chain.doFilter()),
    • or not pass on the request/response pair to the next entity in the filter chain to block the request processing
  4. Directly set headers on the response after invocation of the next entity in the filter chain.
Parameters
request:ServletRequest

the ServletRequest object contains the client's request

response:ServletResponse

the ServletResponse object contains the filter's response

chain:FilterChain

the FilterChain for invoking the next filter or the resource

Annotations
@Override
Exceptions
IOException:
if an I/O related error has occurred during the processing
ServletException:
if an exception occurs that interferes with the filter's normal operation
dumpback to summary
public void dump(Appendable out, String indent) throws IOException

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Doc from org.eclipse.jetty.util.component.Dumpable.dump.

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.

Parameters
out:Appendable

The appendable to dump to

indent:String

The indent to apply after any new lines.

Annotations
@Override
Exceptions
IOException:
if unable to write to Appendable
ensureFilterback to summary
public static FilterHolder ensureFilter(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:ServletContext

the ServletContext to use.

Returns:FilterHolder

the configured default WebSocketUpgradeFilter instance.

getFilterback to summary
public static FilterHolder getFilter(ServletContext servletContext)

Return the default WebSocketUpgradeFilter if present on the ServletContext.

Parameters
servletContext:ServletContext

the ServletContext to use.

Returns:FilterHolder

the configured default WebSocketUpgradeFilter instance.

initback to summary
public void init(FilterConfig config) throws ServletException

Overrides default jakarta.servlet.Filter.init.

Doc from jakarta.servlet.Filter.init.

Called by the web container to indicate to a filter that it is being placed into service.

The servlet container calls the init method exactly once after instantiating the filter. The init method must complete successfully before the filter is asked to do any filtering work. The container will ensure that actions performed in the init method will be visible to any threads that subsequently call the doFilter method according to the rules in JSR-133 (i.e. there is a 'happens before' relationship between init and doFilter).

The web container cannot place the filter into service if the init method either

  1. Throws a ServletException
  2. Does not return within a time period defined by the web container
Parameters
config:FilterConfig

a FilterConfig object containing the filter's configuration and initialization parameters

Annotations
@Override
Exceptions
ServletException:
if an exception has occurred that interferes with the filter's normal operation