2
votes

Trying to use the Mule XML streaming feature as have to process very large xml files. Followed the documentation, the document does not have concrete examples.

When I inspected the payload I get the XMLUtils class and not the XMLStreamReader class as stated in the documentation.

The flow is as follows have a file connector which passes payload to a custom transformer, the transformer passes the data to a spring bean which is going to have event based processing.

In the spring bean. At run time the spring bean gets the XMLUtils class and not the XMLStreamReader class.

Mule - Config:

<spring:beans>
   <spring:bean id="OracleCDMMapper" class="oraclecdmstream.OracleCDMMapper"> 
</spring:bean>
<spring:bean id = "OraclePaySlip" class="com.nect.transform.OracleCDMPaySlip" ></spring:bean>

</spring:beans>

<flow name="mulefileconnectorexampleFlow1" >
        <file:inbound-endpoint path="C:/c-OracleCloud/src/main/resources" pollingFrequency="600000" moveToDirectory="C:/c-OracleCloud/src/main/resources/back"  doc:name="File Input" >
           <!--  <file:filename-regex-filter pattern="(^*.xml$)" caseSensitive="false"/>
 -->            <file:filename-wildcard-filter pattern="*.xml"></file:filename-wildcard-filter>
        </file:inbound-endpoint>
        <logger message="Transferring file : #[message.inboundProperties['originalFilename']]" level="INFO" doc:name="Logger"/>
        <logger message ="Logger 1 "  level="INFO" doc:name ="Logger1" />
        <!--  Call the XMLSTREAMER  -->
       **<custom-transformer name="XmlToXSR" class="org.mule.module.xml.transformer.XmlToXMLStreamReader" doc:name="XMLTOORACLE">**

        </custom-transformer>

         <component doc:name="Java">
              <spring-object bean="OracleCDMMapper"/>
        </component>


   -->      
        <logger message ="I am Complete "  level="INFO" doc:name ="LoggerMurali" />


    </flow>


</mule>

Here is the Javacode:

Spring Bean 
public class OracleCDMMapper implements Callable {

     private final Logger logger = LoggerFactory.getLogger(OracleCDMMapper.class);

    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
        // TODO Auto-generated method stub

        MuleMessage muleMessage = eventContext.getMessage();

        logger.info("In the Spring Component");

        logger.info(muleMessage.getPayload().getClass().toString());


        **javax.xml.stream.XMLStreamReader xsr =  (XMLStreamReader) muleMessage.getPayload(javax.xml.stream.XMLStreamReader.class);**

Any help will be much appreciated

1
Are you certain you're getting an instance of XMLUtils? There are a couple of places in the source code that I see it returning an anonymous inner class that does indeed implement XMLStreamReader. This would appear as something like XMLUtils$2 if you use toStriing() on the Class. Maybe also try logging the getClass().getName() or getFullName(). - Ryan Hoegg

1 Answers

1
votes

I've verified and you are right, in the code the supposed returning class should be a DelegateXMLStreamReader class that implements XMLStreamReader, but the returned class is an anonymous inner class of XMLUtils that at runtime cannot be casted to any Stream like class. It seems to be a defect.

If you really need the control of the xml stream, you could use a custom java component:

 <component class="com.foo.CustomJavaComponent" doc:name="Java"/>

.

public class CustomJavaComponent implements Callable{

    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
        MuleMessage muleMessage = eventContext.getMessage();

        FileInputStream fis = (FileInputStream)muleMessage.getPayload();
        //Do something with this stream

        return "Hello world";
    }
} 

And get the input stream to do whatever you want.