2017-07-04 96 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> 
相关问题