[undertow-dev] Help Configuring Handlers

Stuart Douglas sdouglas at redhat.com
Sun Mar 9 16:36:55 EDT 2014



Ari King wrote:
> Something like this:
>
> PathHandler root = new PathHandler();
> root.addExactPath("/", servlet-root-handler);
> root.addExactPath("/static-stuff", new ResourceHandler(...));

You need root.addPrefixPath() rather than addExactPath(). addExactPath 
will only match the exact URL, (so /static-stuff, not 
/static-stuff/mystuff).

Your other problem is that you are not specifying a resource manager for 
the resource handler (this is probably an issue on my part, it really 
should required it in the constructor, I will fix).
Your new code should look like:

root.addPrefixPath("/", servlet-root-handler);
root.addPrefixPath("/static-stuff", Handlers.resourceHandler(new 
ClassPathResourceManager(getClass().getClassLoader(), "")));

ClassPathResourceManager serves up resources from the class path. It 
takes the class loader to use, and the prefix that you want to serve the 
resources from (so you can serve from a specific package for instance).
Stuart


>
> this way you map your servlet app to / and then override what ever
> you want below it with resource handler.
>
>
> Don't mean to belabour this seemingly straightforward matter, but I
> just can't get undertow to work with custom path handler settings. The
> custom path handler won't serve static files out of
> "src/main/java/resources/" or recognized the intended jaxrs path of
> http://localhost:8080/example/1. I've pasted my setup here
> <http://pastebin.com/W3HEhqQd>; does anyone see what the matter is?
> Thanks.
>
> -Ari
> _______________________________________________
> undertow-dev mailing list
> undertow-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/undertow-dev


More information about the undertow-dev mailing list