Class WebsocketHandlerDecorator
- All Implemented Interfaces:
ParameterResolver<HasMessage>
,HandlerDecorator
SocketSession
.
This decorator supports @HandleWeb
-annotated methods that interact over WebSocket connections, and
transparently manages the lifecycle of SocketSession
instances. It implements both HandlerDecorator
and ParameterResolver
to provide the following capabilities:
-
Automatically upgrades incoming
WS_HANDSHAKE
requests to WebSocket sessions if the handler includes methods annotated withHandleSocketOpen
or similar, but does not explicitly handle the handshake itself. This ensures that endpoints which declare websocket handlers still result in a successful connection upgrade even without a dedicated handshake method. -
Delegates
WS_MESSAGE
requests to the associatedSocketSession
for message dispatch and response. -
Performs cleanup on
WS_CLOSE
requests, closing the session and invoking any associatedHandleSocketClose
handlers. -
Resolves
SocketSession
method parameters in applicable WebSocket handler methods.
This decorator also tracks open WebSocket sessions and ensures that message dispatch is session-aware. It works transparently with the Flux client’s message routing and tracking infrastructure.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HandlerDecorator
HandlerDecorator.MergedDecorator
-
Field Summary
Fields inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HandlerDecorator
noOp
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Handler
<DeserializingMessage> cleanUpOnClose
(Handler<DeserializingMessage> handler) protected Handler
<DeserializingMessage> closeOnError
(Handler<DeserializingMessage> handler) protected Handler
<DeserializingMessage> enableHandshake
(Handler<DeserializingMessage> handler, List<WebPattern> socketPatterns) protected DefaultSocketSession
protected Handler
<DeserializingMessage> handleRequest
(Handler<DeserializingMessage> handler) boolean
matches
(Parameter parameter, Annotation methodAnnotation, HasMessage value) Determines whether this resolver supports injecting aSocketSession
for the given method parameter.protected void
onAbort
(DefaultSocketSession session, int code) resolve
(Parameter p, Annotation methodAnnotation) Resolves aSocketSession
parameter from the currentHasMessage
context.wrap
(Handler<DeserializingMessage> handler) Wraps a websocket-compatible handler with websocket-specific functionality.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HandlerDecorator
andThen
Methods inherited from interface io.fluxcapacitor.common.handling.ParameterResolver
determinesSpecificity, filterMessage
-
Constructor Details
-
WebsocketHandlerDecorator
public WebsocketHandlerDecorator()
-
-
Method Details
-
resolve
Resolves aSocketSession
parameter from the currentHasMessage
context.The session is tracked per session ID and reused for subsequent requests over the same connection. If no session exists for the current message's session ID, a new one is created.
- Specified by:
resolve
in interfaceParameterResolver<HasMessage>
- Parameters:
p
- the method parameter being resolvedmethodAnnotation
- the handler method's annotation (e.g.@HandleWeb
)- Returns:
- a function that resolves the
SocketSession
from the message
-
getOrCreateSocketSession
-
matches
Determines whether this resolver supports injecting aSocketSession
for the given method parameter.The parameter must be assignable from
SocketSession
, and the method must be annotated withHandleWeb
(or a compatible meta-annotation).- Specified by:
matches
in interfaceParameterResolver<HasMessage>
- Parameters:
parameter
- the parameter being resolvedmethodAnnotation
- the annotation present on the handler methodvalue
- the current message- Returns:
true
if the parameter should be resolved by this resolver
-
onAbort
-
wrap
Wraps a websocket-compatible handler with websocket-specific functionality.If the target handler supports websocket patterns (e.g.,
WS_HANDSHAKE
orWS_MESSAGE
), it is wrapped with logic to support automatic handshake negotiation, websocket message dispatch, and session cleanup on close.- Specified by:
wrap
in interfaceHandlerDecorator
- Parameters:
handler
- the original handler- Returns:
- the wrapped handler with websocket support if applicable
-
enableHandshake
protected Handler<DeserializingMessage> enableHandshake(Handler<DeserializingMessage> handler, List<WebPattern> socketPatterns) -
handleRequest
-
closeOnError
-
cleanUpOnClose
-