0
votes

Im trying to consume and produce xml response using rest DSL in Apache camel but it ends with an exception how can i marshal my output POJO object to xml. Below is sy Apache Camel route

<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>

Here is exception im getting

java.io.IOException: org.apache.camel.InvalidPayloadException: No body available of type: javax.xml.bind.JAXBElement but has value: [org.apache.camel.example.rest.User@7f98bc82, org.apache.camel.example.rest.User@4502b96] of type: java.util.TreeMap.Values on: Message[ID-NISB-TEC-C3880-56991-1499145269945-37-3]. Exchange[ID-NISB-TEC-C3880-56991-1499145269945-37-2] at org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:153) at org.apache.camel.processor.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)

1

1 Answers

0
votes

You can try change your bindingMode to "off".

And when you create the get method, you can use the "consumes" and "produces" parameter equals "application/xml", something like this:

 <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>