users@jersey.java.net

Re: [Jersey] Annotation Inheritance

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 30 Oct 2009 17:07:47 +0100

On Oct 30, 2009, at 4:46 PM, animesh sonkar wrote:

> Yeah i solved this one too...
> public interface TestInterface {
>
> @Path("/test")
> @GET
> @Produces("text/plain")
> public String sayHello();
> }
>
> Note @path here :
>
> @Path("")
> public class TestIMPL implements TestInterface {
>
> public String sayHello() {
> // TODO Auto-generated method stub
> return "Hello World";
> }
>
> This solves my problem. Including @Path just lets the
> ServletContainer know that this is a Root Resource and no errors are
> thrown at startup.
>
> The resource is now accessible using "/test".
>
> But i have a doubt, could this be a bug in jersey?

Not a bug. An empty path is allowed on a root resource class.


> If yes, i cannot rely on @Path("") in IMPL.
>
> Also i obseerved that.
> if the impl was
> @Path("/dummy")
> public class TestIMPL implements TestInterface {
>
> public String sayHello() {
> // TODO Auto-generated method stub
> return "Hello World";
> }
> then
> "/dummy" worked (sorry about previous post in which i mentioned this
> did not work)
> also
> "/dummy/test" gave me the same result....
> Fits in the REST context? or another bug in jersey?
>

Only "/dummy/test" should work. So in that respect there is a bug.

>
>
> Thanks i got the problem. Shifted @Path to TestIMPL and things were
> smooth
>
> But my whole intention was to provide an interface with @Path("/test")
>

JAX-RS is POJO-based so it is not always necessary to separate out
into an interface and implementation like one would do with say JAX-WS
or RMI. The primary interface you are implementing to is the *HTTP*
interface. So one could scope out what that HTTP interface needs to be
and let the implementor use JAX-RS to implement according their
implementation design.

Paul.