Prasad
Prasad

Reputation: 31

How to read plain text file in mule 3.8

In mule 3.8, when I use file connector to process text file , I am getting exception as below, please help.

Here is flow xml

file:connector name="File" autoDelete="true"  streaming="true" validateConnections="true" doc:name="File"/>

flow name="DW-FixedWidth-Processing">

file:inbound-endpoint path="D:/mule/input" connector-ref="File" responseTimeout="10000" doc:name="File"/>

file:file-to-string-transformer doc:name="File to String"/>

dw:transform-message doc:name="Transform Message">

dw:input-payload />

dw:set-payload><![CDATA[%dw 1.0
%output application/csv header=false
---
    ((payload splitBy /\n/)[0..8]) map {
    location:trim $[0..14],
    sku:trim $[15..39],
    dtc:trim $[40..42],
    tt:trim $[43..44],
    txnqty:trim $[45..54],
    um:trim $[55..56],
    rcd:trim $[57..59],
    te:trim $[60..89],
    ul:trim $[90..104],
    date:trim $[105..114],
    time:trim $[115..120]
} ]]>
dw:set-payload>

dw:transform-message>

logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>

file:outbound-endpoint path="D:/mule/output" responseTimeout="10000" doc:name="File"/>

Exception

Root Exception stack trace:

java.lang.IllegalStateException: No schema set at com.mulesoft.weave.module.flatfile.FlatFileSettings.loadSchema(FlatFileSettings.scala:45) at com.mulesoft.weave.module.flatfile.FlatFileReader.ffParser(FlatFileReader.scala:42)

Upvotes: 0

Views: 4677

Answers (4)

Francesco Ganora
Francesco Ganora

Reputation: 11

DW does not currently support mapping from an unstructured string, even if you declare MIME Type = text/plain upstream and you set the input payload metadata to String in the Transform Message processor.

The data formats supported (as per Mule documentation) are Java, XML, JSON, CSV, Flat File, Excel, Fixed Width, and Cobol copybook.

The case here is clearly a Fixed Width format.

Upvotes: 1

vijay dhanakodi
vijay dhanakodi

Reputation: 175

Instead of going to dataweave just use an groovy component to split payload by new line('\n'). Don't use file to string transformer it kills the Java-VM. Also kindly brief what you need to achieve finally in your question. Cheers!

Upvotes: 0

Roger Butenuth
Roger Butenuth

Reputation: 546

When you disable streaming in the file connector, you no longer need the

<object-to-string/>

You can configure DataWeave to use a flat file schema, as already said in the other answer.

When you want to use it the way, you have to tell the correct mime type, in this case it is

application/java

You can do this on any message processor before the DataWeave, in this case the file:inbound-endpoint. Or you can do this in the DataWeave itself (unfortunately this is only visible when you switch Studio to XML).

For me everything worked with the following flow:

    <file:connector name="File" autoDelete="false" streaming="false" validateConnections="true" doc:name="File"/>

    <flow name="dw-testFlow">
        <file:inbound-endpoint path="in" moveToDirectory="processed" connector-ref="File" responseTimeout="10000" mimeType="application/java" doc:name="File">
            <file:filename-regex-filter pattern=".*\.txt" caseSensitive="true"/>
        </file:inbound-endpoint>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
((payload splitBy /\n/)) map {
location:trim $[0..14],
sku:trim $[15..39],
dtc:trim $[40..42],
tt:trim $[43..44],
txnqty:trim $[45..54],
um:trim $[55..56],
rcd:trim $[57..59],
te:trim $[60..89],
ul:trim $[90..104],
date:trim $[105..114],
time:trim $[115..120]
}
]]></dw:set-payload>
        </dw:transform-message>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
    </flow>

The result of the DataWeave is a List of HashMap.

Upvotes: 2

Anil Kumar
Anil Kumar

Reputation: 68

@Prasad, generally the error No Schema Set at throws when the input mime type is no set. In your case, it seems like you are dealing with fixed width data hence you either define a fixed width schema. this article might help.

Upvotes: 0

Related Questions