【问题标题】:No message body writer has been found for class org.apache.cxf.message.MessageContentsList, ContentType: application/xml没有为类 org.apache.cxf.message.MessageContentsList 找到消息正文编写器,ContentType: application/xml
【发布时间】:2016-08-21 12:22:06
【问题描述】:
<cxf:rsServer id="rsServer" address="/services"
        serviceClass="com.mayank.restservice.resource.RestfulResource">

        <cxf:providers>
            <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
            <bean class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" />
        </cxf:providers>

    </cxf:rsServer>

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">

        <route>
            <from uri="cxfrs:bean:rsServer" />
            <to uri="log:body?level=INFO" />
            <to uri="activemq:queue:testQueue" pattern="InOnly" />
        </route>

    </camelContext>

    <!-- ActiveMQ-beans definition -->
    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="brokerURL" value="tcp://localhost:61616" />
    </bean>

我已经使用camel-cxf 组件支持实现了rest 服务来将响应路由到activemq 队列。现在,当运行服务 url 时,我得到 No message body writer has found for class org.apache.cxf.message.MessageContentsList, ContentType: application/xml 消息。

Below is my RestResource class.

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.mayank.restservice.model.ChequeDetails;
import com.mayank.restservice.service.RestfulService;

public class RestfulResource {

    private RestfulService restfulservice;
    public void setRestfulservice(RestfulService restfulservice) {
        this.restfulservice = restfulservice;
    }

    @Path("post")
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_XML)
    public ChequeDetails persistDB(ChequeDetails chequedetails){

        return restfulservice.persistDB(chequedetails);

    }
}

当我尝试使用 @Produce(APPLICATION_JSON) 进行测试时,我得到了成功响应。 不确定这是 camel-cxf 的问题还是我的应用程序的问题?

【问题讨论】:

  • 你找到解决办法了吗?

标签: apache-camel cxf activemq


【解决方案1】:

看起来像是 JAXB 配置问题。您是否已将其配置为支持 JSON ? http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-JSONsupport

配置示例:

<beans xmlns:util="http://www.springframework.org/schema/util">
<bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="namespaceMap" ref="jsonNamespaceMap"/>
</bean>
<util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
<entry key="http://www.example.org/books" value="b"/>
</util:map>
/<beans>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多