wikier
wikier

Reputation: 2566

rest - RESTEasy cutting trailing slash off @Path

RESTEasy looks to ignore the trailing slash, so I cannot write two different web services with and without an trailing slash, and this example shows:

@Path("foo")
public class TestClass {

    @GET
    @Path("/bar")
    public Response bar1() {
        ...
    }

    @GET
    @Path("/bar/")
    public Response bar2() {
        ...
    }
}

With RESTEasy the GET-request to /foo/bar as well as /foo/bar/ are handled by bar2(). Considering RFC3986 and the JAX-RS Spec I do not see why this is handled like this. Could this be a problem with RESTEasy or is there something I oversee?

Upvotes: 4

Views: 3259

Answers (1)

Lan
Lan

Reputation: 6660

Here is what JAX-RS specification says

3.7 Matching Requests to Resource Methods

3.7.3 Converting URI Templates to Regular Expressions

  1. URI encode the template, ignoring URI template variable specifications.
  2. Escape any regular expression characters in the URI template, again ignoring URI template variable specifications.
  3. Replace each URI template variable with a capturing group containing the specified regular expression or ‘([^/]+?)’ if no regular expression is specified.
  4. If the resulting string ends with ‘/’ then remove the final character.
  5. Append ‘(/.*)?’ to the result.

As I read it, the RESTEasy implements the spec correctly.

Upvotes: 4

Related Questions