Skip to main content

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

Hi Jan, thanks for the response, 

Would be useful in my particular use case to have all requests for a certain base path to have to pass through a handler, so:

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

    HandlerWrapper wrapper = new HandlerWrapper();
    wrapper.setHandler(chc);

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

Or perhaps, have a AbstractHandler instead of the wrapper that could reject requests before passing it onto the ContextHandlerCollection() if the request is missing required data common to many context handlers.


The reason for this is that we have a few context handlers that provide some read only internal information about the server, such as ThreadPool stats, a jetty StatisticsHandler, we don't want these to be publicly viewable but want them all to exist on a base context, something like /internal/httpstats, /internal/dbstats.  That way we can stick an authentication check on the handler after /internal/ ContextHandler but before it hits the ContextHandlerCollection. 

Cheers

On Wed, Sep 10, 2014 at 10:58 PM, Jan Bartel <janb@xxxxxxxxxxx> wrote:
Neil,

I'm not really sure why you want to do that?

It is the ContextHandlerCollection that has the smarts to choose
amongst the best context paths that match the request. As the request
is eg  /base/a/xxxx then none of your PrintHandlers match that.

This will certainly work:
chc.setHandlers(new Handler[] {new PrintHandler("/base/a"), new
PrintHandler("/base/b"), new PrintHandler("/base/c")});

cheers
Jan

On 9 September 2014 21:46, Neil Williams <neil@xxxxxxxxxxx> wrote:
> 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
>
> _______________________________________________
> jetty-users mailing list
> jetty-users@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from
> this list, visit
> https://dev.eclipse.org/mailman/listinfo/jetty-users



--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
'Expert Jetty/CometD developer,production,operations advice'
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


Back to the top