Skip to content

Commit

Permalink
Issue #4568 - use jakarta.websocket for jetty-11
Browse files Browse the repository at this point in the history
- Update the jetty-11.0.x branch to use Jakarta WebSocket API.
- Rename websocket classes, variables and comments using javax to use jakarta instead.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts authored and olamy committed Mar 23, 2020
1 parent e37552b commit a7af698
Show file tree
Hide file tree
Showing 476 changed files with 2,849 additions and 2,495 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Expand Up @@ -116,7 +116,7 @@ def mavenBuild(jdk, cmdline, mvnName, junitPublishDisabled) {
mavenOpts: mavenOpts,
mavenLocalRepo: localRepo) {
// Some common Maven command line + provided command line
sh "mvn -Pci -V -B -e -fae -Dmaven.test.failure.ignore=true -Djetty.testtracker.log=true $cmdline -Dunix.socket.tmp=" + env.JENKINS_HOME
sh "mvn -Pci -Psnapshot-repositories -V -U -B -e -fae -Dmaven.test.failure.ignore=true -Djetty.testtracker.log=true $cmdline -Dunix.socket.tmp=" + env.JENKINS_HOME
}
}

Expand Down
4 changes: 2 additions & 2 deletions aggregates/jetty-all/pom.xml
Expand Up @@ -183,7 +183,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-javax-server</artifactId>
<artifactId>websocket-jakarta-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand All @@ -210,7 +210,7 @@
<!-- dependencies that jetty-all needs (some optional) -->
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-javax-websocket-api</artifactId>
<artifactId>jetty-jakarta-websocket-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
Expand Down
4 changes: 2 additions & 2 deletions aggregates/jetty-websocket-all/pom.xml
Expand Up @@ -113,7 +113,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-javax-server</artifactId>
<artifactId>websocket-jakarta-server</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
Expand Down Expand Up @@ -144,7 +144,7 @@
<!-- dependencies that jetty-all needs (some optional) -->
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-javax-websocket-api</artifactId>
<artifactId>jetty-jakarta-websocket-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion examples/embedded/pom.xml
Expand Up @@ -61,7 +61,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-javax-server</artifactId>
<artifactId>websocket-jakarta-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
Expand Up @@ -18,20 +18,19 @@

package org.eclipse.jetty.embedded;

import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

import jakarta.websocket.OnMessage;
import jakarta.websocket.Session;
import jakarta.websocket.server.ServerEndpoint;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer;
import org.eclipse.jetty.websocket.jakarta.server.config.JakartaWebSocketServletContainerInitializer;

/**
* Example of setting up a javax.websocket server with Jetty embedded
* Example of setting up a jakarta.websocket server with Jetty embedded
*/
public class WebSocketJsrServer
public class WebSocketJakartaServer
{
/**
* A server socket endpoint
Expand All @@ -56,11 +55,11 @@ public static Server createServer(int port)
context.setContextPath("/");
handlers.addHandler(context);

// Enable javax.websocket configuration for the context
JavaxWebSocketServletContainerInitializer.configure(context,
// Enable jakarta.websocket configuration for the context
JakartaWebSocketServletContainerInitializer.configure(context,
(servletContext, serverContainer) ->
{
// Add your websocket to the javax.websocket.server.ServerContainer
// Add your websocket to the jakarta.websocket.server.ServerContainer
serverContainer.addEndpoint(EchoJsrSocket.class);
}
);
Expand Down
Expand Up @@ -31,7 +31,7 @@
/**
* Example of setting up a Jetty WebSocket server
* <p>
* Note: this uses the Jetty WebSocket API, not the javax.websocket API.
* Note: this uses the Jetty WebSocket API, not the jakarta.websocket API.
*/
public class WebSocketServer
{
Expand Down
Expand Up @@ -20,14 +20,14 @@

import java.net.URI;
import java.util.concurrent.LinkedBlockingQueue;
import javax.websocket.CloseReason;
import javax.websocket.ContainerProvider;
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfig;
import javax.websocket.MessageHandler;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;

import jakarta.websocket.CloseReason;
import jakarta.websocket.ContainerProvider;
import jakarta.websocket.Endpoint;
import jakarta.websocket.EndpointConfig;
import jakarta.websocket.MessageHandler;
import jakarta.websocket.Session;
import jakarta.websocket.WebSocketContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.websocket.api.util.WSURI;
Expand All @@ -39,14 +39,14 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class WebSocketJsrServerTest
public class WebSocketJakartaServerTest
{
private Server server;

@BeforeEach
public void startServer() throws Exception
{
server = WebSocketJsrServer.createServer(0);
server = WebSocketJakartaServer.createServer(0);
server.start();
}

Expand All @@ -59,23 +59,23 @@ public void stopServer() throws Exception
@Test
public void testGetEcho() throws Exception
{
WebSocketContainer javaxWebSocketClient = ContainerProvider.getWebSocketContainer();
javaxWebSocketClient.setDefaultMaxSessionIdleTimeout(2000);
WebSocketContainer jakartaWebSocketClient = ContainerProvider.getWebSocketContainer();
jakartaWebSocketClient.setDefaultMaxSessionIdleTimeout(2000);
try
{
URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/echo"));

TrackingClientEndpoint clientEndpoint = new TrackingClientEndpoint();

Session session = javaxWebSocketClient.connectToServer(clientEndpoint, null, wsUri);
Session session = jakartaWebSocketClient.connectToServer(clientEndpoint, null, wsUri);
session.getBasicRemote().sendText("Hello World");

String response = clientEndpoint.messages.poll(2, SECONDS);
assertThat("Response", response, is("Hello World"));
}
finally
{
LifeCycle.stop(javaxWebSocketClient);
LifeCycle.stop(jakartaWebSocketClient);
}
}

Expand Down
6 changes: 3 additions & 3 deletions jetty-bom/pom.xml
Expand Up @@ -341,17 +341,17 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-javax-client</artifactId>
<artifactId>websocket-jakarta-client</artifactId>
<version>11.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-javax-server</artifactId>
<artifactId>websocket-jakarta-server</artifactId>
<version>11.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-javax-common</artifactId>
<artifactId>websocket-jakarta-common</artifactId>
<version>11.0.0-SNAPSHOT</version>
</dependency>
<dependency>
Expand Down
Expand Up @@ -139,7 +139,7 @@ Here is an example, setting the context attribute in code (although you can also
----
WebAppContext context = new WebAppContext();
context.setAttribute("org.eclipse.jetty.containerInitializerOrder",
"org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer, com.acme.Foo.MySCI, *");
"org.eclipse.jetty.websocket.jakarta.server.JakartaWebSocketServletContainerInitializer, com.acme.Foo.MySCI, *");
----

In this example, we ensure that the `WebSocketServerContainerInitializer` is the very first `ServletContainerInitializer` that is called, followed by MySCI and then any other `ServletContainerInitializer` instances that were discovered but not yet called.
Expand Down
Expand Up @@ -145,7 +145,7 @@ Properties:
jetty.secure.port = 8443
jetty.truststore = etc/keystore
jetty.truststore.password = OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4
org.eclipse.jetty.websocket.javax = false
org.eclipse.jetty.websocket.jakarta = false
threads.max = 200
threads.min = 10
threads.timeout = 60000
Expand Down Expand Up @@ -189,8 +189,8 @@ Note: order presented here is how they would appear on the classpath.
32: 1.2 | ${jetty.home}/lib/annotations/javax.annotation-api-1.2.jar
33: {VERSION} | ${jetty.home}/lib/jetty-deploy-{VERSION}.jar
34: 1.0 | ${jetty.home}/lib/websocket/javax.websocket-api-1.0.jar
35: {VERSION} | ${jetty.home}/lib/websocket/websocket-javax-client-{VERSION}.jar
36: {VERSION} | ${jetty.home}/lib/websocket/websocket-javax-server-{VERSION}.jar
35: {VERSION} | ${jetty.home}/lib/websocket/websocket-jakarta-client-{VERSION}.jar
36: {VERSION} | ${jetty.home}/lib/websocket/websocket-jakarta-server-{VERSION}.jar
37: {VERSION} | ${jetty.home}/lib/websocket/websocket-api-{VERSION}.jar
38: {VERSION} | ${jetty.home}/lib/websocket/websocket-client-{VERSION}.jar
39: {VERSION} | ${jetty.home}/lib/websocket/websocket-common-{VERSION}.jar
Expand Down Expand Up @@ -235,7 +235,7 @@ etc/demo-rewrite-rules.xml
# Websocket chat examples needs websocket enabled
# Don't start for all contexts (set to true in test.xml context)
org.eclipse.jetty.websocket.javax=false
org.eclipse.jetty.websocket.jakarta=false
--module=websocket
# Create and configure the test realm
Expand Down
Expand Up @@ -97,9 +97,9 @@ Note: order presented here is how they would appear on the classpath.
31: 4.1 | ${jetty.home}/lib/annotations/asm-commons-4.1.jar
32: 1.2 | ${jetty.home}/lib/annotations/javax.annotation-api-1.2.jar
33: {VERSION} | ${jetty.home}/lib/jetty-deploy-{VERSION}.jar
34: 1.0 | ${jetty.home}/lib/websocket/javax.websocket-api-1.0.jar
35: {VERSION} | ${jetty.home}/lib/websocket/websocket-javax-client-{VERSION}.jar
36: {VERSION} | ${jetty.home}/lib/websocket/websocket-javax-server-{VERSION}.jar
34: 1.0 | ${jetty.home}/lib/websocket/jakarta.websocket-api-1.0.jar
35: {VERSION} | ${jetty.home}/lib/websocket/websocket-jakarta-client-{VERSION}.jar
36: {VERSION} | ${jetty.home}/lib/websocket/websocket-jakarta-server-{VERSION}.jar
37: {VERSION} | ${jetty.home}/lib/websocket/websocket-api-{VERSION}.jar
38: {VERSION} | ${jetty.home}/lib/websocket/websocket-client-{VERSION}.jar
39: {VERSION} | ${jetty.home}/lib/websocket/websocket-common-{VERSION}.jar
Expand Down
Expand Up @@ -1150,13 +1150,13 @@ There is a list of Eclipse P2 sites for the jetty releases maintained at http://
Each P2 repo has one big feature group that defines most of the Jetty jars.
*Beware: No 3rd party dependency jars are included, so you will need to have installed the dependencies listed previously in this document.*

In addition, as the feature group includes websocket, you will need to download and have installed the `javax.websocket-api` jar:
In addition, as the feature group includes websocket, you will need to download and have installed the `jakarta.websocket-api` jar:

.Extra Jars Required for Websocket
[cols=",,",options="header",]
|=======================================================================
|Jar |Bundle Symbolic Name |Location
|javax.websocket-api |javax.websocket-api
|https://repo1.maven.org/maven2/javax/websocket/websocket-api[Maven
|jakarta.websocket-api |jakarta.websocket-api
|https://repo1.maven.org/maven2/jakarta/websocket/jakarta.websocket-api/[Maven
central]
|=======================================================================
Expand Up @@ -65,7 +65,7 @@ Use http://caniuse.com/websockets[caniuse.com/websockets] to find out.
____

http://www.jcp.org/en/jsr/detail?id=356[JSR-356]::
The Java WebSocket API (`javax.websocket`)
The Java WebSocket API (`jakarta.websocket`)
+
This is the official Java API for working with WebSockets.

Expand Down Expand Up @@ -97,9 +97,9 @@ Jetty WebSocket Server API::
Jetty WebSocket Client API::
Connect to WebSocket servers with Jetty.
Java WebSocket Client API::
The new standard Java WebSocket Client API (`javax.websocket`) [JSR-356]
The new standard Java WebSocket Client API (`jakarta.websocket`) [JSR-356]
Java WebSocket Server API::
The new standard Java WebSocket Server API (`javax.websocket.server`) [JSR-356]
The new standard Java WebSocket Server API (`jakarta.websocket.server`) [JSR-356]

=== Enabling WebSocket

Expand All @@ -108,17 +108,17 @@ To enable Websocket, you need to enable the `websocket` link:#enabling-modules[m
Once this module is enabled for your Jetty base, it will apply to all webapps deployed to that base. If you want to be more selective about which webapps use Websocket, then you can:

Disable Websocket for a particular webapp:::
You can disable jsr-356 for a particular webapp by setting the link:#context_attributes[context attribute] `org.eclipse.jetty.websocket.javax` to `false`.
You can disable jsr-356 for a particular webapp by setting the link:#context_attributes[context attribute] `org.eclipse.jetty.websocket.jakarta` to `false`.
This will mean that websockets are not available to your webapp, however deployment time scanning for websocket-related classes such as endpoints will still occur.
This can be a significant impost if your webapp contains a lot of classes and/or jar files.
To completely disable websockets and avoid all setup costs associated with it for a particular webapp, use instead the context attribute `org.eclipse.jetty.containerInitializerExclusionPattern`, described next, which allows you to exclude the websocket ServletContainerInitializer that causes the scanning.
Completely disable Websocket for a particular webapp:::
Set the `org.eclipse.jetty.containerInitializerExclusionPattern` link:#context_attributes[context attribute] to include `org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer`.
Set the `org.eclipse.jetty.containerInitializerExclusionPattern` link:#context_attributes[context attribute] to include `org.eclipse.jetty.websocket.jakarta.server.JakartaWebSocketServletContainerInitializer`.
Here's an example of doing this in code, although you can do the link:#intro-jetty-configuration-webapps[same in xml]:
+
[source, java, subs="{sub-order}"]
----
WebAppContext context = new WebAppContext();
context.setAttribute("org.eclipse.jetty.containerInitializerExclusionPattern",
"org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer|com.acme.*");
"org.eclipse.jetty.websocket.jakarta.server.JakartaWebSocketServletContainerInitializer|com.acme.*");
----
10 changes: 5 additions & 5 deletions jetty-home/pom.xml
Expand Up @@ -223,27 +223,27 @@
</configuration>
</execution>
<execution>
<id>copy-lib-javax-websocket-deps</id>
<id>copy-lib-jakarta-websocket-deps</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.eclipse.jetty.toolchain</includeGroupIds>
<includeArtifactIds>jetty-javax-websocket-api</includeArtifactIds>
<includeArtifactIds>jetty-jakarta-websocket-api</includeArtifactIds>
<includeTypes>jar</includeTypes>
<outputDirectory>${assembly-directory}/lib/websocket</outputDirectory>
</configuration>
</execution>
<execution>
<id>copy-lib-javax-websocket-src-deps</id>
<id>copy-lib-jakarta-websocket-src-deps</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.eclipse.jetty.toolchain</includeGroupIds>
<includeArtifactIds>jetty-javax-websocket-api</includeArtifactIds>
<includeArtifactIds>jetty-jakarta-websocket-api</includeArtifactIds>
<includeTypes>jar</includeTypes>
<classifier>sources</classifier>
<outputDirectory>${source-assembly-directory}/lib/websocket</outputDirectory>
Expand Down Expand Up @@ -673,7 +673,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-javax-server</artifactId>
<artifactId>websocket-jakarta-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion jetty-maven-plugin/pom.xml
Expand Up @@ -218,7 +218,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-javax-server</artifactId>
<artifactId>websocket-jakarta-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion jetty-osgi/jetty-osgi-boot/jettyhome/etc/jetty.xml
Expand Up @@ -96,7 +96,7 @@
<Item>org.eclipse.jetty.webapp.JmxConfiguration</Item>
<Item>org.eclipse.jetty.osgi.annotations.AnnotationConfiguration</Item>
<Item>org.eclipse.jetty.websocket.server.config.JettyWebSocketConfiguration</Item>
<Item>org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketConfiguration</Item>
<Item>org.eclipse.jetty.websocket.jakarta.server.config.JakartaWebSocketConfiguration</Item>
<Item>org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration</Item>
<Item>org.eclipse.jetty.osgi.boot.OSGiMetaInfConfiguration</Item>
</Array>
Expand Down
6 changes: 3 additions & 3 deletions jetty-osgi/test-jetty-osgi/pom.xml
Expand Up @@ -298,7 +298,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-javax-client</artifactId>
<artifactId>websocket-jakarta-client</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
Expand All @@ -316,12 +316,12 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-javax-websocket-api</artifactId>
<artifactId>jetty-jakarta-websocket-api</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-javax-server</artifactId>
<artifactId>websocket-jakarta-server</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
Expand Down
Expand Up @@ -34,7 +34,7 @@
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.osgi.boot.utils.ServerConnectorListener">
<Set name="sysPropertyName">boot.javax.websocket.port</Set>
<Set name="sysPropertyName">boot.jakarta.websocket.port</Set>
</New>
</Arg>
</Call>
Expand Down

0 comments on commit a7af698

Please sign in to comment.