Class MicronautServerEndpoint
java.lang.Object
jakarta.websocket.Endpoint
io.micronaut.servlet.websocket.AbstractMicronautEndpoint
io.micronaut.servlet.websocket.MicronautServerEndpoint
The
Endpoint that adapts a connection the server accepted onto a
Micronaut @ServerWebSocket bean, or onto a Jakarta @ServerEndpoint the
annotation processor mapped onto one.
One instance exists per connection. All per-connection state arrives through the
EndpointConfig user properties, so the class also works on containers that
instantiate endpoints reflectively rather than through the configurator. The dispatch itself
is AbstractMicronautEndpoint's; this class adds what only a server connection has: the
upgrade request the handlers are bound against, the route's path variables, the session
registry and the open and close events.
- Since:
- 6.2.0
- Author:
- graemerocher
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe user property under which theWebSocketUpgradeContextis passed. -
Constructor Summary
ConstructorsConstructorDescriptionPublic no-argument constructor, required by containers that create endpoint instances reflectively rather than through the configurator. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyLimits(jakarta.websocket.Session session, @Nullable Integer declaredTextMax, @Nullable Integer declaredBinaryMax) Applies the payload limits.voidonOpen(jakarta.websocket.Session session, jakarta.websocket.EndpointConfig config) protected io.micronaut.core.propagation.PropagatedContextHandlers run with the upgrade request propagated, so thatServerRequestContext.currentRequest()resolves inside them.protected voidsessionClosed(ServletWebSocketSession session, boolean opened) Called once the session is closed and its close handler has run.protected voidsessionOpened(ServletWebSocketSession session) Called once the connection is set up, before the message handlers are registered and the open handler runs.Methods inherited from class AbstractMicronautEndpoint
closeQuietly, micronautSession, onClose, onError, open, openCompleted, openFailed, support, webSocketBean
-
Field Details
-
CONTEXT_PROPERTY
The user property under which theWebSocketUpgradeContextis passed.- See Also:
-
-
Constructor Details
-
MicronautServerEndpoint
public MicronautServerEndpoint()Public no-argument constructor, required by containers that create endpoint instances reflectively rather than through the configurator. The context is then read from theEndpointConfiguser properties instead.
-
-
Method Details
-
onOpen
public void onOpen(jakarta.websocket.Session session, jakarta.websocket.EndpointConfig config) - Specified by:
onOpenin classjakarta.websocket.Endpoint
-
propagatedContext
protected io.micronaut.core.propagation.PropagatedContext propagatedContext()Handlers run with the upgrade request propagated, so thatServerRequestContext.currentRequest()resolves inside them.- Specified by:
propagatedContextin classAbstractMicronautEndpoint- Returns:
- The propagated context
-
sessionOpened
Description copied from class:AbstractMicronautEndpointCalled once the connection is set up, before the message handlers are registered and the open handler runs. Nothing by default.- Overrides:
sessionOpenedin classAbstractMicronautEndpoint- Parameters:
session- The Micronaut session
-
sessionClosed
Description copied from class:AbstractMicronautEndpointCalled once the session is closed and its close handler has run.- Overrides:
sessionClosedin classAbstractMicronautEndpoint- Parameters:
session- The Micronaut sessionopened- Whether the session had reached the open event
-
applyLimits
protected void applyLimits(jakarta.websocket.Session session, @Nullable Integer declaredTextMax, @Nullable Integer declaredBinaryMax) Applies the payload limits. A Micronaut endpoint's one handler limits text and binary alike; a Jakarta endpoint declaresmaxMessageSizeper handler. A limit no handler declares is the configured one.- Overrides:
applyLimitsin classAbstractMicronautEndpoint- Parameters:
session- The container's sessiondeclaredTextMax- The text limit the text handler declares, ornulldeclaredBinaryMax- The binary limit the binary handler declares, ornull
-