Class WebSocketUpgradeFilter
- java.lang.Object
-
- org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter
-
- All Implemented Interfaces:
javax.servlet.Filter,Dumpable,MappedWebSocketCreator
@ManagedObject("WebSocket Upgrade Filter") public class WebSocketUpgradeFilter extends java.lang.Object implements javax.servlet.Filter, MappedWebSocketCreator, Dumpable
Inline Servlet Filter to capture WebSocket upgrade requests and perform path mappings to
WebSocketCreatorobjects.Embedded Jetty Users should initialize this filter using the
configure(ServletContextHandler)method. If you also want to establish some mappings ofPathSpectoWebSocketCreatoragainst thisWebSocketUpgradeFilterthen these actions must occur during the Servlet Initialization Phase. A convenience method is provided withNativeWebSocketServletContainerInitializer.configure(ServletContextHandler, NativeWebSocketServletContainerInitializer.Configurator)to create a lambda that will execute during the appropriate Servlet Initialization Phase.ServletContextHandler contextHandler = new ServletContextHandler(...); WebSocketUpgradeFilter.configure(contextHandler); NativeWebSocketServletContainerInitializer.configure(contextHandler, (context, container) -> { container.getPolicy().setMaxTextMessageBufferSize(65535); container.getPolicy().setInputBufferSize(16384); container.addMapping("/echo", ServerEchoSocket.class); container.addMapping(new ServletPathSpec("/api"), (req, resp) -> new ServerApiSocket()); });
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringATTR_KEYstatic java.lang.StringCONFIG_ATTRIBUTE_KEYstatic java.lang.StringCONTEXT_ATTRIBUTE_KEY
-
Constructor Summary
Constructors Constructor Description WebSocketUpgradeFilter()WebSocketUpgradeFilter(NativeWebSocketConfiguration configuration)Deprecated.WebSocketUpgradeFilter(WebSocketServerFactory factory)Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddMapping(java.lang.String spec, WebSocketCreator creator)Add Mapping to underlyingNativeWebSocketConfigurationvoidaddMapping(PathSpec spec, WebSocketCreator creator)Add Mapping to underlyingNativeWebSocketConfigurationvoidaddMapping(PathSpec spec, WebSocketCreator creator)Deprecated.static WebSocketUpgradeFilterconfigure(ServletContextHandler context)Configure the default WebSocketUpgradeFilter.static WebSocketUpgradeFilterconfigureContext(javax.servlet.ServletContext context)Deprecated.useconfigureContext(ServletContextHandler)insteadstatic WebSocketUpgradeFilterconfigureContext(ServletContextHandler context)Deprecated.useconfigure(ServletContextHandler)insteadvoiddestroy()voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)java.lang.Stringdump()voiddump(java.lang.Appendable out, java.lang.String indent)Dump this object (and children) into an Appendable using the provided indent after any new lines.NativeWebSocketConfigurationgetConfiguration()WebSocketServletFactorygetFactory()WebSocketCreatorgetMapping(java.lang.String target)/** Returns the creator for the given path spec.voidinit(javax.servlet.FilterConfig config)booleanremoveMapping(java.lang.String spec)Remove Mapping to underlyingNativeWebSocketConfigurationvoidsetToAttribute(javax.servlet.ServletContext context, java.lang.String key)java.lang.StringtoString()
-
-
-
Field Detail
-
CONTEXT_ATTRIBUTE_KEY
public static final java.lang.String CONTEXT_ATTRIBUTE_KEY
- See Also:
- Constant Field Values
-
CONFIG_ATTRIBUTE_KEY
public static final java.lang.String CONFIG_ATTRIBUTE_KEY
- See Also:
- Constant Field Values
-
ATTR_KEY
public static final java.lang.String ATTR_KEY
-
-
Constructor Detail
-
WebSocketUpgradeFilter
public WebSocketUpgradeFilter()
-
WebSocketUpgradeFilter
@Deprecated public WebSocketUpgradeFilter(WebSocketServerFactory factory)
Deprecated.
-
WebSocketUpgradeFilter
@Deprecated public WebSocketUpgradeFilter(NativeWebSocketConfiguration configuration)
Deprecated.
-
-
Method Detail
-
configure
public static WebSocketUpgradeFilter configure(ServletContextHandler context) throws javax.servlet.ServletException
Configure the default WebSocketUpgradeFilter.This will return the default
WebSocketUpgradeFilteron the providedServletContextHandler, creating the filter if necessary.The default
WebSocketUpgradeFilteris also available via theServletContextattribute namedorg.eclipse.jetty.websocket.server.WebSocketUpgradeFilter- Parameters:
context- theServletContextHandlerto use- Returns:
- the configured default
WebSocketUpgradeFilterinstance, use this reference later in your Servlet Initialization Phase to establish mappings of websockets. - Throws:
javax.servlet.ServletException- if the filer cannot be configured
-
configureContext
@Deprecated public static WebSocketUpgradeFilter configureContext(ServletContextHandler context) throws javax.servlet.ServletException
Deprecated.useconfigure(ServletContextHandler)instead- Parameters:
context- theServletContextHandlerto use- Returns:
- a configured
WebSocketUpgradeFilterinstance - Throws:
javax.servlet.ServletException- if the filer cannot be configured
-
configureContext
@Deprecated public static WebSocketUpgradeFilter configureContext(javax.servlet.ServletContext context) throws javax.servlet.ServletException
Deprecated.useconfigureContext(ServletContextHandler)instead- Parameters:
context- the ServletContext to use- Returns:
- a configured
WebSocketUpgradeFilterinstance - Throws:
javax.servlet.ServletException- if the filer cannot be configured
-
addMapping
public void addMapping(PathSpec spec, WebSocketCreator creator)
Add Mapping to underlying
NativeWebSocketConfigurationIMPORTANT: Can only be used during Servlet Initialization phase.
Embedded Jetty users, consider using
NativeWebSocketServletContainerInitializer.configure(ServletContextHandler, NativeWebSocketServletContainerInitializer.Configurator)instead to define mappings early that happen during the Servlet Initialization phase.- Specified by:
addMappingin interfaceMappedWebSocketCreator- Parameters:
spec- the path spec to usecreator- the creator for the mapping- See Also:
NativeWebSocketConfiguration.addMapping(PathSpec, WebSocketCreator)
-
addMapping
@Deprecated public void addMapping(PathSpec spec, WebSocketCreator creator)
Deprecated.Description copied from interface:MappedWebSocketCreatorAdd a mapping.- Specified by:
addMappingin interfaceMappedWebSocketCreator- Parameters:
spec- the path spec to usecreator- the creator for the mapping
-
addMapping
public void addMapping(java.lang.String spec, WebSocketCreator creator)Add Mapping to underlying
NativeWebSocketConfigurationIMPORTANT: Can only be used during Servlet Initialization phase.
Embedded Jetty users, consider using
NativeWebSocketServletContainerInitializer.configure(ServletContextHandler, NativeWebSocketServletContainerInitializer.Configurator)instead to define mappings early that happen during the Servlet Initialization phase.- Specified by:
addMappingin interfaceMappedWebSocketCreator- Parameters:
spec- the path spec to use.creator- the websocket creator for this specific mapping- See Also:
NativeWebSocketConfiguration.addMapping(String, WebSocketCreator)
-
removeMapping
public boolean removeMapping(java.lang.String spec)
Remove Mapping to underlying
NativeWebSocketConfigurationIMPORTANT: Can only be used during Servlet Initialization phase.
- Specified by:
removeMappingin interfaceMappedWebSocketCreator- Parameters:
spec- the path spec to remove (using the same spec syntax as seen inMappedWebSocketCreator.addMapping(String, WebSocketCreator))- Returns:
- true if underlying mapping were altered, false otherwise
- See Also:
NativeWebSocketConfiguration.removeMapping(String)
-
destroy
public void destroy()
- Specified by:
destroyin interfacejavax.servlet.Filter
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException- Specified by:
doFilterin interfacejavax.servlet.Filter- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOExceptionDescription copied from interface:DumpableDump 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.
-
getFactory
public WebSocketServletFactory getFactory()
-
getConfiguration
@ManagedAttribute(value="configuration", readonly=true) public NativeWebSocketConfiguration getConfiguration()
-
getMapping
public WebSocketCreator getMapping(java.lang.String target)
Description copied from interface:MappedWebSocketCreator/** Returns the creator for the given path spec.- Specified by:
getMappingin interfaceMappedWebSocketCreator- Parameters:
target- the spec to test for (using the same spec syntax as seen inMappedWebSocketCreator.addMapping(String, WebSocketCreator))- Returns:
- the websocket creator if path spec exists, or null
-
init
public void init(javax.servlet.FilterConfig config) throws javax.servlet.ServletException- Specified by:
initin interfacejavax.servlet.Filter- Throws:
javax.servlet.ServletException
-
setToAttribute
public void setToAttribute(javax.servlet.ServletContext context, java.lang.String key) throws javax.servlet.ServletException- Throws:
javax.servlet.ServletException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-