我有一个骡子流: -
<jdbc-ee:connector name="Database_Global" dataSource-ref="DB_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database">
<jdbc-ee:query key="UpdateQuerySOAPRequest" value="UPDATE getData SET ID=#[xpath('//v1:Id').text], NAME=#[xpath('//v1:Name').text], AGE=#[xpath('//v1:Age').text], DESIGNATION = #[xpath('//v1:Designation').text] where ID=#[xpath('//v1:Id').text]"/>
</jdbc-ee:connector>
<flow name="NodeNameFlow" doc:name="NodeNameFlow" initialState="started">
<file:inbound-endpoint responseTimeout="10000" connector-ref="File_Input" doc:name="File" path="E:\backup\test">
<file:filename-regex-filter pattern="XMLRequest.xml" caseSensitive="false"/>
</file:inbound-endpoint>
<splitter evaluator="xpath" expression="//v1:updateDataRequest" doc:name="Splitter_For_MultipleSameNodes"/>
<mulexml:dom-to-xml-transformer name="DomToXmlSOAPUpdate2" doc:name="Dom To XmlSOAPUpdate"/>
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="UpdateQuerySOAPRequest" queryTimeout="-1" connector-ref="Database_Global" doc:name="Database (JDBC)"/>
<choice doc:name="Choice">
<when expression="#[flowVars['MULE_JDBC_UPDATE_COUNT']==0]"> <!-- If not updated -->
<logger message="Updated #[flowVars['MULE_JDBC_UPDATE_COUNT']] rows... Failed!!! No rows were Updated" level="INFO" doc:name="Logger"/>
</when>
<otherwise> <!-- if updated -->
<set-payload value="Updated Successfully !!!" doc:name="Set Payload"/>
</otherwise>
</choice>
<mulexml:object-to-xml-transformer doc:name="Object to XML"></mulexml:object-to-xml-transformer>
<async doc:name="Async_Database_Response_in_File">
<logger message="Request *************************** #[payload:java.lang.String] *************************" level="INFO" doc:name="Logger"/>
<file:outbound-endpoint path="E:\backup\test" outputPattern="SimpleResponse.txt" responseTimeout="10000" doc:name="File" connector-ref="File_Global"/>
</async>
</flow>
现在您可以看到它正在将xml文件作为输入,将其拆分并根据ID更新数据库,最后它将有效负载记录在出站文件中.. ..如果它能够更新数据成功完成后,它能够以正确的方式在记录器<logger message="Request *************************** #[payload:java.lang.String] *************************" level="INFO" doc:name="Logger"/>
中显示有效负载,如: -
org.mule.api.processor.LoggerMessageProcessor: Request ***************************<string> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://services.test.com/schema/MainData/V1">
<soapenv:Header/>
<soapenv:Body>
<v1:updateDataRequest>
<v1:Id>1</v1:Id>
<v1:Name>BnnnnnnBB !!!!!</v1:Name>
<v1:Age>66</v1:Age>
<v1:Designation>EEEEEE</v1:Designation>
</v1:updateDataRequest>
</soapenv:Body>
</soapenv:Envelope> </string> *************************
但是如果它无法根据ID更新数据库,它将显示如下所示的有效负载: -
org.mule.api.processor.LoggerMessageProcessor: Request *************************** <string><?xml version="1.0" encoding="UTF-8"?>
<v1:updateDataRequest xmlns:v1="http://services.test.com/schema/MainData/V1">
<v1:Id>1</v1:Id>
<v1:Name>BnnnnnnBB !!!!!</v1:Name>
<v1:Age>66</v1:Age>
<v1:Designation>EEEEEE</v1:Designation>
</v1:updateDataRequest></string> *************************
... 所以我的问题是为什么它以这种格式显示相同的有效载荷如果它无法更新....任何建议..做..我需要以任何格式转换有效载荷......任何建议????
答案 0 :(得分:3)
仅供参考#[payload:java.lang.String]
的MEL语法为#[message.payloadAs(java.lang.String)]
流程中有一些不合逻辑的东西:在成功的情况下set-payload
将有效负载设置为非XML字符串(即"Updated Successfully !!!"
)。
然而,在choice
之后mulexml:object-to-xml-transformer
启动并尝试将此随机字符串转换为XML,这实际上无法正常工作。你需要解决这个问题。
答案 1 :(得分:0)
因此,我最终得到了#[message.payloadAs(java.lang.String)]
而不是大卫建议的#[payload:java.lang.String]
,并且还将有效负载存储在DB组件之前的流变量中,并将其设置为有效负载,因为有效负载正在中断。 ......它有效!!!!
答案 2 :(得分:0)
FYI the MEL syntax for #[payload:java.lang.String] is #[message.payloadAs(java.lang.String)]
There's something not logical in the flow: in case of success set-payload sets the payload to a non-XML string (i.e "Updated Successfully !!!").
But then, after choice the mulexml:object-to-xml-transformer kicks-in and tries to transfrom this random String into XML, which can't really work. You need to fix this.