【问题标题】:Apache CXF DSOGI with JSON on KarafApache CXF DSOGI 与 Karaf 上的 JSON
【发布时间】:2017-08-17 23:20:47
【问题描述】:

我正在尝试使用 Apache CXF DOSGI 在 Karaf 4.0.8 中创建一个 RESTful Web 服务。正在调用该服务,但我收到此错误:No message body writer has found for class....

欢迎提出任何建议。谢谢!!!

组件:

    @Component(immediate = true, property = {
            "service.exported.interfaces=*", 
            "service.exported.configs=org.apache.cxf.rs",
"org.apache.cxf.rs.provider=com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider",
            "org.apache.cxf.rs.address=/integr" })
    public class AccountRestService implements AccountWebUserIdResource {
    ...
    }


Interface:
------------
    @GET
    @Produces({
        "application/json"
    })
    AccountWebUserIdResource.GetAccountByWebUserIdResponse getAccountByWebUserId(
@PathParam("webUserId")
        String webUserId,
        @QueryParam("sc")
        String sc,
        @QueryParam("fields")
        String fields)
        throws Exception
    ;

实体:

@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
    "href",
    "crm_member_id",
    "email_address",
    "account_status"
})
public class Account {

    /**
     * 
     * (Required)
     * 
     */
    @JsonProperty("href")
    private String href;
    /**
     * 
     * (Required)
     * 
     */
    @JsonProperty("crm_member_id")
    private String crmMemberId;
    /**
     * 
     * (Required)
     * 
     */
    @JsonProperty("email_address")
    private String emailAddress;

....

【问题讨论】:

    标签: json osgi cxf karaf dosgi


    【解决方案1】:

    至少对于 CXF-DOSGi 2,您的代码可能无法运行。无论如何,从类名加载提供程序在 OSGi 中是有问题的,因为 CXF DOSGi 代码没有 com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider 类的可见性。

    在 CXF-DOSGi 中,这可以使用意图来完成。这对 OSGi 更友好,因为 JacksonJsonProvider 然后直接用作类,因此 OSGi 类加载工作得很好。还需要将总线属性设置为 all 以覆盖 jacksonprovider,因为规范通常不允许这样做。

    cxf.bus.prop.skip.default.json.provider.registration=true

    intent 类如下所示:

    @Component(property = "org.apache.cxf.dosgi.IntentName=jackson")
    public class JacksonIntent implements Callable<List<Object>> {
    
        public List<Object> call() throws Exception {
            return Arrays.asList((Object)new JacksonJaxbJsonProvider());
        }
    
    }
    

    Intent 提供了一种通用方式来定义 CXF 的功能和其他覆盖,而不会直接影响您的服务类。

    然后必须使用服务属性service.exported.intents=jackson 在服务中引用意图。

    我刚刚添加了jackson example to CXF-DOSGi

    另一个小障碍是当前的cxf-jackson 功能缺少捆绑包。见CXF-7298

    【讨论】:

      猜你喜欢
      • 2017-08-20
      • 2017-11-14
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      • 2020-05-16
      • 2011-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多