Class WebSocketUpgradeFilter
- java.lang.Object
-
- org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter
-
- All Implemented Interfaces:
javax.servlet.Filter
,org.eclipse.jetty.util.component.Dumpable
,MappedWebSocketCreator
@ManagedObject("WebSocket Upgrade Filter") public class WebSocketUpgradeFilter extends java.lang.Object implements javax.servlet.Filter, MappedWebSocketCreator, org.eclipse.jetty.util.component.Dumpable
Inline Servlet Filter to capture WebSocket upgrade requests and perform path mappings toWebSocketCreator
objects.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ATTR_KEY
static java.lang.String
CONFIG_ATTRIBUTE_KEY
static java.lang.String
CONTEXT_ATTRIBUTE_KEY
-
Constructor Summary
Constructors Constructor Description WebSocketUpgradeFilter()
WebSocketUpgradeFilter(NativeWebSocketConfiguration configuration)
WebSocketUpgradeFilter(WebSocketServerFactory factory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addMapping(java.lang.String spec, WebSocketCreator creator)
Add a mapping, of a pathspec to a WebSocketCreator.void
addMapping(org.eclipse.jetty.http.pathmap.PathSpec spec, WebSocketCreator creator)
Add a mapping.void
addMapping(PathSpec spec, WebSocketCreator creator)
Deprecated.static WebSocketUpgradeFilter
configure(org.eclipse.jetty.servlet.ServletContextHandler context)
Configure the default WebSocketUpgradeFilter.static WebSocketUpgradeFilter
configureContext(javax.servlet.ServletContext context)
Deprecated.useconfigureContext(ServletContextHandler)
insteadstatic WebSocketUpgradeFilter
configureContext(org.eclipse.jetty.servlet.ServletContextHandler context)
Deprecated.useconfigure(ServletContextHandler)
insteadvoid
destroy()
void
doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
java.lang.String
dump()
void
dump(java.lang.Appendable out, java.lang.String indent)
NativeWebSocketConfiguration
getConfiguration()
WebSocketServletFactory
getFactory()
WebSocketCreator
getMapping(java.lang.String target)
/** Returns the creator for the given path spec.void
init(javax.servlet.FilterConfig config)
boolean
removeMapping(java.lang.String spec)
Removes the mapping based on the given path spec.void
setToAttribute(javax.servlet.ServletContext context, java.lang.String key)
java.lang.String
toString()
-
-
-
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
public WebSocketUpgradeFilter(WebSocketServerFactory factory)
-
WebSocketUpgradeFilter
public WebSocketUpgradeFilter(NativeWebSocketConfiguration configuration)
-
-
Method Detail
-
configure
public static WebSocketUpgradeFilter configure(org.eclipse.jetty.servlet.ServletContextHandler context) throws javax.servlet.ServletException
Configure the default WebSocketUpgradeFilter.This will return the default
WebSocketUpgradeFilter
on the providedServletContextHandler
, creating the filter if necessary.The default
WebSocketUpgradeFilter
is also available via theServletContext
attribute namedorg.eclipse.jetty.websocket.server.WebSocketUpgradeFilter
- Parameters:
context
- theServletContextHandler
to use- Returns:
- the configured default
WebSocketUpgradeFilter
instance - Throws:
javax.servlet.ServletException
- if the filer cannot be configured
-
configureContext
@Deprecated public static WebSocketUpgradeFilter configureContext(org.eclipse.jetty.servlet.ServletContextHandler context) throws javax.servlet.ServletException
Deprecated.useconfigure(ServletContextHandler)
instead- Parameters:
context
- theServletContextHandler
to use- Returns:
- a configured
WebSocketUpgradeFilter
instance - 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
WebSocketUpgradeFilter
instance - Throws:
javax.servlet.ServletException
- if the filer cannot be configured
-
addMapping
public void addMapping(org.eclipse.jetty.http.pathmap.PathSpec spec, WebSocketCreator creator)
Description copied from interface:MappedWebSocketCreator
Add a mapping.- Specified by:
addMapping
in interfaceMappedWebSocketCreator
- Parameters:
spec
- the path spec to usecreator
- the creator for the mapping
-
addMapping
@Deprecated public void addMapping(PathSpec spec, WebSocketCreator creator)
Deprecated.Description copied from interface:MappedWebSocketCreator
Add a mapping.- Specified by:
addMapping
in interfaceMappedWebSocketCreator
- Parameters:
spec
- the path spec to usecreator
- the creator for the mapping
-
addMapping
public void addMapping(java.lang.String spec, WebSocketCreator creator)
Description copied from interface:MappedWebSocketCreator
Add a mapping, of a pathspec to a WebSocketCreator.Recognized Path Spec syntaxes
/path/to
or/
or*.ext
orservlet|{spec}
- Servlet Syntax
^{spec}
orregex|{spec}
- Regex Syntax
uri-template|{spec}
- URI Template (see JSR356 and RFC6570 level 1)
- Specified by:
addMapping
in interfaceMappedWebSocketCreator
- Parameters:
spec
- the path spec to use.creator
- the websocket creator for this specific mapping
-
removeMapping
public boolean removeMapping(java.lang.String spec)
Description copied from interface:MappedWebSocketCreator
Removes the mapping based on the given path spec.- Specified by:
removeMapping
in 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
-
destroy
public void destroy()
- Specified by:
destroy
in 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:
doFilter
in interfacejavax.servlet.Filter
- Throws:
java.io.IOException
javax.servlet.ServletException
-
dump
public java.lang.String dump()
- Specified by:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
- Specified by:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
- Throws:
java.io.IOException
-
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:
getMapping
in 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:
init
in 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:
toString
in classjava.lang.Object
-
-