Hi Scorpio,
One way of doing that would be to implement a sub-resource locator method,
which would do the lookup for you, the following code does not deal with
OSGi
but should give you an idea on how to proceed:
@Path("my-app")
public class MyRootResource {
static Random MyRandom = new Random();
public static interface MyServiceInterface {
@GET
@Produces("text/plain")
public String getIt();
}
public static class MyImpl1 implements MyServiceInterface {
@Override
public String getIt() {
return "impl 1";
}
}
public static class MyImpl2 implements MyServiceInterface {
@Override
public String getIt() {
return "impl 2";
}
}
@Path("service")
public Object getService() {
return lookupServiceImpl();
}
private MyServiceInterface lookupServiceImpl() {
// TODO: a proper OSGi based lookup code comes here:
return MyRandom.nextBoolean() ? new MyImpl1() : new MyImpl2();
}
}
Hope this helps,
~Jakub
On 4.11.2011 8:43, Scorpio wrote:
> I have a service interface which is implemented by many different
> implementations in OSGi. The implementations can be added dynamically in
> OSGi platform.My requirement is that I want to register the interface as a
> Rest Resource, and when ever it gets a hit, the Jersey should bind it to any
> one of the implementations.
>
> Is it possible for this binding to be taken care by Jersey?
>
> Regards
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Registering-an-Inteface-as-a-Rest-Resource-tp6961906p6961906.html
> Sent from the Jersey mailing list archive at Nabble.com.
>