2017-07-04 191 views
0

我試圖消耗和生成xml響應使用休息DSL在Apache駱駝中,但它以一個異常結束如何將我的輸出POJO對象編組爲xml。下面是SY Apache的駱駝航線如何在Apache Camel中使用REST DSL生成xml響應

<camelContext id="camelContext-02bcd908-03ed-4c2c-878a-b87e3a3668ca" 
     xmlns="http://camel.apache.org/schema/blueprint"> 
     <restConfiguration bindingMode="xml" component="servlet" 
      contextPath="/camel-example-servlet-rest-blueprint/rest" port="8181"> 
      <dataFormatProperty key="mustBeJAXBElement" value="true" /> 
     </restConfiguration> 
     <!-- defines the rest services using the context-path /user --> 
     <rest consumes="application/xml" path="/user" produces="application/xml"> 
      <description>User rest service</description> 
      <!-- this is a rest GET to view an user by the given id --> 
      <get outType="org.apache.camel.example.rest.User" uri="/{id}"> 
       <description>Find user by id</description> 
       <to uri="bean:userService?method=getUser(${header.id})" /> 
      </get> 
      <!-- this is a rest GET to find all users --> 
      <get outType="org.apache.camel.example.rest.User[]" uri="/findAll"> 
       <description>Find all users</description> 
       <to uri="bean:userService?method=listUsers" /> 
      </get> 
     </rest> 
    </camelContext> 

這裏是例外即時得到

產生java.io.IOException:org.apache.camel.InvalidPayloadException:身無可用的類型:javax.xml.bind.JAXBElement但具有以下值:[[email protected][email protected]]類型:java.util.TreeMap.Values on:Message [ID-NISB- TEC-C3880-56991-1499145269945-37-3。 Exchange [ID-NISB-TEC-C3880-56991-1499145269945-37-2] 位於org.apache.camel.processor的org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:153) 。 MarshalProcessor.process(MarshalProcessor.java:69) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109) at org.apache.camel.processor.MarshalProcessor.process(MarshalProcessor.java:50)

回答

0

您可以嘗試將您的bindingMode更改爲「off」。

而且當你創建get方法,您可以使用「消耗」和「生產」參數等於「應用程序/ XML」,這樣的事情:

<get outType="org.apache.camel.example.rest.User[]" uri="/findAll"consumes="application/xml" produces="application/xml"> 
    <description>Find all users</description> 
    <to uri="bean:userService?method=listUsers" /> 
</get> 
相關問題