I am trying to run DOSGI in Apache Felix. I use CXF 3.2.0 bundles and DOSGI 2.3.0
I can successfully register services but I can not register global custom providers for my resources.
I have a Resource defined in interface:
@Path("")
public interface IToDoResource {
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
List<ToDo> getAllToDos();
@GET
@Path("{id}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
ToDo getToDoById(@PathParam("id") Long id);
...
}
Then implemented in:
@Component(//
name = "My.ToDoRestService", //
immediate = true, //
property = //
{ //
"service.exported.configs=org.apache.cxf.rs", //
"service.exported.interfaces=*", //
"org.apache.cxf.rs.address=/todos", //
} //
)
public class ToDoResource implements IToDoResource {
....
}
I try to register Global custom Providers for my classes. I can make it working with "service.exported.intents" property on the resource and "IntentName" on the provider for one provider. However for this resource I want to register 4 providers:
Alternatively I can also implement IntentsProvider on the resource and it also works.
However following does not work and I get no provider registered for this type error in the logs:
@Component(//
name = "My.ToDoJsonProvider", //
immediate = true, //
service = MessageBodyWriter.class, //
property = {
"service.exported.configs=org.apache.cxf.rs", //
"org.apache.cxf.rs.provider=true", //
} //
)
@Provider
@Produces(MediaType.APPLICATION_JSON)
public class ToDoJsonProvider implements MessageBodyWriter<ToDo> {
GET on localhost:8080/cxf/todos/1 returns empty document and on logs:
JAXRSUtils:1834] No message body writer has been found for class my.todo.repository.api.ToDo, ContentType: application/xml
What do I miss here to register a custom provider globally?
It seems like intents are only taken into account when they are directly named in the Resource properties. "service.exported.intents" property must list all intents that can are required by the resource.
I could not find any documentation but the source code of the RsProvider and IntentManagerImpl classes helped to me.
IntentManagerImpl: https://github.com/apache/cxf-dosgi/blob/master/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java