[undertow-dev] Problem using two PathHandlers

electrotype electrotype at gmail.com
Thu Jul 21 14:06:48 EDT 2016


Hi,

I'm using Undertow 1.2.12.Final (for its Java 7 compatibility).

Let's says I have an /exact /path "/aaa/bbb" for which I want to chain two handlers managed by two 
PathHandlers:

- a SecurityInitialHandler
- a ResourceHandler

In other words, the "/aaa/bbb" exact path is a static resource and is protected.

The problem I found is that if the first PathHandler (the one for the SecurityInitialHandler) 
matches, then this code is called, in io.undertow.server.handlers.PathHandler#handleRequest(...) :

/exchange.setRelativePath(match.getRemaining());/

The "/aaa/bbb" path fully matches so the exchange's relativePath is set to "" after that match.

Then, the seconds PathHandler (the one for ResourceHandler) is run. The matching is done using:

/match = pathMatcher.match(exchange.getRelativePath());/

Since the relative path is now "", and not "/aaa/bbb", the ResourceHandler for "/aaa/bbb" is not 
used, even if it exists.

Worst, since the relative path is now "", the path to match will actually be converted to "/". This 
is because of io.undertow.util.PathMatcher#getExactPath(...) :

/return exactPathMatches.get(URLUtils.normalizeSlashes(path));/

The /normalizeSlashes(path)/ method convert "" to "/".

This means that the /default handler/ of the second PathHandler will be used for "/aaa/bbb". If the 
"/" static resource exists, it will be served instead of the "/aaa/bbb" resource.

Maybe I'm missing something about PathHandlers though... Any tips?

Thanks!

Julien



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20160721/84e35ce8/attachment.html 


More information about the undertow-dev mailing list