Skip to content
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

Jetty 10 based JenkinsRule #453

Merged
merged 5 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 16 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ THE SOFTWARE.
<properties>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.361</jenkins.version>
<jetty.version>9.4.49.v20220914</jetty.version>
<hamcrest.version>2.2</hamcrest.version>
<jmh.version>1.36</jmh.version>
<gitHubRepo>jenkinsci/${project.artifactId}</gitHubRepo>
Expand All @@ -71,6 +70,13 @@ THE SOFTWARE.

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-bom</artifactId>
<version>10.0.12</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>annotation-indexer</artifactId>
Expand Down Expand Up @@ -140,23 +146,22 @@ THE SOFTWARE.
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<!-- or javax-websocket-server-impl -->
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>${jetty.version}</version>
<!-- or websocket-javax-server -->
<artifactId>websocket-jetty-server</artifactId>
<!-- until Jetty release including https://github.com/eclipse/jetty.project/pull/8199 -->
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jvnet/hudson/test/HudsonTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.apache.commons.beanutils.PropertyUtils;
import org.eclipse.jetty.http.HttpCompliance;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.http.UriCompliance;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.LoginService;
import org.eclipse.jetty.security.UserStore;
Expand All @@ -177,6 +179,7 @@
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebXmlConfiguration;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
import org.jvnet.hudson.test.HudsonHomeLoader.CopyExisting;
import org.jvnet.hudson.test.recipes.Recipe;
import org.jvnet.hudson.test.recipes.Recipe.Runner;
Expand Down Expand Up @@ -540,6 +543,7 @@ protected ServletContext createWebServer() throws Exception {
context.setConfigurations(new Configuration[]{new WebXmlConfiguration()});
context.addBean(new NoListenerConfiguration(context));
server.setHandler(context);
JettyWebSocketServletContainerInitializer.configure(context, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.setMimeTypes(MIME_TYPES);
context.getSecurityHandler().setLoginService(configureUserRealm());

Expand All @@ -548,6 +552,8 @@ protected ServletContext createWebServer() throws Exception {
HttpConfiguration config = connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
// use a bigger buffer as Stapler traces can get pretty large on deeply nested URL
config.setRequestHeaderSize(12 * 1024);
config.setHttpCompliance(HttpCompliance.RFC7230);
config.setUriCompliance(UriCompliance.LEGACY);
connector.setHost("localhost");

server.addConnector(connector);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.eclipse.jetty.http.HttpCompliance;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.http.UriCompliance;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.LoginService;
import org.eclipse.jetty.security.UserStore;
Expand All @@ -216,6 +218,7 @@
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebXmlConfiguration;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -796,6 +799,7 @@ public static ImmutablePair<Server, ServletContext> _createWebServer(String cont
context.setConfigurations(new Configuration[]{new WebXmlConfiguration()});
context.addBean(new NoListenerConfiguration(context));
server.setHandler(context);
JettyWebSocketServletContainerInitializer.configure(context, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@basil FYI this JTH release breaks a WebSocket test in the kubernetes plugin:

java.lang.NullPointerException: Cannot invoke "org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer.upgrade(org.eclipse.jetty.websocket.server.JettyWebSocketCreator, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)" because the return value of "org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer.getContainer(javax.servlet.ServletContext)" is null
	at jenkins.websocket.Jetty10Provider.handle(Jetty10Provider.java:61)
	at jenkins.websocket.WebSockets.lambda$upgrade$0(WebSockets.java:70)

I am still trying to understand why; in the meantime, jenkinsci/kubernetes-plugin@dcc8137

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, never mind, I think this is due to a stale copy in that plugin (#289 (comment)).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to hear it, especially given that I tested this case by running the Swarm plugin's JenkinsRule-based tests (which use WebSocket) against this PR prior to its merge and release.

context.setMimeTypes(MIME_TYPES);
context.getSecurityHandler().setLoginService(loginServiceSupplier.get());
context.setResourceBase(WarExploder.getExplodedDir().getPath());
Expand All @@ -804,6 +808,8 @@ public static ImmutablePair<Server, ServletContext> _createWebServer(String cont
HttpConfiguration config = connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
// use a bigger buffer as Stapler traces can get pretty large on deeply nested URL
config.setRequestHeaderSize(12 * 1024);
config.setHttpCompliance(HttpCompliance.RFC7230);
config.setUriCompliance(UriCompliance.LEGACY);
connector.setHost("localhost");
if (System.getProperty("port") != null) {
connector.setPort(Integer.parseInt(System.getProperty("port")));
Expand Down