1
votes

I'm trying to expose a REST service through OSGi (using Apache Felix). I'm using the osgi-jax-rs-connector to publish the resource. Here is the resource interface:

@Path("/bingo")
public interface BingoService {

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/lottery")
List<Integer> getLottery();
}

The implementation uses DS annotation to obtain reference to a provided service in container:

@Component(
    immediate = true,
    service = BingoService.class,
    properties = "jersey.properties")
public class Bingo implements BingoService {

@Reference
private RandomNumberGenerator rng;

@Activate
public void activateBingo() {
    System.out.println("Bingo Service activated using " +
                        rng.getClass().getSimpleName());
}

@Override
public List<Integer> getLottery() {
    List<Integer> result = new ArrayList<>();
    for (int i = 5; i > 0; i--) {
        result.add(rng.nextInt());
        }
    return result;
    }
}

jersey.properties simply contains this line

service.exported.interfaces=*

When I deploy the bundle it starts and register the service correctly. But if I go to http://localhost:8181/services/bingo/lottery I get 404. Could someone point me to the issue or give me some advice on where to look?

1

1 Answers

0
votes

On reading the documentation for OSGi - JAX-RS Connector, it expects to find the annotations @Path or @Provider on the service instance object. You have placed them instead on an interface implemented by the component.

I'm not sure what the purpose of the BingoService interface is. This is not required for JAX-RS services. Normally you would register the resource class using its own type (e.g. service=Bingo.class) or simply java.lang.Object.