Skip to content

Commit

Permalink
Upgrade Jetty from v9 to v10
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlwilson committed Oct 1, 2023
1 parent 29f5eb5 commit 5d7f3cc
Show file tree
Hide file tree
Showing 51 changed files with 254 additions and 284 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Expand Up @@ -220,9 +220,9 @@ domain/target/
installers/target/
jar-class-loader/out/
jar-class-loader/target/
jetty9/logs/
jetty9/out/
jetty9/target/
jetty/logs/
jetty/out/
jetty/target/
plugin-infra/go-plugin-access/config/
plugin-infra/go-plugin-access/logs/
plugin-infra/go-plugin-access/out/
Expand Down
Expand Up @@ -26,7 +26,7 @@ public abstract class ServletHelper {

public static void init() {
try {
instance = getAppServerHelper("com.thoughtworks.go.server.util.Jetty9ServletHelper");
instance = getAppServerHelper("com.thoughtworks.go.server.util.JettyServletHelper");
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Expand Up @@ -15,10 +15,9 @@
*/
package com.thoughtworks.go.server.util;

import java.util.function.Function;

public interface ServletRequest {
String getUrl();
String getUriPath();
String getUriAsString();
void setRequestURI(String uri);
void modifyPath(Function<String, String> pathModifier);
String getRootURL();
}
Expand Up @@ -139,8 +139,8 @@ public class SystemEnvironment implements Serializable, ConfigDirProvider {

public static final GoSystemProperty<String> JETTY_XML_FILE_NAME = new GoStringSystemProperty("jetty.xml.file.name", JETTY_XML);

public static final String JETTY9 = "com.thoughtworks.go.server.Jetty9Server";
public static final GoSystemProperty<String> APP_SERVER = new CachedProperty<>(new GoStringSystemProperty("app.server", JETTY9));
public static final String JETTY = "com.thoughtworks.go.server.JettyServer";
public static final GoSystemProperty<String> APP_SERVER = new CachedProperty<>(new GoStringSystemProperty("app.server", JETTY));
public static final GoSystemProperty<String> GO_LANDING_PAGE = new GoStringSystemProperty("go.landing.page", "/pipelines");

public static final GoSystemProperty<Boolean> ARTIFACT_VIEW_INCLUDE_ALL_FILES = new GoBooleanSystemProperty("go.view-artifacts.include-all", true);
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Expand Up @@ -414,13 +414,14 @@ subprojects {
details.useTarget project.deps.jakartaAnnotation
}
// Javax Servlet API has migrated to jakarta Servlet API
if (details.requested.group == 'javax.servlet' && details.requested.name == 'javax.servlet-api') {
if (details.requested.group in ['javax.servlet', 'org.eclipse.jetty.toolchain'] && details.requested.name in ['javax.servlet-api', 'jetty-servlet-api']) {
details.useTarget project.deps.servletApi
}
// Javax Transaction API has migrated to jakarta Transaction API
if (details.requested.group == 'javax.transaction' && details.requested.name == 'jta') {
details.useTarget project.deps.jakartaTransaction
}

}
}

Expand Down
4 changes: 2 additions & 2 deletions dependencies.gradle
Expand Up @@ -68,7 +68,7 @@ final Map<String, String> libraries = [
jcommander : 'com.beust:jcommander:1.82',
jdom : 'org.jdom:jdom2:2.0.6.1',
jetBrainsAnnotations: 'org.jetbrains:annotations:24.0.1',
jetty : 'org.eclipse.jetty:jetty-server:9.4.52.v20230823',
jetty : 'org.eclipse.jetty:jetty-server:10.0.16',
jgit : 'org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r',
jodaTime : 'joda-time:joda-time:2.12.5', // joda-time version has to be compatible with the jruby version
jolt : 'com.bazaarvoice.jolt:jolt-core:0.1.8',
Expand Down Expand Up @@ -198,7 +198,7 @@ final Map<String, String> related = [
jettyServlets : "org.eclipse.jetty:jetty-servlets:${v.jetty}",
jettyUtil : "org.eclipse.jetty:jetty-util:${v.jetty}",
jettyWebapp : "org.eclipse.jetty:jetty-webapp:${v.jetty}",
jettyWebsocket : "org.eclipse.jetty.websocket:websocket-server:${v.jetty}",
jettyWebsocket : "org.eclipse.jetty.websocket:websocket-jetty-server:${v.jetty}",
jgitServer : "org.eclipse.jgit:org.eclipse.jgit.http.server:${v.jgit}",
joltJsonUtils : "com.bazaarvoice.jolt:json-utils:${v.jolt}",
junit5Api : "org.junit.jupiter:junit-jupiter-api",
Expand Down
6 changes: 4 additions & 2 deletions development-utility/development-server/build.gradle
Expand Up @@ -31,13 +31,15 @@ dependencies {
implementation project.deps.jettyServlets
implementation project.deps.jettyUtil
implementation project.deps.jettyDeploy
implementation project.deps.jettyWebsocket
implementation(project.deps.jettyWebsocket) {
exclude(module: 'jetty-annotations')
}

implementation(project.deps.jgitServer) {
exclude(module: 'jsch')
exclude(module: 'jzlib')
}
implementation project(path: ':jetty9', configuration: 'runtimeElements')
implementation project(path: ':jetty', configuration: 'runtimeElements')
implementation project.deps.servletApi
implementation project.deps.jruby
implementation project.deps.rack
Expand Down
9 changes: 7 additions & 2 deletions jetty9/build.gradle → jetty/build.gradle
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

description = 'GoCD Jetty9 Bootstrapper'
description = 'GoCD Jetty Bootstrapper'

dependencies {
implementation project(path: ':app-server', configuration: 'runtimeElements')
Expand All @@ -28,10 +28,15 @@ dependencies {
compileOnly project.deps.jettyServlets
compileOnly project.deps.jettyUtil
compileOnly project.deps.jettyDeploy
compileOnly project.deps.jettyWebsocket
compileOnly(project.deps.jettyWebsocket) {
exclude(module: 'jetty-annotations')
}

testImplementation project.deps.jettyDeploy
testImplementation project.deps.jettyJmx
testImplementation(project.deps.jettyWebsocket) {
exclude(module: 'jetty-annotations')
}
testImplementation project(path: ':test:test-utils', configuration: 'runtimeElements')
testImplementation project.deps.junit5Api
testImplementation project.deps.junit5Params
Expand Down
Expand Up @@ -37,7 +37,7 @@ public AssetsContextHandler(SystemEnvironment systemEnvironment) {
super(systemEnvironment.getWebappContextPath() + "/assets");
this.systemEnvironment = systemEnvironment;

GzipHandler gzipHandler = Jetty9Server.gzipHandler();
GzipHandler gzipHandler = JettyServer.gzipHandler();
gzipHandler.setHandler(this.assetsHandler);
setHandler(gzipHandler);
}
Expand Down
Expand Up @@ -30,9 +30,9 @@
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebInfConfiguration;
import org.eclipse.jetty.webapp.WebXmlConfiguration;
import org.eclipse.jetty.webapp.*;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketConfiguration;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -49,20 +49,20 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

public class Jetty9Server extends AppServer {
public class JettyServer extends AppServer {
static String JETTY_XML_LOCATION_IN_JAR = "/defaultFiles/config";
static final String JETTY_CONFIG_VERSION = "jetty-config-gocd-v9";
private static final Logger LOG = LoggerFactory.getLogger(Jetty9Server.class);
static final String JETTY_CONFIG_VERSION = "jetty-config-gocd-v10";
private static final Logger LOG = LoggerFactory.getLogger(JettyServer.class);
private static final String JETTY_XML = "jetty.xml";
private final Server server;
private final DeploymentManager deploymentManager;
private WebAppContext webAppContext;

public Jetty9Server(SystemEnvironment systemEnvironment) {
public JettyServer(SystemEnvironment systemEnvironment) {
this(systemEnvironment, new Server(), new DeploymentManager());
}

Jetty9Server(SystemEnvironment systemEnvironment, Server server, DeploymentManager deploymentManager) {
JettyServer(SystemEnvironment systemEnvironment, Server server, DeploymentManager deploymentManager) {
super(systemEnvironment);
systemEnvironment.set(SystemEnvironment.JETTY_XML_FILE_NAME, JETTY_XML);
this.server = server;
Expand All @@ -81,7 +81,7 @@ public void configure() throws Exception {

JettyCustomErrorPageHandler errorHandler = new JettyCustomErrorPageHandler();
webAppContext.setErrorHandler(errorHandler);
webAppContext.setGzipHandler(gzipHandler());
webAppContext.insertHandler(gzipHandler());
server.addBean(errorHandler);
server.addBean(deploymentManager);

Expand Down Expand Up @@ -168,7 +168,7 @@ void startHandlers() {
if (systemEnvironment.useCompressedJs()) {
AssetsContextHandler assetsContextHandler = new AssetsContextHandler(systemEnvironment);
deploymentManager.addApp(new App(deploymentManager, webAppProvider, "assetsHandler", assetsContextHandler));
webAppContext.addLifeCycleListener(new AssetsContextHandlerInitializer(assetsContextHandler, webAppContext));
webAppContext.addEventListener(new AssetsContextHandlerInitializer(assetsContextHandler, webAppContext));
}

deploymentManager.addApp(new App(deploymentManager, webAppProvider, "realApp", webAppContext));
Expand Down Expand Up @@ -225,14 +225,19 @@ private WebAppContext createWebAppContext() {

context.setConfigurationClasses(new String[]{
WebInfConfiguration.class.getCanonicalName(),
WebXmlConfiguration.class.getCanonicalName()
WebXmlConfiguration.class.getCanonicalName(),
WebAppConfiguration.class.getCanonicalName(),
JettyWebSocketConfiguration.class.getCanonicalName()
});
context.addServletContainerInitializer(new JettyWebSocketServletContainerInitializer());
context.setContextPath(systemEnvironment.getWebappContextPath());

// delegate all logging to parent classloader to avoid initialization of loggers in multiple classloaders
context.getSystemClasspathPattern().add("org.apache.log4j.");
context.getSystemClasspathPattern().add("org.slf4j.");
context.getSystemClasspathPattern().add("org.apache.commons.logging.");
context.addSystemClassMatcher(new ClassMatcher(
"org.apache.log4j.",
"org.slf4j.",
"org.apache.commons.logging.")
);

context.setWar(getWarFile());
context.setParentLoaderPriority(systemEnvironment.getParentLoaderPriority());
Expand Down
Expand Up @@ -15,20 +15,20 @@
*/
package com.thoughtworks.go.server.util;

import com.thoughtworks.go.server.Jetty9Server;
import com.thoughtworks.go.server.JettyServer;
import com.thoughtworks.go.util.SystemEnvironment;
import org.eclipse.jetty.server.*;

public class GoPlainSocketConnector implements GoSocketConnector {
private final Connector httpConnector;
private final SystemEnvironment systemEnvironment;

public GoPlainSocketConnector(Jetty9Server server, SystemEnvironment systemEnvironment) {
public GoPlainSocketConnector(JettyServer server, SystemEnvironment systemEnvironment) {
this.systemEnvironment = systemEnvironment;
httpConnector = plainConnector(server);
}

private Connector plainConnector(Jetty9Server server) {
private Connector plainConnector(JettyServer server) {
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setOutputBufferSize(systemEnvironment.get(SystemEnvironment.RESPONSE_BUFFER_SIZE));
httpConfig.setSendServerVersion(false);
Expand Down
Expand Up @@ -15,14 +15,16 @@
*/
package com.thoughtworks.go.server.util;

import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.server.Request;

import javax.servlet.ServletRequestWrapper;
import java.util.function.Function;

public class Jetty9Request implements ServletRequest {
private Request request;
public class JettyRequest implements ServletRequest {
private final Request request;

public Jetty9Request(javax.servlet.ServletRequest request) {
public JettyRequest(javax.servlet.ServletRequest request) {
while (request instanceof ServletRequestWrapper) {
request = ((ServletRequestWrapper) request).getRequest();
}
Expand All @@ -31,23 +33,8 @@ public Jetty9Request(javax.servlet.ServletRequest request) {
}

@Override
public String getUrl() {
return request.getRootURL().append(getUriAsString()).toString();
}

@Override
public String getUriPath() {
return request.getHttpURI().getPath();
}

@Override
public String getUriAsString() {
return request.getHttpURI().getPathQuery();
}

@Override
public void setRequestURI(String uri) {
request.getHttpURI().setPath(uri);
public void modifyPath(Function<String, String> pathModifier) {
request.setHttpURI(HttpURI.build(request.getHttpURI()).path(pathModifier.apply(request.getHttpURI().getPath())).asImmutable());
}

@Override
Expand Down
Expand Up @@ -17,11 +17,10 @@

import org.eclipse.jetty.server.Response;

public class Jetty9Response implements ServletResponse {
private javax.servlet.ServletResponse servletResponse;

public Jetty9Response(javax.servlet.ServletResponse servletResponse) {
public class JettyResponse implements ServletResponse {
private final javax.servlet.ServletResponse servletResponse;

public JettyResponse(javax.servlet.ServletResponse servletResponse) {
this.servletResponse = servletResponse;
}

Expand Down
Expand Up @@ -16,15 +16,15 @@
package com.thoughtworks.go.server.util;

//Do not delete. Invoked using reflection
public class Jetty9ServletHelper extends ServletHelper {
public class JettyServletHelper extends ServletHelper {
@Override
public ServletRequest getRequest(javax.servlet.ServletRequest servletRequest) {
return new Jetty9Request(servletRequest);
return new JettyRequest(servletRequest);
}

@Override
public ServletResponse getResponse(javax.servlet.ServletResponse servletResponse) {
return new Jetty9Response(servletResponse);
return new JettyResponse(servletResponse);
}

}
Expand Down
File renamed without changes.
Expand Up @@ -16,6 +16,7 @@
package com.thoughtworks.go.server;

import com.thoughtworks.go.util.SystemEnvironment;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.webapp.WebAppContext;
Expand All @@ -29,6 +30,7 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
Expand Down Expand Up @@ -193,12 +195,9 @@ private void assertLoadingResponseInHTML(MockResponse response, String expectedB
done());
}

private MockResponse request(String target, String acceptHeaderValue) throws Exception {
private MockResponse request(String target, String acceptHeaderValue) throws IOException, ServletException {
Request baseRequest = mock(Request.class);
HttpFields httpFields = new HttpFields();
if (acceptHeaderValue != null) {
httpFields.add("Accept", acceptHeaderValue);
}
HttpFields httpFields = acceptHeaderValue != null ? HttpFields.from(new HttpField("Accept", acceptHeaderValue)) : HttpFields.from();
lenient().when(baseRequest.getHttpFields()).thenReturn(httpFields);

HttpServletRequest servletRequest = mock(HttpServletRequest.class);
Expand Down Expand Up @@ -227,7 +226,7 @@ private void loadingPageIsSetTo(String loadingPageResourcePath) {
when(systemEnvironment.get(SystemEnvironment.LOADING_PAGE)).thenReturn(loadingPageResourcePath);
}

private class MockResponse {
private static class MockResponse {
private HttpServletResponse response;
private PrintWriter printWriter;

Expand Down
Expand Up @@ -22,9 +22,9 @@
import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;

import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

Expand Down

0 comments on commit 5d7f3cc

Please sign in to comment.