-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[JENKINS-68933] Update to Jetty 10, with WebSocket #6785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
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 c670842
Removing use of reflection to access Jetty WebSocket types
jglick ce2b909
Merge branch 'master' of https://github.com/jenkinsci/jenkins into ws…
jglick b6f67d1
Removing `javax.servlet-api` from BOM
jglick 476a6fa
Tweaking packaging
jglick 2398931
Revert "Revert "[JENKINS-68694] Winstone 6.0: Upgrade Jetty from 9.4.…
jglick 7800ab0
Currently broken draft of Jetty 10 provider
jglick 944ad29
Checkstyle
basil d7438dc
SpotBugs
basil a14541b
Enforcer
basil b7bc5c4
Merge branch 'master' of https://github.com/jenkinsci/jenkins into ws…
jglick 01e59fc
Skip Javadoc on new modules
jglick f53b2df
Merge branch 'ws-JENKINS-68933' into ws-JENKINS-68933-jetty-10
jglick 1453121
Skip Javadoc on new module
jglick 4880587
`enforceBytecodeVersion` exclude
jglick 042b962
Also exclude `Jetty10Provider` from SpotBugs
jglick 46e1a2e
Checkstyle
jglick c2ebbc0
Pick up https://github.com/jenkinsci/winstone/pull/240
jglick db4d91f
Treat `ClosedChannelException` specially.
jglick 96f3ddf
https://github.com/jenkinsci/winstone/pull/240 released
jglick 32cab3b
Treat `ClosedChannelException` specially.
jglick e98f3cd
Do not bundle `javax.servlet-api`: https://github.com/jenkinsci/jenki…
jglick f190f5d
Do not bundle `javax.servlet-api`: https://github.com/jenkinsci/jenki…
jglick 487f5d2
Exclude Jetty 10 from test project
basil 9f57b6f
Merge branch 'master' of https://github.com/jenkinsci/jenkins into ws…
jglick ac6d1ef
Do not propagate `winstone` dep to `test`: https://github.com/jenkins…
jglick 69c5832
Merge branch 'ws-JENKINS-68933' into ws-JENKINS-68933-jetty-10
jglick 5cacd9f
Do not propagate `winstone` dep to `test`: https://github.com/jenkins…
jglick 4f6f2cc
Merge branch 'master' of https://github.com/jenkinsci/jenkins into ws…
jglick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
162
websocket/jetty10/src/main/java/jenkins/websocket/Jetty10Provider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.