我是Mulesoft开发的新手。最近我被要求开发一个MuleESB应用程序来从逗号分隔的CSV文件中读取一些值,然后使用提供的值调用REST API。我不确定我是在正确地做这件事,还是在正确的道路上实现这一目标,因为我一直在接受这个 WARN 2016-08-03 02:39:49,209 [creditsFlow.stage1.02] org.mule。 routing.ExpressionSplitter:Splitter没有返回任何结果。如果不是这样,请检查您的拆分表达式,接下来没有任何事情发生。
通常我们称之为REST API:https://xx.xx.com/server/CreditPost/views/CreditPost?ID=12345678&CompletionDt=2017-08-03&CourseNbr=90000001
以下是我的MuleESB代码的片段:
<flow name="creditsFlow">
<file:inbound-endpoint path="C:\Users\kteo1\Downloads\Inbound" responseTimeout="10000" metadata:id="a67520d0-f60d-4b5c-9fc8-3578d6c6434d" doc:name="input file" mimeType="application/csv">
<file:filename-regex-filter pattern="credits_(?:(?!\.csv)(?:.|\n))*\.csv" caseSensitive="true"/>
</file:inbound-endpoint>
<dw:transform-message metadata:id="0e395c12-6af5-4894-b9c2-f7642816f8d3" doc:name="CSV to XML">
<dw:input-payload doc:sample="list_credits.csv"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
---
{
credits: {
(payload map ((payload01 , indexOfPayload01) -> {
credit: {
ID: payload01.ID,
CourseNbr: payload01.CourseNbr,
CompletionDt: payload01.CompletionDt as :string
}
}))
}
}]]></dw:set-payload>
</dw:transform-message>
<json:xml-to-json-transformer doc:name="XML to JSON"/>
<logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
<json:json-to-object-transformer doc:name="JSON to Object"/>
<set-variable variableName="totalCredits" value="#[json:credits]" doc:name="totalCredits"/>
<set-variable variableName="creditsArrayList" value="#[new java.util.ArrayList()]" doc:name="creditsArrayList"/>
<foreach collection="#[json:credit]" doc:name="For Each" >
<logger message="#[json:ID]" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/server/CreditPost/views/CreditPost?ID={ID}&CompletionDt={CompletionDt}&CourseNbr={CourseNbr}" method="GET" doc:name="HTTP">
<http:request-builder>
<http:uri-param paramName="ID" value="#[json:ID]"/>
<http:uri-param paramName="CompletionDt" value="#[json:CompletionDt]"/>
<http:uri-param paramName="CourseNbr" value="#[json:CourseNbr]"/>
</http:request-builder>
</http:request>
</foreach>
</flow>
请告知。
答案 0 :(得分:0)
首先,您不需要将数据转换为xml,然后转换为json,然后转换为java。
使用类似
的内容%dw 1.0
%output application/java
---
(payload map ((payload01 , indexOfPayload01) -> {
ID: payload01.ID,
CourseNbr: payload01.CourseNbr,
CompletionDt: payload01.CompletionDt as :string
}))
它将生成arraylist传递给请求构建器。
另一个问题是关于uri-params。您正在使用uri-pamars而不是在设置查询参数时使用查询参数和访问#[payload.ID], #[payload.CourseNbr], #[payload.CompletionDt]
等字段。
<dw:transform-message doc:name="Transform Message" metadata:id="55f04db1-ed48-4e1f-b966-562768a3c173">
<dw:input-payload doc:sample="list_csv.csv">
<dw:reader-property name="header" value="false"/>
</dw:input-payload>
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
(payload map ((payload01 , indexOfPayload01) -> {
ID: payload01.ID,
CourseNbr: payload01.CourseNbr,
CompletionDt: payload01.CompletionDt as :string
}))
]]></dw:set-payload>
</dw:transform-message>
<foreach doc:name="For Each">
<http:request config-ref="HTTP_Request_Configuration" path="/server/CreditPost/views/CreditPost" method="GET" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName="ID" value="#[payload.ID]"/>
<http:query-param paramName="CourseNbr" value="#[payload.CourseNbr]"/>
<http:query-param paramName="CompletionDt" value="#[payload.CompletionDt]"/>
</http:request-builder>
</http:request>
</foreach>
希望这有帮助。