DOSGI自定义提供程序注册

时间:2017-11-02 14:49:15

标签: java cxf dosgi

我正在尝试在Apache Felix中运行DOSGI。 我使用CXF 3.2.0捆绑包和DOSGI 2.3.0

我可以成功注册服务,但我无法为我的资源注册全球自定义提供程序。

我在界面中定义了资源:

@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);
...
}

然后实施于:

@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 {
....
}

我尝试为我的课程注册全球自定义提供商。 我可以使用资源上的“service.exported.intents”属性和一个提供程序的提供程序上的“IntentName”。 但是对于这个资源,我想注册4个提供者:

  • ToDo XML提供程序
  • ToDo Json提供商
  • ArrayList XML提供程序
  • ArrayList Json提供程序

或者我也可以在资源上实现 IntentsProvider ,它也可以。

但是,以下操作不起作用,我在日志中没有为此类型错误注册提供程序:

@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> {

在localhost上获取:8080 / cxf / todos / 1返回空文档和日志:

  

JAXRSUtils:1834]找不到类my.todo.repository.api.ToDo,ContentType:application / xml

的邮件正文编写器

我在这里想要在全球注册自定义提供商?

1 个答案:

答案 0 :(得分:0)

似乎只有在资源属性中直接命名它们时才会考虑意图。 &#34; service.exported.intents&#34; 属性必须列出资源可能需要的所有意图。

我找不到任何文档,但RsProvider和IntentManagerImpl类的源代码对我有帮助。

RsProvider: https://github.com/apache/cxf-dosgi/blob/master/provider-rs/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/RsProvider.java

IntentManagerImpl: https://github.com/apache/cxf-dosgi/blob/master/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java

相关问题