vipx / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Servlet mapping does not match base on SUFFIX style #741

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Description of the issue:

Steps to reproduce:
1. Bind a servlet to a path with serve("/myservlet/*").with(MyServlet.class) 
that handles GETs.
2. Send a GET request to the server at the path /myservlet.
3. The bound servlet definition with Guice will not match the path in the 
request due to the way that the ServletStyleUriPatternMatcher creates its 
pattern.

A change like this is one possible solution:

public ServletStyleUriPatternMatcher(String pattern) {
      if (pattern.startsWith("*")) {
        this.pattern = pattern.substring(1);
        this.patternKind = Kind.PREFIX;
      } else if (pattern.endsWith("/*")) {
        this.pattern = pattern.substring(0, pattern.length() - 2);
        this.patternKind = Kind.SUFFIX;
      } else {
        this.pattern = pattern;
        this.patternKind = Kind.LITERAL;
      }
    }

The SUFFIX style will correctly match both '/myservlet' and 
'/myservlet/something' paths which matches the servlet specification in section 
SRV.11.2.

Original issue reported on code.google.com by ben.and...@gmail.com on 8 Feb 2013 at 6:24