Hi Joakim,
Those are interesting workarounds. I haven't tried the DefaultServlet idea, but I remember you had suggested using the error handler back when i first asked about pushstate in the original thread. I tried several techniques but it didn`t work for me. I actually lost a lot of time trying to find a way to make one that would work. Here's what I had tried:
Note: i used parentheses below to indicate whether or not handlers are set inside the webapp context or chained together at a higher level. The main webapp context has its own error handler built in.
(WebAppContext -> Servlet -> CustomErrorHandler -> ErrorHandlingServlet)
This was your suggestion. I couldn't get it to work because I couldn't figure out how to get the error handling servlet to return the index.html along with the appropriate parameter. Perhaps if you gave us an example as to how to return the index.html file with parameters? This could work in theory.
Rewrite Handler -> (WebAppContext -> Servlet -> DefaultErrorHandler)
This didn't work because we can't do conditional handling in the rewriter. Images and servlet would all return the contents of index.html. There is no support for conditional rewriting on Jetty.
(WebAppContext -> Servlet -> DefaultErrorHandler) -> RewriteHandler -> WebAppContext...
While this would fix my earlier problem of not being able to feed the rewritten path in the file server, this didn't work because the error handler would stop the chain.
(WebAppContext -> Servlet -> null error handler) -> RewriteHandler -> WebAppContext...
This didn't work because the Default error handler would still stop the chain. If error handler is null, the code for WebAppContext instantiates a DefaultErrorHandler automatically.
(WebAppContext -> Servlet ->
CustomPassthroughErrorHandler ) -> RewriteHandler -> WebAppContext...
In this attempt, i created a custom error handler which would ignore errors and let them trough so the chain can keep going. Jetty has a loop detection thing that prevents feeding the path back into the same context.
(WebAppContext with no welcome page -> Servlet -> CustomPassthroughErrorHandler) -> Rewrite Handler -> CustomAngularContext...
In this attempt, I was trying to separate Servlet contexts from File contexts so that Jetty would no longer view this as a loop. I think at that point I felt this was becoming ridiculous so I decided to write the conditional rewrite handler. I felt a conditional rewriter was not only simpler but also a better design because it does what it is meant to do.
By the way, in retrospective, I think the fact that the webapp context automatically instantiates a default error handler if the handler is null, that could be a design issue...
Seems like searches to fix this kind of problems on Java servers is trending. I ran a new search today, and I found this new example example for JBoss Wildfly server which also performs rewriting. Interestingly enough, they too have support for conditional rewriting, see the xml section which checks that the requested resource is neither a real file or servlet path: