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

upgrade to using jetty 12.x using ee9 (jakarta 5.x) #2670

Merged
merged 2 commits into from
Aug 5, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions containers/jetty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<properties>
<kinesis.logback.version>2.1.3</kinesis.logback.version>
<code.coverage.min>0.8893</code.coverage.min>
<code.coverage.min>0.8975</code.coverage.min>
</properties>

<dependencies>
Expand Down Expand Up @@ -111,8 +111,13 @@
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-servlets</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
Expand All @@ -126,8 +131,8 @@
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,18 @@
import com.yahoo.athenz.container.filter.HealthCheckFilter;
import jakarta.servlet.DispatcherType;
import org.eclipse.jetty.deploy.DeploymentManager;
import org.eclipse.jetty.deploy.PropertiesConfigurationManager;
import org.eclipse.jetty.deploy.bindings.DebugListenerBinding;
import org.eclipse.jetty.deploy.providers.WebAppProvider;
import org.eclipse.jetty.deploy.providers.ContextProvider;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpHeaderValue;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.ArrayRetainableByteBufferPool;
import org.eclipse.jetty.rewrite.handler.HeaderPatternRule;
import org.eclipse.jetty.rewrite.handler.RewriteHandler;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.StatisticsHandler;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.ee9.servlet.FilterHolder;
import org.eclipse.jetty.ee9.servlet.ServletContextHandler;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.ssl.KeyStoreScanner;
import org.eclipse.jetty.util.ssl.SslContextFactory;
Expand All @@ -71,7 +67,7 @@ public class AthenzJettyContainer {

private Server server = null;
private String banner = null;
private HandlerCollection handlers = null;
private ContextHandlerCollection handlers = null;
private PrivateKeyStore privateKeyStore;
private final AthenzConnectionListener connectionListener = new AthenzConnectionListener();
private final JettyConnectionLoggerFactory jettyConnectionLoggerFactory = new JettyConnectionLoggerFactory();
Expand All @@ -84,7 +80,7 @@ Server getServer() {
return server;
}

HandlerCollection getHandlers() {
ContextHandlerCollection getHandlers() {
return handlers;
}

Expand Down Expand Up @@ -169,8 +165,8 @@ public void addServletHandlers(String serverHostName) {
if (!keepAlive) {
HeaderPatternRule disableKeepAliveRule = new HeaderPatternRule();
disableKeepAliveRule.setPattern("/*");
disableKeepAliveRule.setName(HttpHeader.CONNECTION.asString());
disableKeepAliveRule.setValue(HttpHeaderValue.CLOSE.asString());
disableKeepAliveRule.setHeaderName(HttpHeader.CONNECTION.asString());
disableKeepAliveRule.setHeaderName(HttpHeaderValue.CLOSE.asString());
rewriteHandler.addRule(disableKeepAliveRule);
}

Expand All @@ -189,8 +185,8 @@ public void addServletHandlers(String serverHostName) {
for (Map.Entry<String, String> responseHeader : responseHeaders.entrySet()) {
HeaderPatternRule rule = new HeaderPatternRule();
rule.setPattern("/*");
rule.setName(responseHeader.getKey());
rule.setValue(responseHeader.getValue());
rule.setHeaderName(responseHeader.getKey());
rule.setHeaderValue(responseHeader.getValue());
rewriteHandler.addRule(rule);
}
}
Expand All @@ -200,8 +196,8 @@ public void addServletHandlers(String serverHostName) {

HeaderPatternRule hostNameRule = new HeaderPatternRule();
hostNameRule.setPattern("/*");
hostNameRule.setName(HttpHeader.HOST.asString());
hostNameRule.setValue(serverHostName);
hostNameRule.setHeaderName(HttpHeader.HOST.asString());
hostNameRule.setHeaderValue(serverHostName);
rewriteHandler.addRule(hostNameRule);

handlers.addHandler(rewriteHandler);
Expand All @@ -225,6 +221,7 @@ public void addServletHandlers(String serverHostName) {
}

// check to see if graceful shutdown support is enabled

boolean gracefulShutdown = Boolean.parseBoolean(
System.getProperty(AthenzConsts.ATHENZ_PROP_GRACEFUL_SHUTDOWN, "false"));
if (gracefulShutdown) {
Expand Down Expand Up @@ -263,39 +260,26 @@ public void addServletHandlers(String serverHostName) {
contexts.addHandler(servletCtxHandler);

DeploymentManager deployer = new DeploymentManager();

boolean debug = Boolean.parseBoolean(System.getProperty(AthenzConsts.ATHENZ_PROP_DEBUG, "false"));
if (debug) {
DebugListener debugListener = new DebugListener(System.err, true, true, true);
server.addBean(debugListener);
deployer.addLifeCycleBinding(new DebugListenerBinding(debugListener));
}

deployer.setContexts(contexts);
deployer.setContextAttribute(
"org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
".*/servlet-api-[^/]*\\.jar$");

final String jettyHome = System.getProperty(AthenzConsts.ATHENZ_PROP_JETTY_HOME, getRootDir());
WebAppProvider webappProvider = new WebAppProvider();
ContextProvider webappProvider = new ContextProvider();
webappProvider.setEnvironmentName("ee9");
webappProvider.setMonitoredDirName(jettyHome + "/webapps");
webappProvider.setScanInterval(60);
webappProvider.setExtractWars(true);
webappProvider.setConfigurationManager(new PropertiesConfigurationManager());
webappProvider.setParentLoaderPriority(true);

// set up a Default web.xml file. file is applied to a Web application
// before its own WEB_INF/web.xml

setDefaultsDescriptor(webappProvider, jettyHome);
final String jettyTemp = System.getProperty(AthenzConsts.ATHENZ_PROP_JETTY_TEMP, jettyHome + "/temp");
webappProvider.setTempDir(new File(jettyTemp));

deployer.addAppProvider(webappProvider);
server.addBean(deployer);
}

private void setDefaultsDescriptor(WebAppProvider webappProvider, String jettyHome) {
private void setDefaultsDescriptor(ContextProvider webappProvider, String jettyHome) {

// set up a Default web.xml file. file is applied to a Web application before
// its own WEB_INF/web.xml. check for file existence
Expand Down Expand Up @@ -566,32 +550,7 @@ public void createServer(int maxThreads) {
threadPool.setMaxThreads(maxThreads);

server = new Server(threadPool);

// if configured to override Jetty's default retainable byte buffer pool,
// make sure the ArrayRetainableByteBufferPool is added before the server is started

boolean setRetainableByteBufferPoolEnabled = Boolean.parseBoolean(
System.getProperty(AthenzConsts.ATHENZ_PROP_SERVER_POOL_SET_ENABLED, "false"));

if (setRetainableByteBufferPoolEnabled) {
long maxHeapMemory = Long.parseLong(
System.getProperty(AthenzConsts.ATHENZ_PROP_SERVER_POOL_MAX_HEAP_MEMORY, "134217728"));
long maxDirectMemory = Long.parseLong(
System.getProperty(AthenzConsts.ATHENZ_PROP_SERVER_POOL_MAX_DIRECT_MEMORY, "134217728"));
int minCapacity = Integer.parseInt(
System.getProperty(AthenzConsts.ATHENZ_PROP_SERVER_POOL_MIN_CAPACITY, "0"));
int maxCapacity = Integer.parseInt(
System.getProperty(AthenzConsts.ATHENZ_PROP_SERVER_POOL_MAX_CAPACITY, "-1"));
int factor = Integer.parseInt(
System.getProperty(AthenzConsts.ATHENZ_PROP_SERVER_POOL_FACTOR, "-1"));
int maxBucketSize = Integer.parseInt(
System.getProperty(AthenzConsts.ATHENZ_PROP_SERVER_POOL_MAX_BUCKET_SIZE, "1000"));

server.addBean(new ArrayRetainableByteBufferPool(minCapacity, factor, maxCapacity,
maxBucketSize, maxHeapMemory, maxDirectMemory));
}

handlers = new HandlerCollection();
handlers = new ContextHandlerCollection();
server.setHandler(handlers);
}

Expand Down
Loading
Loading