Class WebSocketMappings
- All Implemented Interfaces:
EventListener, Dumpable, LifeCycle.Listener
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainer -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMapping(PathSpec pathSpec, WebSocketCreator creator, FrameHandlerFactory factory, Configuration.Customizer customizer) Manually add a WebSocket mapping.voidaddMapping(PathSpec pathSpec, WebSocketNegotiator negotiator) Manually add a WebSocket mapping.voidclear()voiddump(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.static WebSocketMappingsensureMappings(ContextHandler contextHandler) static WebSocketMappingsgetMappings(ContextHandler contextHandler) getMatchedNegotiator(Request request, BiConsumer<Request, PathSpec> consumer) Returns the mappedWebSocketNegotiatorif there is a match of givenrequestagainst aregistered mapping, otherwise returnsnullif there is no match.getWebSocketCreator(PathSpec pathSpec) getWebSocketNegotiator(PathSpec pathSpec) voidlifeCycleStopping(LifeCycle event) static PathSpecparsePathSpec(String rawSpec) Parse a PathSpec string into a PathSpec instance.booleanremoveMapping(PathSpec pathSpec) booleanupgrade(Request request, Response response, Callback callback, Configuration.Customizer defaultCustomizer) Attempts to find a WebSocket mapping and upgrade a request to WebSocket.booleanupgrade(WebSocketNegotiator negotiator, Request request, Response response, Callback callback, Configuration.Customizer defaultCustomizer) Attempts to find a WebSocket mapping and upgrade a request to WebSocket.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface LifeCycle.Listener
lifeCycleFailure, lifeCycleStarted, lifeCycleStarting, lifeCycleStopped
-
Field Details
-
WEBSOCKET_MAPPING_ATTRIBUTE
-
-
Constructor Details
-
WebSocketMappings
public WebSocketMappings() -
WebSocketMappings
-
-
Method Details
-
getMappings
-
ensureMappings
-
parsePathSpec
Parse a PathSpec string into a PathSpec instance.Recognized Path Spec syntaxes:
/path/toor/or*.extorservlet|{spec}- Servlet Syntax
^{spec}orregex|{spec}- Regex Syntax
uri-template|{spec}- URI Template (see JSR356 and RFC6570 level 1)
- Parameters:
rawSpec- the raw path spec as String to parse.- Returns:
- the
PathSpecimplementation for the rawSpec
-
getWebSocketComponents
-
getHandshaker
-
lifeCycleStopping
- Specified by:
lifeCycleStoppingin interfaceLifeCycle.Listener
-
clear
public void clear() -
dump
Description 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.- Specified by:
dumpin interfaceDumpable- Parameters:
out- The appendable to dump toindent- The indent to apply after any new lines.- Throws:
IOException- if unable to write to Appendable
-
getWebSocketNegotiator
-
getWebSocketCreator
-
addMapping
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- the pathspec to respond oncreator- the websocket creator to activate on the provided mapping.factory- the factory to use to create a FrameHandler for the websocket.customizer- the customizer to use to customize the WebSocket session.- Throws:
WebSocketException
-
addMapping
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- the pathspec to respond onnegotiator- the WebSocketNegotiator to use to create a FrameHandler for the websocket.- Throws:
WebSocketException
-
removeMapping
-
getMatchedNegotiator
public WebSocketNegotiator getMatchedNegotiator(Request request, BiConsumer<Request, PathSpec> consumer) Returns the mapped
WebSocketNegotiatorif there is a match of givenrequestagainst aregistered mapping, otherwise returnsnullif there is no match.If there is a match, the given consumer is invoked with the
PathSpecthat matched so that, for example, it can be stored as a request attribute for later usage. This is important in case ofUriTemplatePathSpec, where applications may want to extract the values of the template groups.- Parameters:
request- the request to matchconsumer- the consumer to invoke in case of match- Returns:
- the
WebSocketNegotiatorif there is a match, ornullif there is no match
-
upgrade
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
trueif 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. Returnsfalseif a response is not generated and the caller is responsible for generating a response and completing the callback.- Parameters:
request- the requestresponse- the responsecallback- the callbackdefaultCustomizer- the customizer- Returns:
- true if the WebSocket upgrade was accepted
- Throws:
WebSocketException- there is an error during the upgrade
-
upgrade
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
trueif 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. Returnsfalseif a response is not generated and the caller is responsible for generating a response and completing the callback.- Parameters:
negotiator- the negotiatorrequest- the requestresponse- the responsecallback- the callbackdefaultCustomizer- the customizer- Returns:
- true if the WebSocket upgrade was accepted
- Throws:
WebSocketException- there is an error during the upgrade
-