Search code examples
javajettyjetty-12

Porting from Jetty 11 to Jetty 12. Problem with HandlerList


I am porting application that uses Jetty as a HTTP server from Jetty 11 to Jetty 12. I use my own handler that extends ResourceHandler.

For Jetty 12 I changed many things like request.getRemoteAddr() -> Request.getRemoteAddr(request), and I use Request.Wrapper to change immutable request. But now my problem is a little complicated handler usage that uses HandlerList, but HandlerList is no longer available in Jetty 12.

My code that works in Jetty 11:

static private void set_jetty_handlers(Server server)
    {
    ...
    HandlerList handlers = new HandlerList();

    ServletContextHandler static_handler = new ServletContextHandler();
    static_handler.insertHandler(new GzipHandler());
    static_handler.setContextPath("/");
    static_handler.setBaseResourceAsString(resource_base);
    ...

    // My_jetty_handler extends ResourceHandler
    My_jetty_handler my_handler = new My_jetty_handler();
    my_handler.setWelcomeFiles(new String[] { ... });
    my_handler.setBaseResourceAsString(resource_base);
    my_handler.setCacheControl(MAX_AGE);

    ...
    GzipHandler my_handler_gzip = new GzipHandler();
    my_handler_gzip.addIncludedMimeTypes(...);
    my_handler_gzip.setHandler(my_handler);
    handlers.addHandler(my_handler_gzip);

    handlers.addHandler(static_handler);

    // I want to work with aliases (links and symbolic links)
    ContextHandler context_handler = new ContextHandler();
    context_handler.addAliasCheck(new ApproveAllAliases());
    context_handler.setHandler(handlers);

    InetAccessHandler access_handler = new InetAccessHandler();
    addIPRules(access_handler);
    access_handler.setHandler(context_handler);

    server.setHandler(access_handler);
    }

What should I do to port this from Jetty 11 to Jetty 12?


Solution

  • I used solution from @StephenC comment:

    The replacement is ContextHandlerCollection: https://eclipse.dev/jetty/javadoc/jetty-12/org/eclipse/jetty/server/Handler.Sequence.html