Jakarta EE 9 migration
Upgrades many dependency declarations; removes old EJB 2.x support and outdated Servlet-based integrations (Commons FileUpload, FreeMarker JSP support, Tiles). Closes gh-22093 Closes gh-25354 Closes gh-26185 Closes gh-27423 See gh-27424
This commit is contained in:
@@ -383,7 +383,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
|
||||
public Validator webFluxValidator() {
|
||||
Validator validator = getValidator();
|
||||
if (validator == null) {
|
||||
if (ClassUtils.isPresent("javax.validation.Validator", getClass().getClassLoader())) {
|
||||
if (ClassUtils.isPresent("jakarta.validation.Validator", getClass().getClassLoader())) {
|
||||
Class<?> clazz;
|
||||
try {
|
||||
String name = "org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean";
|
||||
|
||||
@@ -51,7 +51,7 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
* constructor and then added to the model. Once created the attribute is
|
||||
* populated via data binding to the request (form data, query params).
|
||||
* Validation also may be applied if the argument is annotated with
|
||||
* {@code @javax.validation.Valid} or Spring's own
|
||||
* {@code @jakarta.validation.Valid} or Spring's own
|
||||
* {@code @org.springframework.validation.annotation.Validated}.
|
||||
*
|
||||
* <p>When this handler is created with {@code useDefaultResolution=true}
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.web.server.ServerWebInputException;
|
||||
* body of the request through a compatible {@code HttpMessageReader}.
|
||||
*
|
||||
* <p>An {@code @RequestBody} method argument is also validated if it is
|
||||
* annotated with {@code @javax.validation.Valid} or
|
||||
* annotated with {@code @jakarta.validation.Valid} or
|
||||
* {@link org.springframework.validation.annotation.Validated}. Validation
|
||||
* failure results in an {@link ServerWebInputException}.
|
||||
*
|
||||
|
||||
@@ -296,7 +296,7 @@ public class RedirectView extends AbstractUrlBasedView {
|
||||
|
||||
/**
|
||||
* Whether the given targetUrl has a host that is a "foreign" system in which
|
||||
* case {@link javax.servlet.http.HttpServletResponse#encodeRedirectURL} will not be applied.
|
||||
* case {@link jakarta.servlet.http.HttpServletResponse#encodeRedirectURL} will not be applied.
|
||||
* This method returns {@code true} if the {@link #setHosts(String[])}
|
||||
* property is configured and the target URL has a host that does not match.
|
||||
* @param targetUrl the target redirect URL
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.reactive.socket.adapter;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
import org.eclipse.jetty.websocket.api.extensions.Frame;
|
||||
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.reactive.socket.CloseStatus;
|
||||
import org.springframework.web.reactive.socket.WebSocketHandler;
|
||||
import org.springframework.web.reactive.socket.WebSocketMessage;
|
||||
import org.springframework.web.reactive.socket.WebSocketMessage.Type;
|
||||
import org.springframework.web.reactive.socket.WebSocketSession;
|
||||
|
||||
/**
|
||||
* Identical to {@link JettyWebSocketHandlerAdapter}, only excluding the
|
||||
* {@code onWebSocketFrame} method, since the {@link Frame} argument has moved
|
||||
* to a different package in Jetty 10.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.3.4
|
||||
*/
|
||||
@WebSocket
|
||||
public class Jetty10WebSocketHandlerAdapter {
|
||||
|
||||
private final WebSocketHandler delegateHandler;
|
||||
|
||||
private final Function<Session, JettyWebSocketSession> sessionFactory;
|
||||
|
||||
@Nullable
|
||||
private JettyWebSocketSession delegateSession;
|
||||
|
||||
|
||||
public Jetty10WebSocketHandlerAdapter(WebSocketHandler handler,
|
||||
Function<Session, JettyWebSocketSession> sessionFactory) {
|
||||
|
||||
Assert.notNull(handler, "WebSocketHandler is required");
|
||||
Assert.notNull(sessionFactory, "'sessionFactory' is required");
|
||||
this.delegateHandler = handler;
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onWebSocketConnect(Session session) {
|
||||
this.delegateSession = this.sessionFactory.apply(session);
|
||||
this.delegateHandler.handle(this.delegateSession)
|
||||
.checkpoint(session.getUpgradeRequest().getRequestURI() + " [JettyWebSocketHandlerAdapter]")
|
||||
.subscribe(this.delegateSession);
|
||||
}
|
||||
|
||||
@OnWebSocketMessage
|
||||
public void onWebSocketText(String message) {
|
||||
if (this.delegateSession != null) {
|
||||
WebSocketMessage webSocketMessage = toMessage(Type.TEXT, message);
|
||||
this.delegateSession.handleMessage(webSocketMessage.getType(), webSocketMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@OnWebSocketMessage
|
||||
public void onWebSocketBinary(byte[] message, int offset, int length) {
|
||||
if (this.delegateSession != null) {
|
||||
ByteBuffer buffer = ByteBuffer.wrap(message, offset, length);
|
||||
WebSocketMessage webSocketMessage = toMessage(Type.BINARY, buffer);
|
||||
this.delegateSession.handleMessage(webSocketMessage.getType(), webSocketMessage);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: onWebSocketFrame can't be declared without compiling against Jetty 10
|
||||
// Jetty 10: org.eclipse.jetty.websocket.api.Frame
|
||||
// Jetty 9: org.eclipse.jetty.websocket.api.extensions.Frame
|
||||
//
|
||||
// private static final ByteBuffer EMPTY_PAYLOAD = ByteBuffer.wrap(new byte[0]);
|
||||
//
|
||||
// @OnWebSocketFrame
|
||||
// public void onWebSocketFrame(Frame frame) {
|
||||
// if (this.delegateSession != null) {
|
||||
// if (OpCode.PONG == frame.getOpCode()) {
|
||||
// ByteBuffer buffer = (frame.getPayload() != null ? frame.getPayload() : EMPTY_PAYLOAD);
|
||||
// WebSocketMessage webSocketMessage = toMessage(Type.PONG, buffer);
|
||||
// this.delegateSession.handleMessage(webSocketMessage.getType(), webSocketMessage);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private <T> WebSocketMessage toMessage(Type type, T message) {
|
||||
WebSocketSession session = this.delegateSession;
|
||||
Assert.state(session != null, "Cannot create message without a session");
|
||||
if (Type.TEXT.equals(type)) {
|
||||
byte[] bytes = ((String) message).getBytes(StandardCharsets.UTF_8);
|
||||
DataBuffer buffer = session.bufferFactory().wrap(bytes);
|
||||
return new WebSocketMessage(Type.TEXT, buffer);
|
||||
}
|
||||
else if (Type.BINARY.equals(type)) {
|
||||
DataBuffer buffer = session.bufferFactory().wrap((ByteBuffer) message);
|
||||
return new WebSocketMessage(Type.BINARY, buffer);
|
||||
}
|
||||
else if (Type.PONG.equals(type)) {
|
||||
DataBuffer buffer = session.bufferFactory().wrap((ByteBuffer) message);
|
||||
return new WebSocketMessage(Type.PONG, buffer);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unexpected message type: " + message);
|
||||
}
|
||||
}
|
||||
|
||||
@OnWebSocketClose
|
||||
public void onWebSocketClose(int statusCode, String reason) {
|
||||
if (this.delegateSession != null) {
|
||||
this.delegateSession.handleClose(CloseStatus.create(statusCode, reason));
|
||||
}
|
||||
}
|
||||
|
||||
@OnWebSocketError
|
||||
public void onWebSocketError(Throwable cause) {
|
||||
if (this.delegateSession != null) {
|
||||
this.delegateSession.handleError(cause);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.Frame;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
@@ -27,8 +28,7 @@ import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
import org.eclipse.jetty.websocket.api.extensions.Frame;
|
||||
import org.eclipse.jetty.websocket.common.OpCode;
|
||||
import org.eclipse.jetty.websocket.core.OpCode;
|
||||
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -20,11 +20,11 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.PongMessage;
|
||||
import javax.websocket.Session;
|
||||
import jakarta.websocket.CloseReason;
|
||||
import jakarta.websocket.Endpoint;
|
||||
import jakarta.websocket.EndpointConfig;
|
||||
import jakarta.websocket.PongMessage;
|
||||
import jakarta.websocket.Session;
|
||||
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -20,12 +20,11 @@ import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.CloseReason.CloseCodes;
|
||||
import javax.websocket.SendHandler;
|
||||
import javax.websocket.SendResult;
|
||||
import javax.websocket.Session;
|
||||
|
||||
import jakarta.websocket.CloseReason;
|
||||
import jakarta.websocket.CloseReason.CloseCodes;
|
||||
import jakarta.websocket.SendHandler;
|
||||
import jakarta.websocket.SendResult;
|
||||
import jakarta.websocket.Session;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.Sinks;
|
||||
|
||||
@@ -38,7 +37,7 @@ import org.springframework.web.reactive.socket.WebSocketSession;
|
||||
|
||||
/**
|
||||
* Spring {@link WebSocketSession} adapter for a standard Java (JSR 356)
|
||||
* {@link javax.websocket.Session}.
|
||||
* {@link jakarta.websocket.Session}.
|
||||
*
|
||||
* @author Violeta Georgieva
|
||||
* @author Rossen Stoyanchev
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.springframework.web.reactive.socket.adapter;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
||||
|
||||
import javax.websocket.Session;
|
||||
|
||||
import jakarta.websocket.Session;
|
||||
import org.apache.tomcat.websocket.WsSession;
|
||||
import reactor.core.publisher.Sinks;
|
||||
|
||||
@@ -29,7 +28,7 @@ import org.springframework.web.reactive.socket.WebSocketSession;
|
||||
|
||||
/**
|
||||
* Spring {@link WebSocketSession} adapter for Tomcat's
|
||||
* {@link javax.websocket.Session}.
|
||||
* {@link jakarta.websocket.Session}.
|
||||
*
|
||||
* @author Violeta Georgieva
|
||||
* @since 5.0
|
||||
|
||||
@@ -17,29 +17,22 @@
|
||||
package org.springframework.web.reactive.socket.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.client.io.UpgradeListener;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.Sinks;
|
||||
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.reactive.socket.HandshakeInfo;
|
||||
import org.springframework.web.reactive.socket.WebSocketHandler;
|
||||
import org.springframework.web.reactive.socket.adapter.ContextWebSocketHandler;
|
||||
import org.springframework.web.reactive.socket.adapter.Jetty10WebSocketHandlerAdapter;
|
||||
import org.springframework.web.reactive.socket.adapter.JettyWebSocketHandlerAdapter;
|
||||
import org.springframework.web.reactive.socket.adapter.JettyWebSocketSession;
|
||||
|
||||
@@ -54,37 +47,23 @@ import org.springframework.web.reactive.socket.adapter.JettyWebSocketSession;
|
||||
*
|
||||
* @author Violeta Georgieva
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
* @since 5.0
|
||||
*/
|
||||
public class JettyWebSocketClient implements WebSocketClient, Lifecycle {
|
||||
|
||||
private static ClassLoader loader = JettyWebSocketClient.class.getClassLoader();
|
||||
|
||||
private static final boolean jetty10Present;
|
||||
|
||||
static {
|
||||
jetty10Present = ClassUtils.isPresent(
|
||||
"org.eclipse.jetty.websocket.client.JettyUpgradeListener", loader);
|
||||
}
|
||||
|
||||
|
||||
private static final Log logger = LogFactory.getLog(JettyWebSocketClient.class);
|
||||
|
||||
|
||||
private final org.eclipse.jetty.websocket.client.WebSocketClient jettyClient;
|
||||
|
||||
private final boolean externallyManaged;
|
||||
|
||||
private final UpgradeHelper upgradeHelper =
|
||||
(jetty10Present ? new Jetty10UpgradeHelper() : new Jetty9UpgradeHelper());
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor that creates and manages an instance of a Jetty
|
||||
* {@link org.eclipse.jetty.websocket.client.WebSocketClient WebSocketClient}.
|
||||
* The instance can be obtained with {@link #getJettyClient()} for further
|
||||
* configuration.
|
||||
*
|
||||
* <p><strong>Note: </strong> When this constructor is used {@link Lifecycle}
|
||||
* methods of this class are delegated to the Jetty {@code WebSocketClient}.
|
||||
*/
|
||||
@@ -96,7 +75,6 @@ public class JettyWebSocketClient implements WebSocketClient, Lifecycle {
|
||||
/**
|
||||
* Constructor that accepts an existing instance of a Jetty
|
||||
* {@link org.eclipse.jetty.websocket.client.WebSocketClient WebSocketClient}.
|
||||
*
|
||||
* <p><strong>Note: </strong> Use of this constructor implies the Jetty
|
||||
* {@code WebSocketClient} is externally managed and hence {@link Lifecycle}
|
||||
* methods of this class are not delegated to it.
|
||||
@@ -165,8 +143,13 @@ public class JettyWebSocketClient implements WebSocketClient, Lifecycle {
|
||||
url, ContextWebSocketHandler.decorate(handler, contextView), completionSink);
|
||||
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||
request.setSubProtocols(handler.getSubProtocols());
|
||||
return this.upgradeHelper.upgrade(
|
||||
this.jettyClient, jettyHandler, url, request, headers, completionSink);
|
||||
try {
|
||||
this.jettyClient.connect(jettyHandler, url, request);
|
||||
return completionSink.asMono();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -175,9 +158,7 @@ public class JettyWebSocketClient implements WebSocketClient, Lifecycle {
|
||||
HandshakeInfo info = createHandshakeInfo(url, session);
|
||||
return new JettyWebSocketSession(session, info, DefaultDataBufferFactory.sharedInstance, completion);
|
||||
};
|
||||
return (jetty10Present ?
|
||||
new Jetty10WebSocketHandlerAdapter(handler, sessionFactory) :
|
||||
new JettyWebSocketHandlerAdapter(handler, sessionFactory));
|
||||
return new JettyWebSocketHandlerAdapter(handler, sessionFactory);
|
||||
}
|
||||
|
||||
private HandshakeInfo createHandshakeInfo(URI url, Session jettySession) {
|
||||
@@ -187,80 +168,4 @@ public class JettyWebSocketClient implements WebSocketClient, Lifecycle {
|
||||
return new HandshakeInfo(url, headers, Mono.empty(), protocol);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encapsulate incompatible changes between Jetty 9.4 and 10.
|
||||
*/
|
||||
private interface UpgradeHelper {
|
||||
|
||||
Mono<Void> upgrade(org.eclipse.jetty.websocket.client.WebSocketClient jettyClient,
|
||||
Object jettyHandler, URI url, ClientUpgradeRequest request, HttpHeaders headers,
|
||||
Sinks.Empty<Void> completionSink);
|
||||
}
|
||||
|
||||
|
||||
private static class Jetty9UpgradeHelper implements UpgradeHelper {
|
||||
|
||||
@Override
|
||||
public Mono<Void> upgrade(org.eclipse.jetty.websocket.client.WebSocketClient jettyClient,
|
||||
Object jettyHandler, URI url, ClientUpgradeRequest request, HttpHeaders headers,
|
||||
Sinks.Empty<Void> completionSink) {
|
||||
|
||||
try {
|
||||
jettyClient.connect(jettyHandler, url, request, new DefaultUpgradeListener(headers));
|
||||
return completionSink.asMono();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class DefaultUpgradeListener implements UpgradeListener {
|
||||
|
||||
private final HttpHeaders headers;
|
||||
|
||||
|
||||
public DefaultUpgradeListener(HttpHeaders headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHandshakeRequest(UpgradeRequest request) {
|
||||
this.headers.forEach(request::setHeader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHandshakeResponse(UpgradeResponse response) {
|
||||
}
|
||||
}
|
||||
|
||||
private static class Jetty10UpgradeHelper implements UpgradeHelper {
|
||||
|
||||
// On Jetty 9 returns Future, on Jetty 10 returns CompletableFuture
|
||||
private static final Method connectMethod;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class<?> type = loader.loadClass("org.eclipse.jetty.websocket.client.WebSocketClient");
|
||||
connectMethod = type.getMethod("connect", Object.class, URI.class, ClientUpgradeRequest.class);
|
||||
}
|
||||
catch (ClassNotFoundException | NoSuchMethodException ex) {
|
||||
throw new IllegalStateException("No compatible Jetty version found", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> upgrade(org.eclipse.jetty.websocket.client.WebSocketClient jettyClient,
|
||||
Object jettyHandler, URI url, ClientUpgradeRequest request, HttpHeaders headers,
|
||||
Sinks.Empty<Void> completionSink) {
|
||||
|
||||
// TODO: pass JettyUpgradeListener argument to set headers from HttpHeaders (like we do for Jetty 9)
|
||||
// which would require a JDK Proxy since it is new in Jetty 10
|
||||
|
||||
ReflectionUtils.invokeMethod(connectMethod, jettyClient, jettyHandler, url, request);
|
||||
return completionSink.asMono();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,14 +20,13 @@ import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.websocket.ClientEndpointConfig;
|
||||
import javax.websocket.ClientEndpointConfig.Configurator;
|
||||
import javax.websocket.ContainerProvider;
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.HandshakeResponse;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
import jakarta.websocket.ClientEndpointConfig;
|
||||
import jakarta.websocket.ClientEndpointConfig.Configurator;
|
||||
import jakarta.websocket.ContainerProvider;
|
||||
import jakarta.websocket.Endpoint;
|
||||
import jakarta.websocket.HandshakeResponse;
|
||||
import jakarta.websocket.Session;
|
||||
import jakarta.websocket.WebSocketContainer;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package org.springframework.web.reactive.socket.client;
|
||||
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
import jakarta.websocket.Session;
|
||||
import jakarta.websocket.WebSocketContainer;
|
||||
import org.apache.tomcat.websocket.WsWebSocketContainer;
|
||||
import reactor.core.publisher.Sinks;
|
||||
|
||||
|
||||
@@ -70,8 +70,6 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle {
|
||||
|
||||
private static final boolean jettyPresent;
|
||||
|
||||
private static final boolean jetty10Present;
|
||||
|
||||
private static final boolean undertowPresent;
|
||||
|
||||
private static final boolean reactorNettyPresent;
|
||||
@@ -79,8 +77,7 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle {
|
||||
static {
|
||||
ClassLoader loader = HandshakeWebSocketService.class.getClassLoader();
|
||||
tomcatPresent = ClassUtils.isPresent("org.apache.tomcat.websocket.server.WsHttpUpgradeHandler", loader);
|
||||
jettyPresent = ClassUtils.isPresent("org.eclipse.jetty.websocket.server.WebSocketServerFactory", loader);
|
||||
jetty10Present = ClassUtils.isPresent("org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer", loader);
|
||||
jettyPresent = ClassUtils.isPresent("org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer", loader);
|
||||
undertowPresent = ClassUtils.isPresent("io.undertow.websockets.WebSocketProtocolHandshakeHandler", loader);
|
||||
reactorNettyPresent = ClassUtils.isPresent("reactor.netty.http.server.HttpServerResponse", loader);
|
||||
}
|
||||
@@ -122,9 +119,6 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle {
|
||||
else if (jettyPresent) {
|
||||
className = "JettyRequestUpgradeStrategy";
|
||||
}
|
||||
else if (jetty10Present) {
|
||||
className = "Jetty10RequestUpgradeStrategy";
|
||||
}
|
||||
else if (undertowPresent) {
|
||||
className = "UndertowRequestUpgradeStrategy";
|
||||
}
|
||||
|
||||
@@ -21,16 +21,16 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.websocket.Decoder;
|
||||
import javax.websocket.Encoder;
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.Extension;
|
||||
import javax.websocket.server.ServerEndpointConfig;
|
||||
import jakarta.websocket.Decoder;
|
||||
import jakarta.websocket.Encoder;
|
||||
import jakarta.websocket.Endpoint;
|
||||
import jakarta.websocket.Extension;
|
||||
import jakarta.websocket.server.ServerEndpointConfig;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link javax.websocket.server.ServerEndpointConfig}
|
||||
* Default implementation of {@link jakarta.websocket.server.ServerEndpointConfig}
|
||||
* for use in {@code RequestUpgradeStrategy} implementations.
|
||||
*
|
||||
* @author Violeta Georgieva
|
||||
@@ -48,7 +48,7 @@ class DefaultServerEndpointConfig extends ServerEndpointConfig.Configurator
|
||||
|
||||
|
||||
/**
|
||||
* Constructor with a path and an {@code javax.websocket.Endpoint}.
|
||||
* Constructor with a path and an {@code jakarta.websocket.Endpoint}.
|
||||
* @param path the endpoint path
|
||||
* @param endpoint the endpoint instance
|
||||
*/
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.reactive.socket.server.upgrade;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.target.EmptyTargetSource;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.reactive.socket.HandshakeInfo;
|
||||
import org.springframework.web.reactive.socket.WebSocketHandler;
|
||||
import org.springframework.web.reactive.socket.adapter.ContextWebSocketHandler;
|
||||
import org.springframework.web.reactive.socket.adapter.Jetty10WebSocketHandlerAdapter;
|
||||
import org.springframework.web.reactive.socket.adapter.JettyWebSocketSession;
|
||||
import org.springframework.web.reactive.socket.server.RequestUpgradeStrategy;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
/**
|
||||
* A {@link RequestUpgradeStrategy} for use with Jetty 10.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.3.4
|
||||
*/
|
||||
public class Jetty10RequestUpgradeStrategy implements RequestUpgradeStrategy {
|
||||
|
||||
private static final Class<?> webSocketCreatorClass;
|
||||
|
||||
private static final Method getContainerMethod;
|
||||
|
||||
private static final Method upgradeMethod;
|
||||
|
||||
private static final Method setAcceptedSubProtocol;
|
||||
|
||||
static {
|
||||
ClassLoader loader = Jetty10RequestUpgradeStrategy.class.getClassLoader();
|
||||
try {
|
||||
webSocketCreatorClass = loader.loadClass("org.eclipse.jetty.websocket.server.JettyWebSocketCreator");
|
||||
|
||||
Class<?> type = loader.loadClass("org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer");
|
||||
getContainerMethod = type.getMethod("getContainer", ServletContext.class);
|
||||
Method upgrade = ReflectionUtils.findMethod(type, "upgrade", (Class<?>[]) null);
|
||||
Assert.state(upgrade != null, "Upgrade method not found");
|
||||
upgradeMethod = upgrade;
|
||||
|
||||
type = loader.loadClass("org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse");
|
||||
setAcceptedSubProtocol = type.getMethod("setAcceptedSubProtocol", String.class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("No compatible Jetty version found", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Mono<Void> upgrade(
|
||||
ServerWebExchange exchange, WebSocketHandler handler,
|
||||
@Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {
|
||||
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
|
||||
HttpServletRequest servletRequest = ServerHttpRequestDecorator.getNativeRequest(request);
|
||||
HttpServletResponse servletResponse = ServerHttpResponseDecorator.getNativeResponse(response);
|
||||
ServletContext servletContext = servletRequest.getServletContext();
|
||||
|
||||
HandshakeInfo handshakeInfo = handshakeInfoFactory.get();
|
||||
DataBufferFactory factory = response.bufferFactory();
|
||||
|
||||
// Trigger WebFlux preCommit actions and upgrade
|
||||
return exchange.getResponse().setComplete()
|
||||
.then(Mono.deferContextual(contextView -> {
|
||||
Jetty10WebSocketHandlerAdapter adapter = new Jetty10WebSocketHandlerAdapter(
|
||||
ContextWebSocketHandler.decorate(handler, contextView),
|
||||
session -> new JettyWebSocketSession(session, handshakeInfo, factory));
|
||||
|
||||
try {
|
||||
Object creator = createJettyWebSocketCreator(adapter, subProtocol);
|
||||
Object container = ReflectionUtils.invokeMethod(getContainerMethod, null, servletContext);
|
||||
ReflectionUtils.invokeMethod(upgradeMethod, container, creator, servletRequest, servletResponse);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
return Mono.empty();
|
||||
}));
|
||||
}
|
||||
|
||||
private static Object createJettyWebSocketCreator(
|
||||
Jetty10WebSocketHandlerAdapter adapter, @Nullable String protocol) {
|
||||
|
||||
ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE);
|
||||
factory.addInterface(webSocketCreatorClass);
|
||||
factory.addAdvice(new WebSocketCreatorInterceptor(adapter, protocol));
|
||||
return factory.getProxy();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Proxy for a JettyWebSocketCreator to supply the WebSocket handler and set the sub-protocol.
|
||||
*/
|
||||
private static class WebSocketCreatorInterceptor implements MethodInterceptor {
|
||||
|
||||
private final Jetty10WebSocketHandlerAdapter adapter;
|
||||
|
||||
@Nullable
|
||||
private final String protocol;
|
||||
|
||||
|
||||
public WebSocketCreatorInterceptor(
|
||||
Jetty10WebSocketHandlerAdapter adapter, @Nullable String protocol) {
|
||||
|
||||
this.adapter = adapter;
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object invoke(@NonNull MethodInvocation invocation) {
|
||||
if (this.protocol != null) {
|
||||
ReflectionUtils.invokeMethod(
|
||||
setAcceptedSubProtocol, invocation.getArguments()[2], this.protocol);
|
||||
}
|
||||
return this.adapter;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,26 +16,27 @@
|
||||
|
||||
package org.springframework.web.reactive.socket.server.upgrade;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.core.NamedThreadLocal;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.target.EmptyTargetSource;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.reactive.socket.HandshakeInfo;
|
||||
import org.springframework.web.reactive.socket.WebSocketHandler;
|
||||
import org.springframework.web.reactive.socket.adapter.ContextWebSocketHandler;
|
||||
@@ -45,102 +46,46 @@ import org.springframework.web.reactive.socket.server.RequestUpgradeStrategy;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
/**
|
||||
* A {@link RequestUpgradeStrategy} for use with Jetty.
|
||||
* A {@link RequestUpgradeStrategy} for Jetty 11.
|
||||
*
|
||||
* @author Violeta Georgieva
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
* @since 5.3.4
|
||||
*/
|
||||
public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Lifecycle {
|
||||
public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy {
|
||||
|
||||
private static final ThreadLocal<WebSocketHandlerContainer> adapterHolder =
|
||||
new NamedThreadLocal<>("JettyWebSocketHandlerAdapter");
|
||||
private static final Class<?> webSocketCreatorClass;
|
||||
|
||||
private static final Method getContainerMethod;
|
||||
|
||||
@Nullable
|
||||
private WebSocketPolicy webSocketPolicy;
|
||||
private static final Method upgradeMethod;
|
||||
|
||||
@Nullable
|
||||
private WebSocketServerFactory factory;
|
||||
private static final Method setAcceptedSubProtocol;
|
||||
|
||||
@Nullable
|
||||
private volatile ServletContext servletContext;
|
||||
static {
|
||||
// TODO: can switch to non-reflective implementation now
|
||||
|
||||
private volatile boolean running;
|
||||
ClassLoader loader = JettyRequestUpgradeStrategy.class.getClassLoader();
|
||||
try {
|
||||
webSocketCreatorClass = loader.loadClass("org.eclipse.jetty.websocket.server.JettyWebSocketCreator");
|
||||
|
||||
private final Object lifecycleMonitor = new Object();
|
||||
Class<?> type = loader.loadClass("org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer");
|
||||
getContainerMethod = type.getMethod("getContainer", ServletContext.class);
|
||||
Method upgrade = ReflectionUtils.findMethod(type, "upgrade", (Class<?>[]) null);
|
||||
Assert.state(upgrade != null, "Upgrade method not found");
|
||||
upgradeMethod = upgrade;
|
||||
|
||||
|
||||
/**
|
||||
* Configure a {@link WebSocketPolicy} to use to initialize
|
||||
* {@link WebSocketServerFactory}.
|
||||
* @param webSocketPolicy the WebSocket settings
|
||||
*/
|
||||
public void setWebSocketPolicy(WebSocketPolicy webSocketPolicy) {
|
||||
this.webSocketPolicy = webSocketPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured {@link WebSocketPolicy}, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public WebSocketPolicy getWebSocketPolicy() {
|
||||
return this.webSocketPolicy;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
synchronized (this.lifecycleMonitor) {
|
||||
ServletContext servletContext = this.servletContext;
|
||||
if (!isRunning() && servletContext != null) {
|
||||
try {
|
||||
this.factory = (this.webSocketPolicy != null ?
|
||||
new WebSocketServerFactory(servletContext, this.webSocketPolicy) :
|
||||
new WebSocketServerFactory(servletContext));
|
||||
this.factory.setCreator((request, response) -> {
|
||||
WebSocketHandlerContainer container = adapterHolder.get();
|
||||
String protocol = container.getProtocol();
|
||||
if (protocol != null) {
|
||||
response.setAcceptedSubProtocol(protocol);
|
||||
}
|
||||
return container.getAdapter();
|
||||
});
|
||||
this.factory.start();
|
||||
this.running = true;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Unable to start WebSocketServerFactory", ex);
|
||||
}
|
||||
}
|
||||
type = loader.loadClass("org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse");
|
||||
setAcceptedSubProtocol = type.getMethod("setAcceptedSubProtocol", String.class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("No compatible Jetty version found", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
synchronized (this.lifecycleMonitor) {
|
||||
if (isRunning()) {
|
||||
if (this.factory != null) {
|
||||
try {
|
||||
this.factory.stop();
|
||||
this.running = false;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Failed to stop WebSocketServerFactory", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return this.running;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,
|
||||
public Mono<Void> upgrade(
|
||||
ServerWebExchange exchange, WebSocketHandler handler,
|
||||
@Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {
|
||||
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
@@ -148,16 +93,11 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Life
|
||||
|
||||
HttpServletRequest servletRequest = ServerHttpRequestDecorator.getNativeRequest(request);
|
||||
HttpServletResponse servletResponse = ServerHttpResponseDecorator.getNativeResponse(response);
|
||||
ServletContext servletContext = servletRequest.getServletContext();
|
||||
|
||||
HandshakeInfo handshakeInfo = handshakeInfoFactory.get();
|
||||
DataBufferFactory factory = response.bufferFactory();
|
||||
|
||||
startLazily(servletRequest);
|
||||
|
||||
Assert.state(this.factory != null, "No WebSocketServerFactory available");
|
||||
boolean isUpgrade = this.factory.isUpgradeRequest(servletRequest, servletResponse);
|
||||
Assert.isTrue(isUpgrade, "Not a WebSocket handshake");
|
||||
|
||||
// Trigger WebFlux preCommit actions and upgrade
|
||||
return exchange.getResponse().setComplete()
|
||||
.then(Mono.deferContextual(contextView -> {
|
||||
@@ -166,51 +106,53 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Life
|
||||
session -> new JettyWebSocketSession(session, handshakeInfo, factory));
|
||||
|
||||
try {
|
||||
adapterHolder.set(new WebSocketHandlerContainer(adapter, subProtocol));
|
||||
this.factory.acceptWebSocket(servletRequest, servletResponse);
|
||||
Object creator = createJettyWebSocketCreator(adapter, subProtocol);
|
||||
Object container = ReflectionUtils.invokeMethod(getContainerMethod, null, servletContext);
|
||||
ReflectionUtils.invokeMethod(upgradeMethod, container, creator, servletRequest, servletResponse);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
catch (Exception ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
finally {
|
||||
adapterHolder.remove();
|
||||
}
|
||||
return Mono.empty();
|
||||
}));
|
||||
}
|
||||
|
||||
private void startLazily(HttpServletRequest request) {
|
||||
if (isRunning()) {
|
||||
return;
|
||||
}
|
||||
synchronized (this.lifecycleMonitor) {
|
||||
if (!isRunning()) {
|
||||
this.servletContext = request.getServletContext();
|
||||
start();
|
||||
}
|
||||
}
|
||||
private static Object createJettyWebSocketCreator(
|
||||
JettyWebSocketHandlerAdapter adapter, @Nullable String protocol) {
|
||||
|
||||
ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE);
|
||||
factory.addInterface(webSocketCreatorClass);
|
||||
factory.addAdvice(new WebSocketCreatorInterceptor(adapter, protocol));
|
||||
return factory.getProxy();
|
||||
}
|
||||
|
||||
|
||||
private static class WebSocketHandlerContainer {
|
||||
/**
|
||||
* Proxy for a JettyWebSocketCreator to supply the WebSocket handler and set the sub-protocol.
|
||||
*/
|
||||
private static class WebSocketCreatorInterceptor implements MethodInterceptor {
|
||||
|
||||
private final JettyWebSocketHandlerAdapter adapter;
|
||||
|
||||
@Nullable
|
||||
private final String protocol;
|
||||
|
||||
public WebSocketHandlerContainer(JettyWebSocketHandlerAdapter adapter, @Nullable String protocol) {
|
||||
|
||||
public WebSocketCreatorInterceptor(
|
||||
JettyWebSocketHandlerAdapter adapter, @Nullable String protocol) {
|
||||
|
||||
this.adapter = adapter;
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public JettyWebSocketHandlerAdapter getAdapter() {
|
||||
return this.adapter;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getProtocol() {
|
||||
return this.protocol;
|
||||
@Override
|
||||
public Object invoke(@NonNull MethodInvocation invocation) {
|
||||
if (this.protocol != null) {
|
||||
ReflectionUtils.invokeMethod(
|
||||
setAcceptedSubProtocol, invocation.getArguments()[2], this.protocol);
|
||||
}
|
||||
return this.adapter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,10 @@ package org.springframework.web.reactive.socket.server.upgrade;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.server.ServerContainer;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.websocket.Endpoint;
|
||||
import jakarta.websocket.server.ServerContainer;
|
||||
import org.apache.tomcat.websocket.server.WsServerContainer;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -51,7 +50,7 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
*/
|
||||
public class TomcatRequestUpgradeStrategy implements RequestUpgradeStrategy {
|
||||
|
||||
private static final String SERVER_CONTAINER_ATTR = "javax.websocket.server.ServerContainer";
|
||||
private static final String SERVER_CONTAINER_ATTR = "jakarta.websocket.server.ServerContainer";
|
||||
|
||||
|
||||
@Nullable
|
||||
@@ -72,7 +71,7 @@ public class TomcatRequestUpgradeStrategy implements RequestUpgradeStrategy {
|
||||
|
||||
/**
|
||||
* Exposes the underlying config option on
|
||||
* {@link javax.websocket.server.ServerContainer#setAsyncSendTimeout(long)}.
|
||||
* {@link jakarta.websocket.server.ServerContainer#setAsyncSendTimeout(long)}.
|
||||
*/
|
||||
public void setAsyncSendTimeout(Long timeoutInMillis) {
|
||||
this.asyncSendTimeout = timeoutInMillis;
|
||||
@@ -85,7 +84,7 @@ public class TomcatRequestUpgradeStrategy implements RequestUpgradeStrategy {
|
||||
|
||||
/**
|
||||
* Exposes the underlying config option on
|
||||
* {@link javax.websocket.server.ServerContainer#setDefaultMaxSessionIdleTimeout(long)}.
|
||||
* {@link jakarta.websocket.server.ServerContainer#setDefaultMaxSessionIdleTimeout(long)}.
|
||||
*/
|
||||
public void setMaxSessionIdleTimeout(Long timeoutInMillis) {
|
||||
this.maxSessionIdleTimeout = timeoutInMillis;
|
||||
@@ -98,7 +97,7 @@ public class TomcatRequestUpgradeStrategy implements RequestUpgradeStrategy {
|
||||
|
||||
/**
|
||||
* Exposes the underlying config option on
|
||||
* {@link javax.websocket.server.ServerContainer#setDefaultMaxTextMessageBufferSize(int)}.
|
||||
* {@link jakarta.websocket.server.ServerContainer#setDefaultMaxTextMessageBufferSize(int)}.
|
||||
*/
|
||||
public void setMaxTextMessageBufferSize(Integer bufferSize) {
|
||||
this.maxTextMessageBufferSize = bufferSize;
|
||||
@@ -111,7 +110,7 @@ public class TomcatRequestUpgradeStrategy implements RequestUpgradeStrategy {
|
||||
|
||||
/**
|
||||
* Exposes the underlying config option on
|
||||
* {@link javax.websocket.server.ServerContainer#setDefaultMaxBinaryMessageBufferSize(int)}.
|
||||
* {@link jakarta.websocket.server.ServerContainer#setDefaultMaxBinaryMessageBufferSize(int)}.
|
||||
*/
|
||||
public void setMaxBinaryMessageBufferSize(Integer bufferSize) {
|
||||
this.maxBinaryMessageBufferSize = bufferSize;
|
||||
@@ -163,7 +162,7 @@ public class TomcatRequestUpgradeStrategy implements RequestUpgradeStrategy {
|
||||
if (this.serverContainer == null) {
|
||||
Object container = request.getServletContext().getAttribute(SERVER_CONTAINER_ATTR);
|
||||
Assert.state(container instanceof WsServerContainer,
|
||||
"ServletContext attribute 'javax.websocket.server.ServerContainer' not found.");
|
||||
"ServletContext attribute 'jakarta.websocket.server.ServerContainer' not found.");
|
||||
this.serverContainer = (WsServerContainer) container;
|
||||
initServerContainer(this.serverContainer);
|
||||
}
|
||||
|
||||
@@ -23,9 +23,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,11 +51,11 @@ import org.springframework.http.codec.DecoderHttpMessageReader;
|
||||
import org.springframework.http.codec.FormHttpMessageReader;
|
||||
import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
||||
import org.springframework.http.codec.multipart.DefaultPartHttpMessageReader;
|
||||
import org.springframework.http.codec.multipart.FilePart;
|
||||
import org.springframework.http.codec.multipart.FormFieldPart;
|
||||
import org.springframework.http.codec.multipart.MultipartHttpMessageReader;
|
||||
import org.springframework.http.codec.multipart.Part;
|
||||
import org.springframework.http.codec.multipart.SynchronossPartHttpMessageReader;
|
||||
import org.springframework.http.codec.xml.Jaxb2XmlDecoder;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
@@ -89,7 +89,7 @@ public class BodyExtractorsTests {
|
||||
messageReaders.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
|
||||
messageReaders.add(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()));
|
||||
messageReaders.add(new FormHttpMessageReader());
|
||||
SynchronossPartHttpMessageReader partReader = new SynchronossPartHttpMessageReader();
|
||||
DefaultPartHttpMessageReader partReader = new DefaultPartHttpMessageReader();
|
||||
messageReaders.add(partReader);
|
||||
messageReaders.add(new MultipartHttpMessageReader(partReader));
|
||||
|
||||
|
||||
@@ -27,12 +27,11 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import io.reactivex.rxjava3.core.Flowable;
|
||||
import io.reactivex.rxjava3.core.Maybe;
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
@@ -21,9 +21,8 @@ import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -23,14 +23,13 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import io.reactivex.rxjava3.core.Completable;
|
||||
import io.reactivex.rxjava3.core.Flowable;
|
||||
import io.reactivex.rxjava3.core.Maybe;
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import jakarta.xml.bind.annotation.XmlElement;
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
Reference in New Issue
Block a user