简体   繁体   English

DOSGI定制提供者注册

[英]DOSGI Custom Provider Registration

I am trying to run DOSGI in Apache Felix. 我试图在Apache Felix中运行DOSGI。 I use CXF 3.2.0 bundles and DOSGI 2.3.0 我使用CXF 3.2.0捆绑包和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. 我可以使其与一个提供程序的资源上的“ service.exported.intents”属性以及提供程序上的“ IntentName”一起使用。 However for this resource I want to register 4 providers: 但是,对于此资源,我想注册4个提供程序:

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

Alternatively I can also implement IntentsProvider on the resource and it also works. 另外,我也可以在资源上实现IntentsProvider ,它也可以工作。

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: 在localhost:8080 / cxf / todos / 1上的GET返回空文档并在日志上:

JAXRSUtils:1834] No message body writer has been found for class my.todo.repository.api.ToDo, ContentType: application/xml JAXRSUtils:1834]找不到类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. “ service.exported.intents”属性必须列出资源可能需要的所有意图。

I could not find any documentation but the source code of the RsProvider and IntentManagerImpl classes helped to me. 我找不到任何文档,但是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 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 IntentManagerImpl: https : //github.com/apache/cxf-dosgi/blob/master/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM