Search code examples
javajaxbmuleesb

Using XML Transformer in Mule


I currently receive a string message from a queue, The string message contains XML. How do I pick each element and convert to a POJO. This is the content of my queue

<MsgContent>
   <MsgHeader>
       <code>1010</code>
   </MsgHeader>
   <MsgBody>
        <value>fundstransfer</value>
   </MsgBody>
</MsgContent>

I want to be able to get the values of the two keys(code and value)

This is my mule configuration xml

    <?xml version="1.0" encoding="UTF-8"?>

    <mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:data-        mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"          xmlns:xm="http://www.mulesoft.org/schema/mule/xml"  xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:file="http://www.mulesoft.org/schema/mule/file"   xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-current.xsd
    http://www.mulesoft.org/schema/mule/xml  http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
    http://www.mulesoft.org/schema/mule/core  http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
    http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd">
   <jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>

<mulexml:jaxb-context name="myJaxb" doc:name="myJaxb" packageNames="com.test.jaxb" />
<flow name="JMSMessageFlow1" doc:name="JMSMessageFlow1">
    <jms:inbound-endpoint queue="StudioIns" connector-ref="Active_MQ" doc:name="JMS" />
    <custom-transformer class="org.mule.module.xml.transformer.XmlToXMLStreamReader" />
    <mulexml:jaxb-xml-to-object-transformer  jaxbContext-ref="myJaxb" returnClass="com.test.jaxb.MsgContent"/>
    <component class="com.test.HelloMessage" doc:name="Java"/>
    <file:outbound-endpoint path="D:\Documents\MuleStudio\workspace\jmsmessage\src\main\java\com\test" outputPattern="output.csv" responseTimeout="10000" doc:name="File"/>
</flow>

But still can't retrieve the objects


Solution

  • I have resolved it now. The major issue is that one must have a valid and correct JAXB Binding Class. Thanks all