Wildfly wierd feature in 8.2.0 — automatic redirect if your path matches a directory under your webapp

1. If there is a directory "abc" under your webapp root directory and there is no index.jsp under this "abc" directory

2. and you request http://xxx/abc regardless of GET or POST method

3. then wildfly will redirect you to: 302, GET http://xxx/abc/

The code is on github

            String remaining = match.getRemaining() == null ? match.getMatched() : match.getRemaining();
            Resource resource = resourceManager.getResource(remaining);
            if (resource == null || !resource.isDirectory()) {
                pathMatchCache.add(path, match);
                return match;
            }

            boolean pathEndsWithSlash = remaining.endsWith("/");
            final String pathWithTrailingSlash = pathEndsWithSlash ? remaining : remaining + "/";

            ServletPathMatch welcomePage = findWelcomeFile(pathWithTrailingSlash, !pathEndsWithSlash);

            if (welcomePage != null) {
                pathMatchCache.add(path, welcomePage);
                return welcomePage;
            } else {
                welcomePage = findWelcomeServlet(pathWithTrailingSlash, !pathEndsWithSlash);
                if (welcomePage != null) {
                    pathMatchCache.add(path, welcomePage);
                    return welcomePage;
                } else if(pathEndsWithSlash) {
                    pathMatchCache.add(path, match);
                    return match;
                } else {
                    ServletPathMatch redirect = new ServletPathMatch(match.getServletChain(), match.getMatched(), match.getRemaining(), REDIRECT, "/");
                    pathMatchCache.add(path, redirect);
                    return redirect;
                }
            }

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.