1- package org .apache .avro .ipc .jetty ;
2-
3- import org .apache .avro .ipc .stats .StatsPlugin ;
4- import org .apache .avro .ipc .stats .StatsServlet ;
51/*
62 * Licensed to the Apache Software Foundation (ASF) under one
73 * or more contributor license agreements. See the NOTICE file
1915 * See the License for the specific language governing permissions and
2016 * limitations under the License.
2117 */
18+
19+ package org .apache .avro .ipc .jetty ;
20+
21+ import org .apache .avro .ipc .stats .StatsPlugin ;
22+ import org .apache .avro .ipc .stats .StatsServlet ;
23+
2224import org .eclipse .jetty .server .Server ;
23- import org .eclipse .jetty .servlet .ServletHandler ;
25+ import org .eclipse .jetty .server .handler .ContextHandler ;
26+ import org .eclipse .jetty .server .handler .HandlerList ;
27+ import org .eclipse .jetty .server .handler .ResourceHandler ;
28+ import org .eclipse .jetty .servlet .ServletContextHandler ;
2429import org .eclipse .jetty .servlet .ServletHolder ;
30+ import org .eclipse .jetty .util .resource .Resource ;
2531
2632/* This is a server that displays live information from a StatsPlugin.
2733 *
@@ -42,11 +48,28 @@ public StatsServer(StatsPlugin plugin, int port) throws Exception {
4248 this .httpServer = new Server (port );
4349 this .plugin = plugin ;
4450
45- ServletHandler handler = new ServletHandler ();
46- httpServer .setHandler (handler );
47- handler .addServletWithMapping (new ServletHolder (new StaticServlet ()), "/" );
51+ ServletContextHandler servletContext = new ServletContextHandler (ServletContextHandler .SESSIONS );
52+ servletContext .setContextPath ("/" );
53+
54+ ServletHolder servletHolder = new ServletHolder (new StatsServlet (plugin ));
55+ servletContext .addServlet (servletHolder , "/" );
56+
57+ HandlerList handlers = new HandlerList (servletContext );
58+
59+ Resource classPathResource = Resource .newClassPathResource ("/org/apache/avro/ipc/stats/static" );
60+ if (classPathResource .exists () && classPathResource .isDirectory ()) {
61+ ResourceHandler resourceHandler = new ResourceHandler ();
62+ resourceHandler .setBaseResource (classPathResource );
63+ resourceHandler .setDirectoriesListed (false ); // Optional: prevent directory listing
64+
65+ ContextHandler staticContext = new ContextHandler ();
66+ staticContext .setContextPath ("/static" );
67+ staticContext .setHandler (resourceHandler );
68+
69+ handlers .prependHandler (staticContext );
70+ }
4871
49- handler . addServletWithMapping ( new ServletHolder ( new StatsServlet ( plugin )), "/" );
72+ httpServer . setHandler ( handlers );
5073
5174 httpServer .start ();
5275 }
0 commit comments