Top Description Fields Constructors Methods
org.eclipse.jetty.websocket.core.server

public Class WebSocketMappings

extends Object
implements Dumpable, Listener
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.component.LifeCycle.Listener, java.util.EventListener, org.eclipse.jetty.util.component.Dumpable
Imports
java.io.IOException, java.util.function.BiConsumer, org.eclipse.jetty.http.pathmap.MatchedResource, .PathMappings, .PathSpec, .RegexPathSpec, .ServletPathSpec, .UriTemplatePathSpec, org.eclipse.jetty.server.Request, .Response, org.eclipse.jetty.server.handler.ContextHandler, org.eclipse.jetty.util.Callback, org.eclipse.jetty.util.component.Dumpable, .LifeCycle, org.eclipse.jetty.websocket.core.Configuration, .CoreSession, .FrameHandler, .WebSocketComponents, org.eclipse.jetty.websocket.core.exception.WebSocketException, org.eclipse.jetty.websocket.core.server.internal.CreatorNegotiator, .HandshakerSelector, org.slf4j.Logger, .LoggerFactory

Mapping of pathSpec to a tupple of WebSocketCreator, FrameHandlerFactory and Configuration.Customizer.

When the upgrade(WebSocketNegotiator, Request, Response, Callback, Configuration.Customizer) method is called, a match for the pathSpec is looked for. If one is found then the creator is used to create a POJO for the WebSocket endpoint, the factory is used to wrap that POJO with a FrameHandler and the customizer is used to configure the resulting CoreSession.

Field Summary

Modifier and TypeField and Description
private final WebSocketComponents
private final Handshaker
private static final Logger
private final PathMappings<WebSocketNegotiator>
public static final String

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
addMapping(PathSpec
the pathspec to respond on
pathSpec
,
WebSocketCreator
the websocket creator to activate on the provided mapping.
creator
,
FrameHandlerFactory
the factory to use to create a FrameHandler for the websocket.
factory
,
Configuration.Customizer
the customizer to use to customize the WebSocket session.
customizer
)

Manually add a WebSocket mapping.

public void
addMapping(PathSpec
the pathspec to respond on
pathSpec
,
WebSocketNegotiator
the WebSocketNegotiator to use to create a FrameHandler for the websocket.
negotiator
)

Manually add a WebSocket mapping.

public void
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 WebSocketMappings
public Handshaker
public static WebSocketMappings
getMappings(ContextHandler contextHandler)

public WebSocketNegotiator

Returns:

the WebSocketNegotiator if there is a match, or null if there is no match
getMatchedNegotiator
(Request
the request to match
request
,
BiConsumer<Request, PathSpec>
the consumer to invoke in case of match
consumer
)

Returns the mapped WebSocketNegotiator if there is a match of given request against a registered mapping, otherwise returns null if there is no match.

public WebSocketComponents
public WebSocketCreator
public WebSocketNegotiator
public void
public static PathSpec

Returns:

the PathSpec implementation for the rawSpec
parsePathSpec
(String
the raw path spec as String to parse.
rawSpec
)

Parse a PathSpec string into a PathSpec instance.

public boolean
private static void
storePathSpec(Request request, PathSpec pathSpec)

public boolean

Returns:

true if the WebSocket upgrade was accepted
upgrade
(Request
the request
request
,
Response
the response
response
,
Callback
the callback
callback
,
Configuration.Customizer
the customizer
defaultCustomizer
)

Attempts to find a WebSocket mapping and upgrade a request to WebSocket.

public boolean

Returns:

true if the WebSocket upgrade was accepted
upgrade
(WebSocketNegotiator
the negotiator
negotiator
,
Request
the request
request
,
Response
the response
response
,
Callback
the callback
callback
,
Configuration.Customizer
the customizer
defaultCustomizer
)

Attempts to find a WebSocket mapping and upgrade a request to WebSocket.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

componentsback to summary
private final WebSocketComponents components
handshakerback to summary
private final Handshaker handshaker
LOGback to summary
private static final Logger LOG
mappingsback to summary
private final PathMappings<WebSocketNegotiator> mappings
WEBSOCKET_MAPPING_ATTRIBUTEback to summary
public static final String WEBSOCKET_MAPPING_ATTRIBUTE

Constructor Detail

WebSocketMappingsback to summary
public WebSocketMappings()
WebSocketMappingsback to summary
public WebSocketMappings(WebSocketComponents components)

Method Detail

addMappingback to summary
public void addMapping(PathSpec pathSpec, WebSocketCreator creator, FrameHandlerFactory factory, Configuration.Customizer customizer) throws WebSocketException

Manually add a WebSocket mapping.

If mapping is added before this configuration is started, then it is persisted through stop/start of this configuration's lifecycle. Otherwise it will be removed when this configuration is stopped.

Parameters
pathSpec:PathSpec

the pathspec to respond on

creator:WebSocketCreator

the websocket creator to activate on the provided mapping.

factory:FrameHandlerFactory

the factory to use to create a FrameHandler for the websocket.

customizer:Configuration.Customizer

the customizer to use to customize the WebSocket session.

addMappingback to summary
public void addMapping(PathSpec pathSpec, WebSocketNegotiator negotiator) throws WebSocketException

Manually add a WebSocket mapping.

If mapping is added before this configuration is started, then it is persisted through stop/start of this configuration's lifecycle. Otherwise it will be removed when this configuration is stopped.

Parameters
pathSpec:PathSpec

the pathspec to respond on

negotiator:WebSocketNegotiator

the WebSocketNegotiator to use to create a FrameHandler for the websocket.

clearback to summary
public void clear()
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
ensureMappingsback to summary
public static WebSocketMappings ensureMappings(ContextHandler contextHandler)
getHandshakerback to summary
public Handshaker getHandshaker()
getMappingsback to summary
public static WebSocketMappings getMappings(ContextHandler contextHandler)
getMatchedNegotiatorback to summary
public WebSocketNegotiator getMatchedNegotiator(Request request, BiConsumer<Request, PathSpec> consumer)

Returns the mapped WebSocketNegotiator if there is a match of given request against a registered mapping, otherwise returns null if there is no match.

If there is a match, the given consumer is invoked with the PathSpec that matched so that, for example, it can be stored as a request attribute for later usage. This is important in case of UriTemplatePathSpec, where applications may want to extract the values of the template groups.

Parameters
request:Request

the request to match

consumer:BiConsumer<Request, PathSpec>

the consumer to invoke in case of match

Returns:WebSocketNegotiator

the WebSocketNegotiator if there is a match, or null if there is no match

getWebSocketComponentsback to summary
public WebSocketComponents getWebSocketComponents()
getWebSocketCreatorback to summary
public WebSocketCreator getWebSocketCreator(PathSpec pathSpec)
getWebSocketNegotiatorback to summary
public WebSocketNegotiator getWebSocketNegotiator(PathSpec pathSpec)
lifeCycleStoppingback to summary
public void lifeCycleStopping(LifeCycle event)

Overrides default org.eclipse.jetty.util.component.LifeCycle.Listener.lifeCycleStopping.

Annotations
@Override
parsePathSpecback to summary
public static PathSpec parsePathSpec(String rawSpec)

Parse a PathSpec string into a PathSpec instance.

Recognized Path Spec syntaxes:

/path/to or / or *.ext or servlet|{spec}
Servlet Syntax
^{spec} or regex|{spec}
Regex Syntax
uri-template|{spec}
URI Template (see JSR356 and RFC6570 level 1)
Parameters
rawSpec:String

the raw path spec as String to parse.

Returns:PathSpec

the PathSpec implementation for the rawSpec

removeMappingback to summary
public boolean removeMapping(PathSpec pathSpec)
storePathSpecback to summary
private static void storePathSpec(Request request, PathSpec pathSpec)
upgradeback to summary
public boolean upgrade(Request request, Response response, Callback callback, Configuration.Customizer defaultCustomizer) throws WebSocketException

Attempts to find a WebSocket mapping and upgrade a request to WebSocket.

Returns true if the WebSocket upgrade is successful and a successful response is generated and the callback eventually completed, or if the WebSocket upgrade failed and a failure response is generated and the callback eventually completed. Returns false if a response is not generated and the caller is responsible for generating a response and completing the callback.

Parameters
request:Request

the request

response:Response

the response

callback:Callback

the callback

defaultCustomizer:Configuration.Customizer

the customizer

Returns:boolean

true if the WebSocket upgrade was accepted

Exceptions
WebSocketException:
there is an error during the upgrade
upgradeback to summary
public boolean upgrade(WebSocketNegotiator negotiator, Request request, Response response, Callback callback, Configuration.Customizer defaultCustomizer) throws WebSocketException

Attempts to find a WebSocket mapping and upgrade a request to WebSocket.

Returns true if the WebSocket upgrade is successful and a successful response is generated and the callback eventually completed, or if the WebSocket upgrade failed and a failure response is generated and the callback eventually completed. Returns false if a response is not generated and the caller is responsible for generating a response and completing the callback.

Parameters
negotiator:WebSocketNegotiator

the negotiator

request:Request

the request

response:Response

the response

callback:Callback

the callback

defaultCustomizer:Configuration.Customizer

the customizer

Returns:boolean

true if the WebSocket upgrade was accepted

Exceptions
WebSocketException:
there is an error during the upgrade