Class MicronautWebSocketContainer
- All Implemented Interfaces:
jakarta.websocket.WebSocketContainer
WebSocketContainer of a Micronaut servlet application, for opening client
connections.
Inject it and call connectToServer(Class, URI) with a @ClientEndpoint
class compiled with the Micronaut servlet annotation processor. The connection is opened by
the servlet container's own client implementation, but the endpoint is a bean and its
handlers are invoked through the compiled bean metadata, so nothing is scanned or reflected
on. The handlers may take the container's Session, the EndpointConfig, the
Jakarta CloseReason and everything a Micronaut handler can take; a value an
@OnMessage method returns is sent to the peer; decoders, encoders and
configurator resolve as they do for a @ServerEndpoint.
A class that is not such a bean - one compiled without the processor - is handed to the
container as it is, which then instantiates and scans it reflectively, as it would on its own.
The programmatic Endpoint forms and the container settings are the container's.
Unlike ContainerProvider.getWebSocketContainer(), whose result depends on which
implementation ServiceLoader finds first, this bean is deterministic and is the
documented way to open a Jakarta client connection.
- Since:
- 6.2.0
- Author:
- graemerocher
-
Constructor Summary
ConstructorsConstructorDescriptionMicronautWebSocketContainer(io.micronaut.context.BeanContext beanContext, ServletWebSocketSupport support, WebSocketContainerHolder holder) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionjakarta.websocket.SessionconnectToServer(jakarta.websocket.Endpoint endpointInstance, jakarta.websocket.ClientEndpointConfig cec, URI path) jakarta.websocket.SessionconnectToServer(Class<?> annotatedEndpointClass, URI path) jakarta.websocket.SessionconnectToServer(Class<? extends jakarta.websocket.Endpoint> endpointClass, jakarta.websocket.ClientEndpointConfig cec, URI path) jakarta.websocket.SessionconnectToServer(Object annotatedEndpointInstance, URI path) longintlongintSet<jakarta.websocket.Extension> voidsetAsyncSendTimeout(long timeoutmillis) voidsetDefaultMaxBinaryMessageBufferSize(int max) voidsetDefaultMaxSessionIdleTimeout(long timeout) voidsetDefaultMaxTextMessageBufferSize(int max)
-
Constructor Details
-
MicronautWebSocketContainer
public MicronautWebSocketContainer(io.micronaut.context.BeanContext beanContext, ServletWebSocketSupport support, WebSocketContainerHolder holder) Default constructor.- Parameters:
beanContext- The bean contextsupport- The shared infrastructureholder- The servlet container's WebSocket container
-
-
Method Details
-
connectToServer
public jakarta.websocket.Session connectToServer(Class<?> annotatedEndpointClass, URI path) throws jakarta.websocket.DeploymentException, IOException - Specified by:
connectToServerin interfacejakarta.websocket.WebSocketContainer- Throws:
jakarta.websocket.DeploymentExceptionIOException
-
connectToServer
public jakarta.websocket.Session connectToServer(Object annotatedEndpointInstance, URI path) throws jakarta.websocket.DeploymentException, IOException - Specified by:
connectToServerin interfacejakarta.websocket.WebSocketContainer- Throws:
jakarta.websocket.DeploymentExceptionIOException
-
connectToServer
public jakarta.websocket.Session connectToServer(jakarta.websocket.Endpoint endpointInstance, jakarta.websocket.ClientEndpointConfig cec, URI path) throws jakarta.websocket.DeploymentException, IOException - Specified by:
connectToServerin interfacejakarta.websocket.WebSocketContainer- Throws:
jakarta.websocket.DeploymentExceptionIOException
-
connectToServer
public jakarta.websocket.Session connectToServer(Class<? extends jakarta.websocket.Endpoint> endpointClass, jakarta.websocket.ClientEndpointConfig cec, URI path) throws jakarta.websocket.DeploymentException, IOException The endpoint is instantiated without reflection when it can be - as a bean, through its introspection, or reflectively under the reflection policy, the way the components an endpoint declares are. Otherwise the container instantiates it itself, as it would on its own.
- Specified by:
connectToServerin interfacejakarta.websocket.WebSocketContainer- Throws:
jakarta.websocket.DeploymentExceptionIOException
-
getDefaultAsyncSendTimeout
public long getDefaultAsyncSendTimeout()- Specified by:
getDefaultAsyncSendTimeoutin interfacejakarta.websocket.WebSocketContainer
-
setAsyncSendTimeout
public void setAsyncSendTimeout(long timeoutmillis) - Specified by:
setAsyncSendTimeoutin interfacejakarta.websocket.WebSocketContainer
-
getDefaultMaxSessionIdleTimeout
public long getDefaultMaxSessionIdleTimeout()- Specified by:
getDefaultMaxSessionIdleTimeoutin interfacejakarta.websocket.WebSocketContainer
-
setDefaultMaxSessionIdleTimeout
public void setDefaultMaxSessionIdleTimeout(long timeout) - Specified by:
setDefaultMaxSessionIdleTimeoutin interfacejakarta.websocket.WebSocketContainer
-
getDefaultMaxBinaryMessageBufferSize
public int getDefaultMaxBinaryMessageBufferSize()- Specified by:
getDefaultMaxBinaryMessageBufferSizein interfacejakarta.websocket.WebSocketContainer
-
setDefaultMaxBinaryMessageBufferSize
public void setDefaultMaxBinaryMessageBufferSize(int max) - Specified by:
setDefaultMaxBinaryMessageBufferSizein interfacejakarta.websocket.WebSocketContainer
-
getDefaultMaxTextMessageBufferSize
public int getDefaultMaxTextMessageBufferSize()- Specified by:
getDefaultMaxTextMessageBufferSizein interfacejakarta.websocket.WebSocketContainer
-
setDefaultMaxTextMessageBufferSize
public void setDefaultMaxTextMessageBufferSize(int max) - Specified by:
setDefaultMaxTextMessageBufferSizein interfacejakarta.websocket.WebSocketContainer
-
getInstalledExtensions
- Specified by:
getInstalledExtensionsin interfacejakarta.websocket.WebSocketContainer
-