diff --git a/src/main/java/jenkins/benchmark/jmh/JmhBenchmarkState.java b/src/main/java/jenkins/benchmark/jmh/JmhBenchmarkState.java index fc146011e..8e90c078d 100644 --- a/src/main/java/jenkins/benchmark/jmh/JmhBenchmarkState.java +++ b/src/main/java/jenkins/benchmark/jmh/JmhBenchmarkState.java @@ -15,7 +15,7 @@ import jenkins.model.Jenkins; import jenkins.model.JenkinsLocationConfiguration; import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.webapp.WebAppContext; import org.jvnet.hudson.test.JavaNetReverseProxy; import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.TemporaryDirectoryAllocator; @@ -93,15 +93,15 @@ public final void terminateJenkins() { } private void launchInstance() throws Exception { - server = JenkinsRule._createWebServer( + WebAppContext context = JenkinsRule._createWebAppContext( contextPath, localPort::set, getClass().getClassLoader(), localPort.get(), JenkinsRule::_configureUserRealm); + server = context.getServer(); - ServletContext webServer = - server.getChildHandlerByClass(ContextHandler.class).getServletContext(); + ServletContext webServer = context.getServletContext(); jenkins = new Hudson(temporaryDirectoryAllocator.allocate(), webServer, TestPluginManager.INSTANCE); JenkinsRule._configureJenkinsForTest(jenkins); diff --git a/src/main/java/org/jvnet/hudson/test/JenkinsRule.java b/src/main/java/org/jvnet/hudson/test/JenkinsRule.java index 40d318630..18c21d221 100644 --- a/src/main/java/org/jvnet/hudson/test/JenkinsRule.java +++ b/src/main/java/org/jvnet/hudson/test/JenkinsRule.java @@ -183,7 +183,6 @@ import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.security.Password; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.webapp.Configuration; @@ -800,15 +799,16 @@ protected ServletContext createWebServer() throws Exception { */ protected ServletContext createWebServer(@CheckForNull BiConsumer contextAndServerConsumer) throws Exception { - server = _createWebServer( + WebAppContext context = _createWebAppContext( contextPath, (x) -> localPort = x, getClass().getClassLoader(), localPort, this::configureUserRealm, contextAndServerConsumer); + server = context.getServer(); LOGGER.log(Level.INFO, "Running on {0}", getURL()); - return server.getChildHandlerByClass(ContextHandler.class).getServletContext(); + return context.getServletContext(); } /** @@ -822,14 +822,14 @@ protected ServletContext createWebServer(@CheckForNull BiConsumer portSetter, ClassLoader classLoader, int localPort, Supplier loginServiceSupplier) throws Exception { - return _createWebServer(contextPath, portSetter, classLoader, localPort, loginServiceSupplier, null); + return _createWebAppContext(contextPath, portSetter, classLoader, localPort, loginServiceSupplier, null); } /** * Creates a web server on which Jenkins can run @@ -843,7 +843,7 @@ public static Server _createWebServer( * @return the {@link Server} * @since 2.50 */ - public static Server _createWebServer( + public static WebAppContext _createWebAppContext( String contextPath, Consumer portSetter, ClassLoader classLoader, @@ -886,7 +886,7 @@ public static Server _createWebServer( portSetter.accept(connector.getLocalPort()); - return server; + return context; } /**