Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] ContextHandlerCollection as a child handler of ContextHandler

Looking at having the following:

public class ContextPlay {
  public static void main(String[] args) throws Exception {
    Server server = new Server(8000);

    ContextHandlerCollection chc = new ContextHandlerCollection();
    chc.setHandlers(new Handler[] {new PrintHandler("/a"), new PrintHandler("/b"), new PrintHandler("/c")});

    ContextHandler ch = new ContextHandler("/base")
    ch.setHandler(chc);

    server.setHandler(ch);

    server.start();
    server.join();
  }

  public static class PrintHandler extends ContextHandler {
    public PrintHandler(String context) {
      super(context);
    }

    @Override
    public void doHandle(String target, Request baseRequest, HttpServletRequest request,
        HttpServletResponse response) throws IOException, ServletException {
      response.getWriter().print(getContextPath());
      baseRequest.setHandled(true);
    }
  }
}

So a base ContextHandler with the ContextHandlerCollection as the ContextHandler's child handler.

A request to http://localhost:8000/base/c will 404, a request to http://localhost:8000/base/a will succeed. Is this sort of chaining meant to be supported by Jetty? It would certainly be useful.

Thanks, Neil

Back to the top