Class JakartaWebSocketUpgrader
java.lang.Object
io.micronaut.servlet.websocket.JakartaWebSocketUpgrader
- All Implemented Interfaces:
ServletWebSocketUpgrader
@Internal
@Singleton
@Requires(classes={jakarta.websocket.server.ServerContainer.class,io.micronaut.websocket.annotation.ServerWebSocket.class}) @Requires(property="micronaut.servlet.websocket.enabled",notEquals="false",defaultValue="true")
public final class JakartaWebSocketUpgrader
extends Object
implements ServletWebSocketUpgrader
Switches a matched upgrade request over to the servlet container's Jakarta WebSocket
implementation.
No endpoint is ever registered with the container, so the container's own upgrade
filter never matches and can never bypass the Micronaut filter chain. Instead a
ServerEndpointConfig is built for the connection at hand and handed to
ServerContainer.upgradeHttpToWebSocket(Object, Object, ServerEndpointConfig, Map), which Jetty, Tomcat and Undertow all
implement as of Jakarta WebSocket 2.1.
- Since:
- 6.2.0
- Author:
- graemerocher
-
Field Summary
Fields inherited from interface ServletWebSocketUpgrader
WEBSOCKET -
Constructor Summary
ConstructorsConstructorDescriptionJakartaWebSocketUpgrader(io.micronaut.context.BeanContext beanContext, ServletWebSocketSupport support, ServletWebSocketConfiguration configuration, io.micronaut.http.server.HttpServerConfiguration serverConfiguration, io.micronaut.http.server.util.HttpHostResolver httpHostResolver) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidupgrade(ServletExchange<?, ?> exchange, io.micronaut.http.HttpRequest<?> request, io.micronaut.web.router.UriRouteMatch<?, ?> routeMatch, io.micronaut.http.HttpResponse<?> handshakeResponse) Switch the given exchange over to the WebSocket protocol.
-
Constructor Details
-
JakartaWebSocketUpgrader
public JakartaWebSocketUpgrader(io.micronaut.context.BeanContext beanContext, ServletWebSocketSupport support, ServletWebSocketConfiguration configuration, io.micronaut.http.server.HttpServerConfiguration serverConfiguration, io.micronaut.http.server.util.HttpHostResolver httpHostResolver) Default constructor.- Parameters:
beanContext- The bean contextsupport- The shared WebSocket servicesconfiguration- The WebSocket configurationserverConfiguration- The server configuration, used for the CORS policyhttpHostResolver- Resolves the host of the handshake, so a same-origin socket is recognised
-
-
Method Details
-
upgrade
public void upgrade(ServletExchange<?, ?> exchange, io.micronaut.http.HttpRequest<?> request, io.micronaut.web.router.UriRouteMatch<?, throws Exception?> routeMatch, io.micronaut.http.HttpResponse<?> handshakeResponse) Description copied from interface:ServletWebSocketUpgraderSwitch the given exchange over to the WebSocket protocol.Implementations are invoked on the container thread that is dispatching the request and before any asynchronous processing has been started, since servlet containers require the upgrade to happen while the original request is still being dispatched.
- Specified by:
upgradein interfaceServletWebSocketUpgrader- Parameters:
exchange- The exchange being upgradedrequest- The originating HTTP requestrouteMatch- The matched WebSocket routehandshakeResponse- The response produced by the Micronaut filter chain, any headers of which should be carried over to the handshake response- Throws:
Exception- if the upgrade cannot be performed
-