users@jersey.java.net

Re: [Jersey] Common resource path issue

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 27 Oct 2009 09:00:36 +0100

Hi,

JAX-RS and Jersey does not support the "merging" of root resource
classes with the same @Path value or backtracking in the matching
algorithm.

So it is not possible to support two root resource classes with the
same @Path value.

You need to do:

@Path("/resource")
public class MergedResource {

     @POST
     @Path("/a")
     public void echo(String s) {
         ...
     }

     @POST
     @Path("/b")
     public void echo(String s) {
        ...
     }
}


Part of the problem with merging or backtracking is when you have the
following:

@Path("/resource")
public class OldResource {

     @POST
     public void echo(String s) {
         ...
     }
}

@Path("/resource")
public class NewResource {

     @POST
     public void echo(String s) {
        ...
     }
}


Which @POST method takes precedence? Granted in such cases it is
possible to detect conflicts and result in a deployment error.

In addition distributing the functionality for a resource over
multiple classes can make it harder to understand the working of the
application.

This is of course at the expense of having a pre-compiled JAX-RS
application to which you want to add further functionality without re-
compiling or modifying the existing code. We did consider this case
but thought it best to keep things simple at least for JAX-RS 1.x.

Paul.

On Oct 27, 2009, at 5:38 AM, Dmitry Shaparev wrote:

> Jersey 1.0.1 has the following issue:
>
> @Path("/resource")
> public class OldResource {
>
> @POST
> @Path("/a")
> public void echo(String s) {
> ...
> }
> }
>
> @Path("/resource")
> public class NewResource {
>
> @POST
> @Path("/b")
> public void echo(String s) {
> ...
> }
> }
>
> Common resource path makes available only one of them, therefore there
> is no availability to use both resources. Could please you clarify has
> a new Jersey release fix for this issue?
>
> Could you provide a way to implement overriding of default action in
> Jersey 1.0.1 to make available both resources with common path?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>