如何在 mule 中使用 for each

how to use for each in mule

***I have a xml ---***
<DBOperation>
<ListOfOperation>
<operation>
<operationName>Insert</operationName>
<input>
<empid>3</empid>
<name>saurabh</name>
</input>
<operationName>Delete</operationName>
<input>
<empid>3</empid>
</input>
<operationName>insert</operationName>
<empid>3</empid>
<name>saurabh</name>
<operationName>update</operationName>
<input>
<empid>3</empid>
<name>raj</>
</input>
</operation>
</ListOfOperation>
</DBOperation>

我想将此 xml 作为 soap 消息发送,但整个操作一次完成,这样使用一个请求我就可以使用选择路由执行所有操作....最有效的方法是什么在 mulesoft 中执行此操作...如果每个都使用我的 collection 选项卡配置?

您是否需要创建一个网络服务,return将此 xml 作为响应?

如果是,这可能对您有帮助:

JAVA(没有骡子)

  • 创建与您的 xml 完全匹配的 java bean 和属性:Response.java
  • 创建 java class 一次操作,即 return 此 Response。并使用一些库,创建您的网络服务:
 

@WebService

    public class WebService {       
        public Response operation_name(Request request){

        }
    }


如果您需要一些参数,请求class。

https://github.com/jrichardsz/java-web-services-template-soa-rest

  • 最后,当您需要 return xml 作为响应时,使用解组过程将您的 xml 文件转换为 Response.java.

http://www.javatpoint.com/jaxb-unmarshalling-example

骡子

此致

<flow name="dbopps">
<http:listener config-ref="HTTP_Listener_Configuration1" path="/" doc:name="HTTP"/>
***<foreach collection="#[xpath://.[xpath:local-name()='DBOperation']/*[xpath:local-name()='ListOfOperation']/*[xpath:local-name()='operation']]" doc:name="For Each" >***
<mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<set-variable variableName="name" value="#[xpath('//operationName').text]" doc:name="Variable"/>
<logger message="#[flowVars.name]" level="INFO" doc:name="Logger"/>
<choice tracking:enable-default-events="true" doc:name="Choice">
<when expression="#[flowVars.name == 'Insert']">
<db:insert config-ref="MySQL_Configuration" doc:name="Insert">
<db:parameterized-query><![CDATA[Insert into employees(empid,name) values ('43',#[xpath('//name').text])]]></db:parameterized-query>
</db:insert>
</when>
<when expression="#[flowVars.name == 'Delete']">
<db:delete config-ref="MySQL_Configuration" doc:name="Delete">
<db:parameterized-query><![CDATA[Delete from employees where empid='10']]></db:parameterized-query>
</db:delete>
</when>
</foreach>
<set-variable variableName="id" value="#[xpath://.[xpath:local-name()='DBOperation']/*[xpath:local-name()='ListOfOperation']/*[xpath:local-name()='operation']/*[xpath:local-name()='operationName']']" doc:name="Variable"/>
<set-payload value="&lt;a&gt; hello &lt;/a&gt;" doc:name="Set Payload"/>
</flow>

这对我来说很好,你可以检查 collection 选项卡配置。