"rewrite URLs that don`t match any servlet or files"

Why not just have a Error handler on status code 404 instead?
This is the easiest approach.
Make it return whatever you want, rewrite it, etc...

Alternatively, if you don't rely on welcome files, you could map your
welcome files to a servlet name.
That way it runs if the incoming path doesn't match a servlet, and not a
directly mentioned static file name.
Make your servlet do what you need.

Option 3 is to provide your own DefaultServlet behavior (mapped to
`<url-pattern>/</url-pattern>`.
Lets call this MyDefaultServlet.
If you get called, then you'll know that you have matched no Servlets.
Then it's just a matter of returning the static file (if it exists), or
rewriting the URL it that doesn't match.
Check out the code for DefaultServlet, you'll essentially want to have a
different doGet()
https://github.com/eclipse/jetty.project/blob/b4ab8a07c12cd8c3bd5f242b02ab37c61ab06676/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java#L456-L461

protected void doGet(HttpServletRequest request, HttpServletResponse
response)
    throws ServletException, IOException
    {
        if(!_resourceService.doGet(request,response))
        {
            // didn't serve a static file, do your special logic here.
            response.sendRedirect("/other/path/that/I/want/to/rewrite/to");
         }
    }




Joakim Erdfelt / [email protected]


On Fri, Nov 30, 2018 at 12:49 PM PETER CURRIVAN <[email protected]>
wrote:

> Nicolas Therrien et al.,
>
>
>
> Thank you for sharing your custom RewriteHandler for use with Angular 6
> routing.  I am having trouble using it, however, because I am using XML
> configuration (non-embedded Jetty).  My problem is I do not know how to
> access a reference to the WebAppContext in my jetty-rewrite.xml file.
> Whereas you have instantiated the WebAppContext and the
> Html5PushStateConditionalRewriteHandler in a single Java file, and can
> simply pass the reference, I am seemingly forced to configure these objects
> in separate Jetty IoC XML files (jetty-web.xml configures the WebAppContext
> and jett-rewrite.xml configures the
> Html5PushStateConditionalRewriteHandler).
>
>
>
> Do you (or anyone else reading this) know a way I might access a reference
> to the WebAppContext configured in jetty-web.xml from within
> jetty-rewrite.xml?  Or perhaps another way to access the “mappedServlet”
> within the custom RewriteHandler?
>
>
>
> I tried adding an id to the WebAppContext in jetty-web.xml and using a Ref
> tag in jetty-rewrite.xml but the reference comes back null.
>
>
>
> jetty-web.xml:
>
> …
>
> <Configure id="webAppContext"
> class="org.eclipse.jetty.webapp.WebAppContext">
>
> …
>
>
>
> jetty-rewrite.xml:
>
> …
>
> <Configure id="Server" class="org.eclipse.jetty.server.Server">
>
>   <Call name="insertHandler">
>
>     <Arg>
>
>       <New class="my.package.Html5PushStateConditionalRewriteHandler">
>
>         <Arg name="webAppContext"><Ref refid="webAppContext"/></Arg>
>
> …
>
>
>
> Thanks,
>
> Peter Currivan
> _______________________________________________
> jetty-users mailing list
> [email protected]
> To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit
> https://www.eclipse.org/mailman/listinfo/jetty-users
_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users

Reply via email to