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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
* limitations under the License.
*/
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.resource.Resource;

/* This is a server that displays live information from a StatsPlugin.
*
Expand All @@ -42,11 +46,24 @@ public StatsServer(StatsPlugin plugin, int port) throws Exception {
this.httpServer = new Server(port);
this.plugin = plugin;

ServletHandler handler = new ServletHandler();
httpServer.setHandler(handler);
handler.addServletWithMapping(new ServletHolder(new StaticServlet()), "/");
ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContext.setContextPath("/");

handler.addServletWithMapping(new ServletHolder(new StatsServlet(plugin)), "/");
ServletHolder servletHolder = new ServletHolder(new StatsServlet(plugin));
servletContext.addServlet(servletHolder, "/");

ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setBaseResource(Resource.newClassPathResource("/org/apache/avro/ipc/stats/static"));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
resourceHandler.setBaseResource(Resource.newClassPathResource("/org/apache/avro/ipc/stats/static"));
Resource baseResource = Resource.newClassPathResource("/org/apache/avro/ipc/stats/static");
if (baseResource == null) {
throw new IllegalStateException("Static resources not found on classpath");
}
resourceHandler.setBaseResource(baseResource);

since the classpath is provided by another Maven module IMO it would be good to make this check here and fail early if for some reason this package is not available

resourceHandler.setDirectoriesListed(false); // Optional: prevent directory listing

ContextHandler staticContext = new ContextHandler();
staticContext.setContextPath("/static");
staticContext.setHandler(resourceHandler);

HandlerList handlers = new HandlerList();
handlers.setHandlers(new org.eclipse.jetty.server.Handler[] { staticContext, servletContext });
Comment on lines +63 to +64
Copy link
Member

Choose a reason for hiding this comment

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

this can be simplified to:

Suggested change
HandlerList handlers = new HandlerList();
handlers.setHandlers(new org.eclipse.jetty.server.Handler[] { staticContext, servletContext });
HandlerList handlers = new HandlerList(staticContext, servletContext);


httpServer.setHandler(handlers);

httpServer.start();
}
Expand Down