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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
package org.apache.avro.ipc.jetty;

import org.apache.avro.ipc.stats.StatsPlugin;
import org.apache.avro.ipc.stats.StatsServlet;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -19,9 +15,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.avro.ipc.jetty;

import org.apache.avro.ipc.stats.StatsPlugin;
import org.apache.avro.ipc.stats.StatsServlet;

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 +48,28 @@ 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("/");

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

HandlerList handlers = new HandlerList(servletContext);

Resource classPathResource = Resource.newClassPathResource("/org/apache/avro/ipc/stats/static");
if (classPathResource.exists() && classPathResource.isDirectory()) {
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setBaseResource(classPathResource);
resourceHandler.setDirectoriesListed(false); // Optional: prevent directory listing

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

handlers.prependHandler(staticContext);
}

handler.addServletWithMapping(new ServletHolder(new StatsServlet(plugin)), "/");
httpServer.setHandler(handlers);

httpServer.start();
}
Expand Down