Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8a14f9d
[JENKINS-68933] Verify basic WebSocket connectivity in `RealJenkinsRule`
jglick Jul 5, 2022
c670842
Removing use of reflection to access Jetty WebSocket types
jglick Jul 5, 2022
ce2b909
Merge branch 'master' of https://github.com/jenkinsci/jenkins into ws…
jglick Jul 5, 2022
b6f67d1
Removing `javax.servlet-api` from BOM
jglick Jul 5, 2022
476a6fa
Tweaking packaging
jglick Jul 5, 2022
2398931
Revert "Revert "[JENKINS-68694] Winstone 6.0: Upgrade Jetty from 9.4.…
jglick Jul 5, 2022
7800ab0
Currently broken draft of Jetty 10 provider
jglick Jul 5, 2022
944ad29
Checkstyle
basil Jul 6, 2022
d7438dc
SpotBugs
basil Jul 6, 2022
a14541b
Enforcer
basil Jul 6, 2022
b7bc5c4
Merge branch 'master' of https://github.com/jenkinsci/jenkins into ws…
jglick Jul 6, 2022
01e59fc
Skip Javadoc on new modules
jglick Jul 6, 2022
f53b2df
Merge branch 'ws-JENKINS-68933' into ws-JENKINS-68933-jetty-10
jglick Jul 6, 2022
1453121
Skip Javadoc on new module
jglick Jul 6, 2022
4880587
`enforceBytecodeVersion` exclude
jglick Jul 6, 2022
042b962
Also exclude `Jetty10Provider` from SpotBugs
jglick Jul 6, 2022
46e1a2e
Checkstyle
jglick Jul 6, 2022
c2ebbc0
Pick up https://github.com/jenkinsci/winstone/pull/240
jglick Jul 6, 2022
db4d91f
Treat `ClosedChannelException` specially.
jglick Jul 6, 2022
96f3ddf
https://github.com/jenkinsci/winstone/pull/240 released
jglick Jul 6, 2022
32cab3b
Treat `ClosedChannelException` specially.
jglick Jul 6, 2022
e98f3cd
Do not bundle `javax.servlet-api`: https://github.com/jenkinsci/jenki…
jglick Jul 6, 2022
f190f5d
Do not bundle `javax.servlet-api`: https://github.com/jenkinsci/jenki…
jglick Jul 6, 2022
487f5d2
Exclude Jetty 10 from test project
basil Jul 6, 2022
9f57b6f
Merge branch 'master' of https://github.com/jenkinsci/jenkins into ws…
jglick Jul 6, 2022
ac6d1ef
Do not propagate `winstone` dep to `test`: https://github.com/jenkins…
jglick Jul 6, 2022
69c5832
Merge branch 'ws-JENKINS-68933' into ws-JENKINS-68933-jetty-10
jglick Jul 6, 2022
5cacd9f
Do not propagate `winstone` dep to `test`: https://github.com/jenkins…
jglick Jul 6, 2022
4f6f2cc
Merge branch 'master' of https://github.com/jenkinsci/jenkins into ws…
jglick Jul 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ updates:
# Provided by Jetty and should be aligned with the version provided by the
# version of Jetty we deliver. See:
# https://github.com/jenkinsci/jenkins/pull/5211
- dependency-name: "javax.servlet:javax.servlet-api"
- dependency-name: "jakarta.servlet:jakarta.servlet-api"

# Jetty Maven Plugin and Winstone should be upgraded in lockstep in order
# to keep their corresponding Jetty versions aligned.
Expand Down
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ THE SOFTWARE.
<properties>
<asm.version>9.3</asm.version>
<slf4jVersion>1.7.36</slf4jVersion>
<stapler.version>1685.v3b_5035c4ce05</stapler.version>
<stapler.version>1711.v5b_1b_03f0fcf2</stapler.version>
<groovy.version>2.4.21</groovy.version>
</properties>

Expand Down
6 changes: 3 additions & 3 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ THE SOFTWARE.
<version>1.1.4c</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>4.0.4</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ THE SOFTWARE.
<module>bom</module>
<module>websocket/spi</module>
<module>websocket/jetty9</module>
<module>websocket/jetty10</module>
<module>core</module>
<module>war</module>
<module>test</module>
Expand Down
1 change: 1 addition & 0 deletions src/spotbugs/spotbugs-excludes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@
<Class name="jenkins.slaves.restarter.WinswSlaveRestarter"/>
<Class name="jenkins.slaves.StandardOutputSwapper$ChannelSwapper"/>
<Class name="jenkins.util.ProgressiveRendering"/>
<Class name="jenkins.websocket.Jetty10Provider"/>
<Class name="jenkins.websocket.Jetty9Provider"/>
<Class name="jenkins.websocket.Provider"/>
<Class name="jenkins.websocket.WebSockets"/>
Expand Down
20 changes: 15 additions & 5 deletions war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ THE SOFTWARE.
jars that are not needed in war. most of the exclusions should happen in the core, to make IDEs happy, not here.
-->
<exclusion>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<groupId>jakarta.servlet.jsp</groupId>
<artifactId>jakarta.servlet.jsp-api</artifactId>
</exclusion>
<!-- Stapler 1.195 fails to declare this as optional, and the 1.1 version lacks a license: -->
<exclusion>
Expand All @@ -96,6 +96,11 @@ THE SOFTWARE.
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>websocket-jetty10</artifactId>
<version>${project.version}</version>
</dependency>
Comment thread
jglick marked this conversation as resolved.
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>websocket-jetty9</artifactId>
Expand Down Expand Up @@ -137,7 +142,7 @@ THE SOFTWARE.
<groupId>org.jenkins-ci</groupId>
<artifactId>winstone</artifactId>
<!-- Make sure to keep jetty-maven-plugin elsewhere in this file in sync with the Jetty release in Winstone -->
<version>5.25</version>
<version>6.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -177,10 +182,15 @@ THE SOFTWARE.
<enforceBytecodeVersion>
<maxJdkVersion>1.8</maxJdkVersion>
<excludes>
<exclude>org.jenkins-ci:commons-jelly</exclude>
<exclude>org.jenkins-ci.main:cli</exclude>
<exclude>org.jenkins-ci.main:jenkins-core</exclude>
<exclude>org.jenkins-ci.main:websocket-jetty9</exclude>
<exclude>org.jenkins-ci.main:websocket-spi</exclude>
<exclude>org.jenkins-ci.main:websocket-jetty9</exclude>
<exclude>org.jenkins-ci.main:websocket-jetty10</exclude>
<exclude>org.kohsuke.stapler:stapler</exclude>
<exclude>org.kohsuke.stapler:stapler-groovy</exclude>
<exclude>org.kohsuke.stapler:stapler-jelly</exclude>
</excludes>
</enforceBytecodeVersion>
</rules>
Expand Down Expand Up @@ -567,7 +577,7 @@ THE SOFTWARE.
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.46.v20220331</version>
<version>10.0.11</version>
<configuration>
<!--
Reload webapp when you hit ENTER. (See JETTY-282 for more)
Expand Down
84 changes: 84 additions & 0 deletions websocket/jetty10/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License

Copyright (c) 2019, CloudBees, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-parent</artifactId>
<version>${revision}${changelist}</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>websocket-jetty10</artifactId>
<name>Jetty 10 implementation for WebSocket</name>
<description>An implementation of the WebSocket handler that works with Jetty 10.</description>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>winstone</artifactId>
<version>6.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>websocket-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>access-modifier-annotation</artifactId>
</dependency>
<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
162 changes: 162 additions & 0 deletions websocket/jetty10/src/main/java/jenkins/websocket/Jetty10Provider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* The MIT License
*
* Copyright 2022 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package jenkins.websocket;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketListener;
import org.eclipse.jetty.websocket.api.WriteCallback;
import org.eclipse.jetty.websocket.server.JettyServerUpgradeRequest;
import org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse;
import org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer;
import org.kohsuke.MetaInfServices;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

@Restricted(NoExternalUse.class)
@MetaInfServices(Provider.class)
public class Jetty10Provider implements Provider {

private static final String ATTR_LISTENER = Jetty10Provider.class.getName() + ".listener";

// TODO does not seem possible to use HttpServletRequest.get/setAttribute for this
private static final Map<Listener, Session> sessions = new WeakHashMap<>();

public Jetty10Provider() {
JettyWebSocketServerContainer.class.hashCode();
}

@Override
public Handler handle(HttpServletRequest req, HttpServletResponse rsp, Listener listener) throws Exception {
req.setAttribute(ATTR_LISTENER, listener);
// TODO Jetty 10 has no obvious equivalent to WebSocketServerFactory.isUpgradeRequest; RFC6455Negotiation?
if (!"websocket".equalsIgnoreCase(req.getHeader("Upgrade"))) {
rsp.sendError(HttpServletResponse.SC_BAD_REQUEST, "only WS connections accepted here");
return null;
}
if (!JettyWebSocketServerContainer.getContainer(req.getServletContext()).upgrade(Jetty10Provider::createWebSocket, req, rsp)) {
rsp.sendError(HttpServletResponse.SC_BAD_REQUEST, "did not manage to upgrade");
return null;
}
return new Handler() {
@Override
public Future<Void> sendBinary(ByteBuffer data) throws IOException {
CompletableFuture<Void> f = new CompletableFuture<>();
session().getRemote().sendBytes(data, new WriteCallbackImpl(f));
return f;
}

@Override
public void sendBinary(ByteBuffer partialByte, boolean isLast) throws IOException {
session().getRemote().sendPartialBytes(partialByte, isLast);
}

@Override
public Future<Void> sendText(String text) throws IOException {
CompletableFuture<Void> f = new CompletableFuture<>();
session().getRemote().sendString(text, new WriteCallbackImpl(f));
return f;
}

@Override
public void sendPing(ByteBuffer applicationData) throws IOException {
session().getRemote().sendPing(applicationData);
}

@Override
public void close() throws IOException {
session().close();
}

private Session session() {
Session session = sessions.get(listener);
if (session == null) {
throw new IllegalStateException("missing session");
}
return session;
}
};
}

private static final class WriteCallbackImpl implements WriteCallback {
private final CompletableFuture<Void> f;

WriteCallbackImpl(CompletableFuture<Void> f) {
this.f = f;
}

@Override
public void writeSuccess() {
f.complete(null);
}

@Override
public void writeFailed(Throwable x) {
f.completeExceptionally(x);
}
}

private static Object createWebSocket(JettyServerUpgradeRequest req, JettyServerUpgradeResponse resp) {
Listener listener = (Listener) req.getHttpServletRequest().getAttribute(ATTR_LISTENER);
if (listener == null) {
throw new IllegalStateException("missing listener attribute");
}
return new WebSocketListener() {
@Override
public void onWebSocketBinary(byte[] payload, int offset, int length) {
listener.onWebSocketBinary(payload, offset, length);
}

@Override
public void onWebSocketText(String message) {
listener.onWebSocketText(message);
}

@Override
public void onWebSocketClose(int statusCode, String reason) {
listener.onWebSocketClose(statusCode, reason);
}

@Override
public void onWebSocketConnect(Session session) {
sessions.put(listener, session);
listener.onWebSocketConnect();
}

@Override
public void onWebSocketError(Throwable cause) {
listener.onWebSocketError(cause);
}
};
}

}