没有为类org.apache.cxf.message.MessageContentsList找到消息正文编写器,ContentType:application / xml

时间:2016-04-27 09:33:52

标签: apache-camel cxf activemq

<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我得到没有消息正文编写器已找到类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或我的应用程序中的问题吗?

1 个答案:

答案 0 :(得分:0)

它看起来像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>