users@jersey.java.net

Re: [Jersey] Possible bug while matching a request to a resource method?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 09 Apr 2009 18:29:54 +0200

Hi Andrew,

Another work around, the third method as follows:

     @POST
     @Path("/{one: (?!abc).*}")
     public Response thirdMethod(@PathParam("one") String one) {


Jersey uses a map of regex to set of HTTP methods.

Because the @Path("/{one: (?!abc).*}") matches the "/text/fred" path
Jersey uses that key, but only the @GET method is a member of of set
of methods returned.

It seems that there needs a map of HTTP method to set of paths.

Could you log an issue?

Thanks,
Paul.

On Apr 9, 2009, at 6:09 PM, Andrew Ochsner wrote:

> Hi guys:
>
> So I'll be honest, I took a look at the JSR311 spec around this and
> I'm not spec-ologist but it feels like this should work. Seems that
> if there's a regex in my @Path annotation then things don't work
> quite as I expected.
>
> Here's a small test
> @Path("/test")
> public class TestResource {
> @GET
> @Path("/{one: abc.*}")
> public Response firstMethod(@PathParam("one") String one) {
> System.out.println("one");
> System.out.println(one);
> return Response.noContent().build(); // 204
> }
>
> @GET
> @Path("/{one: (?!abc).*}")
> public Response secondMethod(@PathParam("one") String one) {
> System.out.println("two");
> System.out.println(one);
> return Response.notModified().build(); // 304
> }
>
> @POST
> @Path("/{one}")
> public Response thirdMethod(@PathParam("one") String one) {
> System.out.println("three");
> System.out.println(one);
> return Response.ok().build(); // 200
> }
> }
>
> And the following results for various requests:
> GET http://localhost:9998/test/abc123 -> 204
> GET http://localhost:9998/test/fred -> 304
> POST http://localhost:9998/test/fred -> 405!! <- NOT 200
>
> This doesn't seem right. As an aside, I noticed that if I set
> "secondMethod" to:
> @GET
> @Path("/{one}")
> public Response secondMethod(@PathParam("one") String one) {
>
> Things work as expected.
>
> Now, I'll be honest, I'm not exactly a regex expert either and I'm
> having a hard time with this. Is there a more correct way to say
> "does not match 'abc'"? I've tried a few combinations including [^a]
> [^b][^c].*
>
> Is this expected behavior or is this a bug? Like I said, I have a
> solution to go forward with, just thought it was worth raising your
> attention to...
>
> Thanks
> Andy O
>