Search code examples
mulemule-componentanypoint-studio

Why special characters are coming in file?


I have following configuration file , 1)Picking file and sending the contents to active mq. 2)Receiving from active mq and writing it to file But once it is written i am getting some special characters in file like "¬í sr java.util.ArrayListxÒ™Ça I sizexp w ur [B¬óøTà xp `".

Why is it coming?

<mule>
<jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<flow name="activemqFlow">
    <file:inbound-endpoint path="D:\mule\input" responseTimeout="10000" doc:name="File"/>
    <set-property propertyName="fileName" value="#[message.inboundProperties.originalFilename]" doc:name="Property"/>
    <jms:outbound-endpoint queue="logfilequeue" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>
<flow name="JmsInboundFlow">
    <jms:inbound-endpoint queue="logfilequeue" connector-ref="Active_MQ" doc:name="JMS">
        <jms:client-ack-transaction acti on="NONE"/>
    </jms:inbound-endpoint>
    <logger message="#[payload.toString()]" level="INFO" doc:name="Logger"/>
    <file:outbound-endpoint path="D:\mule\output" responseTimeout="10000" doc:name="File" outputPattern="#[message.inboundProperties.fileName]"/>
</flow>


Solution

  • You need to use <object-to-string-transformer doc:name="Object to String"/> after File inbound endpoint like the following :-

    <jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
    <flow name="activemqFlow">
        <file:inbound-endpoint path="D:\mule\input" responseTimeout="10000" doc:name="File"/>
        <object-to-string-transformer doc:name="Object to String"/>
        <set-property propertyName="fileName" value="#[message.inboundProperties.originalFilename]" doc:name="Property"/>
        <jms:outbound-endpoint queue="logfilequeue" connector-ref="Active_MQ" doc:name="JMS"/>
    </flow>
    <flow name="JmsInboundFlow">
        <jms:inbound-endpoint queue="logfilequeue" connector-ref="Active_MQ" doc:name="JMS">
            <jms:client-ack-transaction acti on="NONE"/>
        </jms:inbound-endpoint>
        <logger message="#[payload.toString()]" level="INFO" doc:name="Logger"/>
        <file:outbound-endpoint path="D:\mule\output" responseTimeout="10000" doc:name="File" outputPattern="#[message.inboundProperties.fileName]"/>
    </flow>