请在下面找到带有 dataweave 代码的流程
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8082" doc:name="HTTP Listener Configuration"/>
<flow name="testFlow1" >
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<set-payload value="#['test']" doc:name="Set Payload"/>
<component class="org.test.MyClass" metadata:id="f70e8945-4d11-40ba-beac-dc2f352cc2ff" doc:name="Java"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/csv separator=" "
---
payload map {
SampleValue1:$.OrderData1,
SampleValue2:$.OrderData2,
SampleValue3:$.OrderData3,
SampleValue4:$.OrderData4,
SampleValue5:$.OrderData5
}]]></dw:set-payload>
</dw:transform-message>
<async doc:name="Async">
<file:outbound-endpoint path="C:\Naveen\OutputDump" responseTimeout="10000" doc:name="File" outputPattern="test.txt"/>
</async>
<set-payload value="#['<?xml version="1.0" encoding="utf-8"?>']#[payload]" metadata:id="1e133033-b51d-43a3-a6b5-6496862dd510" doc:name="Set Payload"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
以下是上述流程的输出
SampleValue1 SampleValue2 SampleValue3 SampleValue4 SampleValue5
orderData1 orderData2 orderData3 orderData4 orderData5
orderData1 orderData2 orderData3 orderData4 orderData5
orderData1 orderData2 orderData3 orderData4 orderData5
orderData1 orderData2 orderData3 orderData4 orderData5
orderData1 orderData2 orderData3 orderData4 orderData5
如果您不需要在输出中添加此文件,则上述代码会生成带有标题的 CSV 文件,"header=false"
如下所示。
%output application/csv header=false,separator=" "
java类如下图所示
package org.test;
import java.util.ArrayList;
import java.util.List;
import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
public class MyClass implements Callable{
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
MyPojo pojos = new MyPojo();
pojos.setOrderData1("orderData1");
pojos.setOrderData2("orderData2");
pojos.setOrderData3("orderData3");
pojos.setOrderData4("orderData4");
pojos.setOrderData5("orderData5");
List MyArray = new ArrayList();
MyArray.add(pojos);
MyArray.add(pojos);
MyArray.add(pojos);
MyArray.add(pojos);
MyArray.add(pojos);
return MyArray;
}
}
pojo如下图所示
package org.test;
public class MyPojo {
String OrderData1;
String OrderData2;
String OrderData3;
String OrderData4;
String OrderData5;
public String getOrderData1() {
return OrderData1;
}
public void setOrderData1(String orderData1) {
OrderData1 = orderData1;
}
public String getOrderData2() {
return OrderData2;
}
public void setOrderData2(String orderData2) {
OrderData2 = orderData2;
}
public String getOrderData3() {
return OrderData3;
}
public void setOrderData3(String orderData3) {
OrderData3 = orderData3;
}
public String getOrderData4() {
return OrderData4;
}
public void setOrderData4(String orderData4) {
OrderData4 = orderData4;
}
public String getOrderData5() {
return OrderData5;
}
public void setOrderData5(String orderData5) {
OrderData5 = orderData5;
}
}
如果您有任何问题,请告诉我。