Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 322670

Summary: Inconsistent context view in DefaultHandler vs. ContextHandlerCollection
Product: [RT] Jetty Reporter: Gunnar Wagenknecht <gunnar>
Component: serverAssignee: Greg Wilkins <gregw>
Status: CLOSED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3 CC: jetty-inbox
Version: 7.1.4   
Target Milestone: 7.1.x   
Hardware: PC   
OS: All   
Whiteboard:

Description Gunnar Wagenknecht CLA 2010-08-13 12:04:28 EDT
I created a Jetty configuration with a custom ContextHandler (UrlToApplicationHandler). This handler waits for the first hit. If the hit arrives it lazily initializes the real application delegates to this. There can be multiple such handlers (for different URLs) all delegating to the same application.

Initially the stack looks like this:
org.eclipse.jetty.server.Server
 +-HandlerCollection 
    +-ContextHandlerCollection
    |  +-UrlToApplicationHandler [applicationId=myApp, url=http://localhost/test/v1]
    |     +-UrlToApplicationHandler$LazyInitializingHotSwapDelegator
    |  +-UrlToApplicationHandler [applicationId=myApp, url=http://localhost/test]
    |     +-UrlToApplicationHandler$LazyInitializingHotSwapDelegator
    +-DefaultHandler

If I now hit an unmatched URL (http://localhost/) the DefaultHandler triggers and lists both available UrlToApplicationHandler contexts.

DefaultHandler:
/test/v1 @ localhost:80 ---> UrlToApplicationHandler [applicationId=myApp, url=http://localhost/test/v1]
/test @ localhost:80 ---> UrlToApplicationHandler [applicationId=myApp, url=http://localhost/test]


If I then hit an actual context URL the application is initialized lazily and put into the stack (all implemented by my LazyInitializingHotSwapDelegator which is a HotSwapHandler). 

The stack now looks like this:
org.eclipse.jetty.server.Server
 +-HandlerCollection 
    +-ContextHandlerCollection
    |  +-UrlToApplicationHandler [applicationId=myApp, url=http://localhost/test/v1]
    |     +-UrlToApplicationHandler$LazyInitializingHotSwapDelegator
    |       +-MyApplicationHandler [applicationId=myApp]
    |  +-UrlToApplicationHandler [applicationId=myApp, url=http://localhost/test]
    |     +-UrlToApplicationHandler$LazyInitializingHotSwapDelegator
    +-DefaultHandler


If I now hit the DefaultHandler it displays _three_ contexts available.

DefaultHandler:
/test/v1 @ localhost:80 ---> UrlToApplicationHandler [applicationId=myApp, url=http://localhost/test/v1]
/test @ localhost:80 ---> UrlToApplicationHandler [applicationId=myApp, url=http://localhost/test]
/ ---> MyApplicationHandler /,null

However, the MyApplicationHandler actually is not reachable because it's never handled by the ContextHandlerCollection (which is the intended behavior).

I'm wondering if DefaultHandler should have the same view as ContextHandlerCollection?
Comment 1 Greg Wilkins CLA 2010-08-16 08:37:06 EDT
Gunnar,

It is probably a good idea for the default servlet to print the handler tree itself, with any URLs that is can work out.

I've changed this to be an enhancement request and we will see if we can get time for it.... happy for code contributions also.
Comment 2 Greg Wilkins CLA 2011-09-06 00:59:31 EDT
Gunnar,

sorry for long delay.  Also I've changed my mind on this one.  The DefaultHandler just lists all Contexts know to the server.  It can't know if they are actually reachable as there are an infinite number of ways handlers can direct requests to contexts and ContextHandlerCollection is just one way (ok it is the default and most common way).

So I'm going to leave it as is.... but feel free to try to convince me otherwise.

cheers
Comment 3 Gunnar Wagenknecht CLA 2011-09-06 01:52:55 EDT
Not sure I will. I wrote a bunch of new handlers already so this is no longer an issue for me. ;)
Comment 4 Jesse McConnell CLA 2011-09-20 15:52:17 EDT
Resolved -> Closed