如何在mule 3.8中读取纯文本文件

如何在mule 3.8中读取纯文本文件,mule,mule-studio,mule-component,mule-module-jpa,Mule,Mule Studio,Mule Component,Mule Module Jpa,在mule 3.8中,当我使用file connector处理文本文件时,出现如下异常,请帮助 下面是流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/inpu

在mule 3.8中,当我使用file connector处理文本文件时,出现如下异常,请帮助

下面是流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"/>
file:connector name=“file”autoDelete=“true”streaming=“true”validateConnections=“true”doc:name=“file”/
flow name=“DW FixedWidth处理”>
file:inbound endpoint path=“D:/mule/input”connector ref=“file”responseTimeout=“10000”doc:name=“file”/>
文件:文件到字符串转换器doc:name=“文件到字符串”/>
dw:转换消息文档:name=“转换消息”>
dw:输入有效负载/>
dw:设置有效负载>
dw:设置有效负载>
dw:转换消息>
logger message=“#[message.payloadAs(java.lang.String)]”level=“INFO”doc:name=“logger”/
file:outbound endpoint path=“D:/mule/output”responseTimeout=“10000”doc:name=“file”/>
例外情况

根异常堆栈跟踪:

java.lang.IllegalStateException:未在上设置架构 com.mulesoft.weave.module.flatfile.FlatFileSettings.loadSchema(FlatFileSettings.scala:45) 在 com.mulesoft.weave.module.flatfile.FlatFileReader.ffParser(FlatFileReader.scala:42)


当您在文件连接器中禁用流时,您不再需要

<object-to-string/>
您可以在DataWeave之前的任何消息处理器上执行此操作,在本例中为file:inbound endpoint。或者您可以在DataWeave本身中执行此操作(不幸的是,只有当您将Studio切换到XML时,此操作才可见)

对我来说,一切都是按照以下流程进行的:

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


DataWeave的结果是HashMap列表。

当您在文件连接器中禁用流时,您不再需要

<object-to-string/>
您可以在DataWeave之前的任何消息处理器上执行此操作,在本例中为file:inbound endpoint。或者您可以在DataWeave本身中执行此操作(不幸的是,只有当您将Studio切换到XML时,此操作才可见)

对我来说,一切都是按照以下流程进行的:

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


DataWeave的结果是HashMap的列表。

@Prasad,通常在输入mime类型未设置时抛出错误
No Schema Set
。在您的例子中,似乎您正在处理固定宽度的数据,因此您可以定义一个固定宽度的模式。这可能会有所帮助。

@Prasad,通常在输入mime类型未设置时抛出错误
No Schema Set
。在您的例子中,似乎您正在处理固定宽度的数据,因此您可以定义一个固定宽度的模式。这可能会有所帮助。

只需使用groovy组件按新行('\n')拆分负载,而无需转到dataweave。 不要使用文件来转换字符串,因为它会杀死Java虚拟机。 另外,请在问题中简要说明您最终需要实现的目标。
干杯

不使用dataweave,只需使用groovy组件按新行('\n')拆分负载即可。 不要使用文件来转换字符串,因为它会杀死Java虚拟机。 另外,请在问题中简要说明您最终需要实现的目标。
干杯

DW当前不支持从非结构化字符串映射,即使您在转换消息处理器中声明MIME Type=text/plain上游,并将输入有效负载元数据设置为字符串

支持的数据格式(根据)有Java、XML、JSON、CSV、平面文件、Excel、固定宽度和Cobol copybook


这里的情况显然是固定宽度格式。

DW当前不支持从非结构化字符串映射,即使您在转换消息处理器中声明MIME Type=text/plain上游,并将输入有效负载元数据设置为字符串

支持的数据格式(根据)有Java、XML、JSON、CSV、平面文件、Excel、固定宽度和Cobol copybook


这里的案例显然是固定宽度格式。

我已经编辑了详细信息部分以包含流xml,请查看我已经编辑了详细信息部分以包含流xml,请查看谢谢回答,我添加了mime类型。谢谢回答,我添加了mime类型,这对我很有帮助,因为我在DW处理器中设置了一个flowVar,输入类型是String。如果这样做,则会出现“无模式集”异常。使用带有MEL的flowVar转换器可以工作。这对我很有帮助,因为我在DW处理器中设置了一个flowVar,输入类型是字符串。如果这样做,则会出现“无模式集”异常。使用带有MEL的flowVar变压器工作。