On Aug 28, 2009, at 11:46 PM, exxos wrote:
> Hi,
>
> I'm testing this source code:
>
> @Path("/test")
> public class TestResource {
>
> @Path("{path: /}")
> public TestSubResource getDelegateGet(@PathParam("path") String
> path) {
> // this class to @GET
> return new TestSubResource(path);
> }
> }
>
> Bellow the results I get:
>
> GET http://127.0.0.1:8080/service/test
> returns 405
> >> OK, normal behavior
>
> GET http://127.0.0.1:8080/service/test/
> returns 405
> >> FAILD, we want to call the method getDelegateGet()
>
> GET http://127.0.0.1:8080/service/test//
> returns 200 = Call the method getDelegateGet() (with path equals to
> "/")
> >> OK, normal behavior, but not expected...
>
> Does it possible to catch the "/" (slash) as a resource path?
>
It is not possible to explicitly match a slash.
Instead Jersey has the following rules:
- by default a Path annotation matches a request URI path with and
without a final '/' present.
- if the property FEATURE_REDIRECT [1] is set true, and the path
value of a Path annotation ends in a slash, the
request URI path does not end in a '/' and would otherwise match
the path value if it did, then the client is
(temporarily) redirected to a new URI that is the request URI with
a '/' appended to the the end of the path.
Paul.
[1]
https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey/com/sun/jersey/api/core/ResourceConfig.html
#FEATURE_REDIRECT