From ce6fe18c031f55d16967ffb7c0db72e7e3522172 Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Wed, 11 Sep 2024 16:56:17 -0500 Subject: [PATCH] fix: Disable Jetty's webapp configuration Simplifies embedded server setup slightly, and avoid calling reflective and ServiceLoader based configuration apis. Fixes #6049 --- .../server/jetty/JettyBackedGrpcServer.java | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/server/jetty/src/main/java/io/deephaven/server/jetty/JettyBackedGrpcServer.java b/server/jetty/src/main/java/io/deephaven/server/jetty/JettyBackedGrpcServer.java index 641948d9489..afae0fca952 100644 --- a/server/jetty/src/main/java/io/deephaven/server/jetty/JettyBackedGrpcServer.java +++ b/server/jetty/src/main/java/io/deephaven/server/jetty/JettyBackedGrpcServer.java @@ -47,13 +47,12 @@ import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.servlet.ErrorPageErrorHandler; import org.eclipse.jetty.servlet.FilterHolder; +import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlets.CrossOriginFilter; import org.eclipse.jetty.util.MultiException; import org.eclipse.jetty.util.component.Graceful; -import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.ssl.SslContextFactory; -import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.websocket.jakarta.common.SessionTracker; import org.eclipse.jetty.websocket.jakarta.server.config.JakartaWebSocketServletContainerInitializer; import org.eclipse.jetty.websocket.jakarta.server.internal.JakartaWebSocketServerContainer; @@ -61,8 +60,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import java.io.IOException; -import java.io.UncheckedIOException; -import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.Collection; @@ -93,17 +90,12 @@ public JettyBackedGrpcServer( jetty = new Server(); jetty.addConnector(createConnector(jetty, config)); - final WebAppContext context = - new WebAppContext(null, "/", null, null, null, new ErrorPageErrorHandler(), NO_SESSIONS); - try { - String knownFile = "/ide/index.html"; - URL ide = JettyBackedGrpcServer.class.getResource(knownFile); - Resource jarContents = Resource.newResource(ide.toExternalForm().replace("!" + knownFile, "!/")); - context.setBaseResource(ControlledCacheResource.wrap(jarContents)); - } catch (IOException ioException) { - throw new UncheckedIOException(ioException); - } - context.setInitParameter(DefaultServlet.CONTEXT_INIT + "dirAllowed", "false"); + final ServletContextHandler context = + new ServletContextHandler(null, "/", null, null, null, new ErrorPageErrorHandler(), NO_SESSIONS); + String knownFile = "/ide/index.html"; + URL ide = JettyBackedGrpcServer.class.getResource(knownFile); + String path = ide.toExternalForm().replace("!" + knownFile, "!/"); + context.addServlet(servletHolder("default", path), "/*"); // Cache all of the appropriate assets folders for (String appRoot : List.of("/ide/", "/iframe/table/", "/iframe/chart/", "/iframe/widget/")) { @@ -178,7 +170,7 @@ public JettyBackedGrpcServer( // Wire up /js-plugins/* // TODO(deephaven-core#4620): Add js-plugins version-aware caching context.addFilter(NoCacheFilter.class, JS_PLUGINS_PATH_SPEC, EnumSet.noneOf(DispatcherType.class)); - context.addServlet(servletHolder("js-plugins", jsPlugins.filesystem()), JS_PLUGINS_PATH_SPEC); + context.addServlet(servletHolder("js-plugins", jsPlugins.filesystem().toString()), JS_PLUGINS_PATH_SPEC); // Set up websockets for grpc-web - depending on configuration, we can register both in case we encounter a // client using "vanilla" @@ -380,12 +372,12 @@ public void onClosed(Connection connection) { return serverConnector; } - private static ServletHolder servletHolder(String name, URI filesystemUri) { + private static ServletHolder servletHolder(String name, String resources) { final ServletHolder jsPlugins = new ServletHolder(name, DefaultServlet.class); // Note, the URI needs explicitly be parseable as a directory URL ending in "!/", a requirement of the jetty // resource creation implementation, see // org.eclipse.jetty.util.resource.Resource.newResource(java.lang.String, boolean) - jsPlugins.setInitParameter("resourceBase", filesystemUri.toString()); + jsPlugins.setInitParameter("resourceBase", resources); jsPlugins.setInitParameter("pathInfoOnly", "true"); jsPlugins.setInitParameter("dirAllowed", "false"); jsPlugins.setAsyncSupported(true);