2016-04-27 24 views
1
<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> 

我已經實現了用駱駝CXF組件支持路由到ActiveMQ的隊列中的響應REST服務。現在,當運行服務url我得到沒有消息正文編寫器已發現類org.apache.cxf.message.MessageContentsList,ContentType:application/xml 消息。沒有消息體的作家已經發現了類org.apache.cxf.message.MessageContentsList,則contentType:應用程序/ 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或我的應用程序中的問題嗎?

回答

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> 
相關問題