From f69d3f0791056677c02a4e1c66790ad147a9b325 Mon Sep 17 00:00:00 2001 From: Grzegorz Grzybek Date: Fri, 16 Jun 2023 09:43:37 +0200 Subject: [PATCH] [#1802] Switch pax-web-tomcat-websocket from javax to jakarta --- pax-web-tomcat-websocket/pom.xml | 61 ++++++++++--------- .../EmbeddedTomcatWebSocketsTest.java | 57 +++++++++-------- 2 files changed, 60 insertions(+), 58 deletions(-) diff --git a/pax-web-tomcat-websocket/pom.xml b/pax-web-tomcat-websocket/pom.xml index b9a7feb07f..5279647cfe 100644 --- a/pax-web-tomcat-websocket/pom.xml +++ b/pax-web-tomcat-websocket/pom.xml @@ -45,14 +45,16 @@ javax.naming, javax.net.ssl, - javax.servlet;version="[3.1,5)", - javax.servlet.annotation;version="[3.1,5)", - javax.servlet.http;version="[3.1,5)", - javax.websocket;version="[1.1,2)", - javax.websocket.server;version="[1.1,2)", + + jakarta.servlet;version="[6,7)", + jakarta.servlet.annotation;version="[6,7)", + jakarta.servlet.http;version="[6,7)", + + jakarta.websocket;version="[2.1,3)", + jakarta.websocket.server;version="[2.1,3)", org.apache.coyote.http11.upgrade, - org.apache.juli.logging;version="[9.0,10)", + org.apache.juli.logging;version="[10.0,11)", org.apache.tomcat;version="${dependency.org.apache.tomcat}", @@ -89,8 +91,13 @@ - + + + jakarta.annotation + jakarta.annotation-api + provided + jakarta.servlet jakarta.servlet-api @@ -101,6 +108,11 @@ jakarta.websocket-api provided + + jakarta.websocket + jakarta.websocket-client-api + provided + @@ -129,7 +141,7 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-slf4j2-impl test @@ -144,8 +156,18 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.assertj + assertj-core test @@ -156,23 +178,4 @@ - - - jdk11 - - [9,) - - - - - - - jakarta.annotation - jakarta.annotation-api - - - - - - diff --git a/pax-web-tomcat-websocket/src/test/java/org/ops4j/pax/web/service/tomcat/websocket/EmbeddedTomcatWebSocketsTest.java b/pax-web-tomcat-websocket/src/test/java/org/ops4j/pax/web/service/tomcat/websocket/EmbeddedTomcatWebSocketsTest.java index 1142357ed6..61a6e47d89 100644 --- a/pax-web-tomcat-websocket/src/test/java/org/ops4j/pax/web/service/tomcat/websocket/EmbeddedTomcatWebSocketsTest.java +++ b/pax-web-tomcat-websocket/src/test/java/org/ops4j/pax/web/service/tomcat/websocket/EmbeddedTomcatWebSocketsTest.java @@ -24,19 +24,19 @@ import java.util.Map; import java.util.ServiceLoader; import java.util.Set; -import javax.websocket.ClientEndpointConfig; -import javax.websocket.ContainerProvider; -import javax.websocket.Endpoint; -import javax.websocket.EndpointConfig; -import javax.websocket.OnMessage; -import javax.websocket.OnOpen; -import javax.websocket.RemoteEndpoint; -import javax.websocket.Session; -import javax.websocket.WebSocketContainer; -import javax.websocket.server.ServerApplicationConfig; -import javax.websocket.server.ServerContainer; -import javax.websocket.server.ServerEndpoint; -import javax.websocket.server.ServerEndpointConfig; +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.ContainerProvider; +import jakarta.websocket.Endpoint; +import jakarta.websocket.EndpointConfig; +import jakarta.websocket.OnMessage; +import jakarta.websocket.OnOpen; +import jakarta.websocket.RemoteEndpoint; +import jakarta.websocket.Session; +import jakarta.websocket.WebSocketContainer; +import jakarta.websocket.server.ServerApplicationConfig; +import jakarta.websocket.server.ServerContainer; +import jakarta.websocket.server.ServerEndpoint; +import jakarta.websocket.server.ServerEndpointConfig; import org.apache.catalina.Context; import org.apache.catalina.Engine; @@ -58,28 +58,27 @@ import org.apache.commons.io.FileUtils; import org.apache.tomcat.websocket.Constants; import org.apache.tomcat.websocket.server.WsSci; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.bridge.SLF4JBridgeHandler; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class EmbeddedTomcatWebSocketsTest { public static final Logger LOG = LoggerFactory.getLogger(EmbeddedTomcatWebSocketsTest.class); - @BeforeClass + @BeforeAll public static void initClass() { SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); } - @AfterClass + @AfterAll public static void cleanupClass() { SLF4JBridgeHandler.uninstall(); } @@ -143,24 +142,24 @@ public void webSockets() throws Exception { LOG.info("Local port after start: {}", connector.getLocalPort()); - // javax.websocket.Endpoint - A logical websocket endpoint to handle endpoint's lifecycle endpoints + // jakarta.websocket.Endpoint - A logical websocket endpoint to handle endpoint's lifecycle endpoints // There is one instance per application per VM of the Endpoint class to represent the logical endpoint // per connected peer (unless special configuration is specified by - // javax.websocket.server.ServerEndpointConfig.Configurator.getEndpointInstance()) implementation + // jakarta.websocket.server.ServerEndpointConfig.Configurator.getEndpointInstance()) implementation // - // javax.websocket.Session - models the sequence of interactions between an endpoint and each of its peers + // jakarta.websocket.Session - models the sequence of interactions between an endpoint and each of its peers // the interaction begins with onOpen() method called on an Endpoint // - // javax.websocket.MessageHandler - is registered on a Session object to handle messages between open and + // jakarta.websocket.MessageHandler - is registered on a Session object to handle messages between open and // close events. There may be only one MessageHandler per type of message (text, binary, pong) // The API forces implementations to get the MessageHandler’s type parameter in runtime, so it's // not possible to pass lambdas // - // javax.websocket.RemoteEndpoint - models a peer of a Session for an Endpoint + // jakarta.websocket.RemoteEndpoint - models a peer of a Session for an Endpoint // - // javax.websocket.WebSocketContainer - websocket implementation used to deploy endpoints. In server + // jakarta.websocket.WebSocketContainer - websocket implementation used to deploy endpoints. In server // deployments, there's one instance per application per VM. In client deployments, an instance is - // obtained using ServiceLocator and javax.websocket.ContainerProvider.class service + // obtained using ServiceLocator and jakarta.websocket.ContainerProvider.class service // (in Tomcat it's org.apache.tomcat.websocket.WsContainerProvider) // coniguration (chapter 3) includes: @@ -190,7 +189,7 @@ public void beforeRequest(Map> headers) { URI.create("ws://localhost:" + connector.getLocalPort() + "/endpoint1")); ServerContainer sc = (ServerContainer) context.getServletContext().getAttribute(ServerContainer.class.getName()); - assertThat(sc.getClass().getName(), equalTo("org.apache.tomcat.websocket.server.WsServerContainer")); + assertThat(sc.getClass().getName()).isEqualTo("org.apache.tomcat.websocket.server.WsServerContainer"); sc.addEndpoint(MyAnnotatedEndpoint.class); container.connectToServer(new MyClientEndpoint("c2"), config,