I am using scatter-gather to call many endpoints with the same host and different paths. How can I add the HTTP request connector inside For Each scope, that can loop into the different paths and add the payload to the same file?
My code is as below, I would like to loop over the HTTP request;
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:ftp="http://www.mulesoft.org/schema/mule/ee/ftp" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/ftp http://www.mulesoft.org/schema/mule/ee/ftp/current/mule-ftp-ee.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<http:request-config name="HTTP_Request_Configuration-testt" protocol="HTTPS" host="servicenow.com" port="443" doc:name="HTTP Request Configuration"/>
<http:listener-config name="HTTP_Listener_Configuration1" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="servicenow-call">
<http:listener config-ref="HTTP_Listener_Configuration1" path="/test" doc:name="HTTP"/>
<scatter-gather doc:name="Scatter-Gather">
<http:request config-ref="HTTP_Request_Configuration-testt" path="/repo/cat1" method="GET" doc:name="HTTP Request 1"/>
<http:request config-ref="HTTP_Request_Configuration-testt" path="/repo/cat2" method="GET" doc:name="HTTP Request 2"/>
<http:request config-ref="HTTP_Request_Configuration-testt" path="/repo/cat3"" method="GET" doc:name="HTTP Request 4"/>
</scatter-gather>
<dw:transform-message doc:name="Set JSON">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
payload]]></dw:set-payload>
</dw:transform-message>
<file:outbound-endpoint path="D:\Local\NewFile.json" outputPattern="first-#[function:datestamp:ddMMyyyy-HHmmss].json" responseTimeout="10000" doc:name="Write FIle"/>
<exception-strategy ref="ImplementationChoice_Exception_Strategy" doc:name="Reference Exception Strategy"/>
</flow>
</mule>
Check the below sample code how we can use foreach in your scenario. THis is in Mule4. I hope you can do it in Mule3 as well.
I am not sure why you want to use foreach. I would suggest use Scatter_Gather instead of foreach. Because foreach will work sequentially and Scatter_Gather works concurrently. Performance wise concurrent process is good.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<flow name="Testing_foreach_stackoverflowFlow" doc:id="95fe6a04-4aca-4106-a0b3-b53afb7be95a" >
<scheduler doc:name="Scheduler" doc:id="e6a81b1c-43f9-486a-a451-b31bcadbe23f" >
<scheduling-strategy >
<fixed-frequency frequency="5" timeUnit="MINUTES"/>
</scheduling-strategy>
</scheduler>
<set-variable value="#[%dw 2.0
output application/json
---
[]]" doc:name="Set Variable" doc:id="7b1bbba6-d63d-4f89-905b-8b9c7d6a7555" variableName="result"/>
<set-payload value='#[["test1","test2"]]' doc:name="Set Payload" doc:id="1b7ff757-1a42-4291-b759-50632db842d3" />
<foreach doc:name="For Each" doc:id="2010c075-b487-4977-8a34-0f58adb23a7d" >
<http:request method="GET" doc:name="Request" doc:id="a0524fe5-2344-46c2-bb03-90660fb8fc04" url='#["http://localhost:8091/" ++ payload]'/>
<ee:transform doc:name="Transform Message" doc:id="0aca9608-f7a1-4e1a-a246-11830b6f245e" >
<ee:message >
</ee:message>
<ee:variables >
<ee:set-variable variableName="result" ><![CDATA[%dw 2.0
output application/json
---
vars.result + payload
]]></ee:set-variable>
</ee:variables>
</ee:transform>
<logger level="INFO" doc:name="payload" doc:id="22bc3348-90f9-4290-bb53-ee4c19af1f18" message="#[payload]"/>
</foreach>
<logger level="INFO" doc:name="payload" doc:id="00e70062-6898-42d7-bc50-974f23a4cd93" message="#[payload]"/>
</flow>
<flow name="Testing_foreach_stackoverflowFlow1" doc:id="fc055a5c-09a0-4dce-99be-70e863ffb0ff" >
<http:listener doc:name="Listener" doc:id="298d5fff-c712-4307-895a-7d4faac42eb1" config-ref="api-httpListenerConfig" path="/test1"/>
<set-payload value='"grapes"' doc:name="Set Payload" doc:id="bfce761e-c63a-4a06-ab9b-f17360d9a7d2" />
</flow>
<flow name="Testing_foreach_stackoverflowFlow2" doc:id="12d67768-525e-46b0-91b4-ce9377b0b7d1" >
<http:listener doc:name="Listener" doc:id="24fc80d9-0f93-4217-a1a2-3802b57ce3cb" config-ref="api-httpListenerConfig" path="/test2"/>
<set-payload value='"banana"' doc:name="Set Payload" doc:id="01ad0e82-5f50-49a3-9804-10190953b1c0" />
</flow>
</mule>
Set a variable with an empty list before the foreach, and for each iteration concatenate the results. I guess you can set a list of the paths and use it to iterate the foreach.
Related
Unfortunately I haven't been able to solve it yet. I'd really appreciate it if someone could look into it. thanks everyone
I run into an issue with Mule 3 is that the payload is not recognized within the query params inside the HTTP request connector section.
This is because the query params must be quoted to be recognized as value. I've tried escaping the quotes and also saving the filter as a variable, but unfortunately that doesn't work either.
The filter must also be executed exactly otherwise get the full payload. So my final URL should be exactly like this otherwise it will not filter and I will get the full payload:
https://service.request.com/request/change/serviceRequest?$filter=id eq 5598f15c-e4fb-482f-ba41-0ced971ec737
Over the id I have the foreach which loops over each id and makes the request.
Below I have added the xml code.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore" xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp"
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns="http://www.mulesoft.org/schema/mule/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/current/mule-objectstore.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<http:request-config name="HTTP_Request_Configuration_1" host="service.request.com" port="443" doc:name="HTTP Request Configuration" />
<objectstore:config name="ObjectStore__Connector_1" partition="timeStamp" persistent="true" doc:name="ObjectStore: Connector"/>
<http:listener-config name="HTTP_Listener_Configuration_1" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="main_flow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<flow-ref name="time_now" doc:name="time_now"/>
<flow-ref name="retrieve_and_save_time" doc:name="retrieve_and_save_time"/>
<flow-ref name="dynamic_call" doc:name="dynamic_call"/>
<flow-ref name="Store_after_succes" doc:name="Store_after_succes"/>
</flow>
<sub-flow name="time_now">
<set-variable variableName="serverTime" value="#[server.dateTime.format("yyyy-MM-dd'T'HH:mm:ss'Z'")] " doc:name="Now Time"/>
</sub-flow>
<sub-flow name="retrieve_and_save_time">
<objectstore:retrieve config-ref="ObjectStore__Connector" key="time" defaultValue-ref="#[(server.dateTime.plusHours(-2).format("yyyy-MM-dd'T'HH:mm:ss'Z'"))]" doc:name="retrieve time last succes"/>
<set-variable variableName="subTime" value="#[payload]" doc:name="save retrieve time in var"/>
</sub-flow>
<sub-flow name="dynamic_call">
<set-variable variableName="result" value="#[[]]" doc:name="set emtpy array"/>
<set-payload value="["5598f15c-e4fb-482f-ba41-0ced971ec737", "f6cb0890-3650-47c0-ba53-202229c8c5df", "0de65b3b-b2c0-4dba-a54a-2bbef4e3bcf2"]" doc:name="Payload Array" mimeType="application/java"/>
<foreach doc:name="For Each" >
<http:request config-ref="HTTP_Request_Configuration" path="/request/change/serviceRequest" method="GET" doc:name="HTTP Service Request">
<http:request-builder>
<http:query-params expression="{"?$filter": "id eq #[payload]"}"/>
</http:request-builder>
</http:request>
<dw:transform-message doc:name="Append payload">
<dw:set-variable variableName="result"><![CDATA[%dw 1.0
%output application/json
---
flowVars.result ++ payload]]></dw:set-variable>
</dw:transform-message>
</foreach>
<http:request config-ref="HTTP_Request_Configuration" path="/request/change/serviceRequest" method="GET" doc:name="HTTP Request Ticket">
<http:request-builder>
<http:query-params expression="{"?$filter": "callDate lt #[flowVars.serverTime] and callDate gt #[flowVars.subTime]"}"/>
</http:request-builder>
</http:request>
<dw:transform-message doc:name="Append payload and set to JSON">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
flowVars.result ++ payload]]></dw:set-payload>
</dw:transform-message>
<file:outbound-endpoint path="C:\Users" outputPattern="test.json" responseTimeout="10000" doc:name="File"/>
</sub-flow>
<sub-flow name="Store_after_succes">
<objectstore:store config-ref="ObjectStore__Connector" key="time" value-ref="#[server.dateTime.format("yyyy-MM-dd'T'HH:mm:ss'Z'")] " doc:name="ObjectStore"/>
</sub-flow>
</mule>
You can add query Param like this. It will resolve the value of the payload and will not send the literal "#[payload] in the query param
<http:request config-ref="HTTP_Request_Configuration" path="/request/change/serviceRequest" method="GET" doc:name="HTTP Service Request">
<http:request-builder>
<http:query-param paramName="$filter" value="id eq #[payload]"/>
</http:request-builder>
</http:request>
I'm using a split function to create an array from the results, so I can use the foreach loop. The foreach loop contain HTTP request connector that takes the array as payload and loops over the different ids. The problem is when the array enters the loop it shows space sign (%20) which make the request wrong. Without space sign everything works fine. So my question how can i remove the spaces inside the http request?
Below I have added the input and output
before splitby
5598f15c-e4fb-482f-ba41-0ced971ec737,f6cb0890-3650-47c0-ba53-202229c8c5df,0de65b3b-b2c0-4dba-a54a-2bbef4e3bcf2
splitby on the above Id's
#[java.util.Arrays.asList(flowVars.Id.split(','))]
and Mime type application/java. After split() it creates a type of java.lang.String
0 = 5598f15c-e4fb-482f-ba41-0ced971ec737
1 = f6cb0890-3650-47c0-ba53-202229c8c5df
2 = 0de65b3b-b2c0-4dba-a54a-2bbef4e3bcf2
I use the next as Base Path in the HTTP request connector
(I misabuse the basepath so I can add dynamically content or payload ;)
/request/change/odata/serviceRequest?$filter=id eq#[payload]
when entering the loop I see this URL
https://service.request.com/request/change/serviceRequest?$filter=id%20eq5598f15c-e4fb-482f-ba41-0ced971ec737/%20
The expected result need to be like this;
https://service.request.com/request/change/serviceRequest?$filter=id eq 5598f15c-e4fb-482f-ba41-0ced971ec737
The XML source code;
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
<http:request-config name="HTTP_Request_Configuration_Service"
protocol="HTTPS" host="${service.host}"
port="${service.port}"
basePath="/request/change/serviceRequest?$filter=id eq #[payload]"
doc:name="HTTP Request Configuration" responseTimeout="${service.timeout}">
<http:basic-authentication username="${service.user}" password="${service.password}" preemptive="true"/>
</http:request-config>
<foreach doc:name="For Each">
<set-payload value="1234f15c-g4fb-511f-ba41-0ced971ec747,f6cb2052-3520-47c0-ba53-202029c8c5df,0ca68b3b-b2c0-4dba-a54a-2bbef4e8bcf2,12a8c48c-c221-4c10-82ab-c2222b5b2cac,3f394fda-d687-4d68-bb27-f532ca650803" doc:name="Incoming payload"/>
<dw:transform-message doc:name="Fetch the id">
<dw:set-variable variableName="id"><![CDATA[%dw 1.0
%output application/java
---
payload.value.id joinBy "," default ""]]></dw:set-variable>
</dw:transform-message>
<set-payload value="#[#[java.util.Arrays.asList(flowVars.id.split(','))]]" doc:name="Transform to array"/>
<foreach doc:name="For Each">
<http:request config-ref="HTTP_Request_Configuration_Service" path="" method="GET" doc:name="HTTP Request Service"/>
<dw:transform-message doc:name="Append payload">
<dw:set-variable variableName="outcome"><![CDATA[%dw 1.0
%output application/json
---
flowVars.outcome ++ payload]]></dw:set-variable>
</dw:transform-message>
</foreach>
</foreach>
</mule>
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore" xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp"
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns="http://www.mulesoft.org/schema/mule/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/current/mule-objectstore.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<http:request-config name="HTTP_Request_Configuration" host="service.request.com" port="443" doc:name="HTTP Request Configuration" basePath="/request/change/serviceRequest#[flowVars.path]"/>
<objectstore:config name="ObjectStore__Connector" partition="timeStamp" persistent="true" doc:name="ObjectStore: Connector"/>
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="ddddddddFlow1">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<flow-ref name="time_now" doc:name="time_now"/>
<flow-ref name="retrieve_and_save_time" doc:name="retrieve_and_save_time"/>
<flow-ref name="dynamic_call" doc:name="dynamic_call"/>
<flow-ref name="Store_after_succes" doc:name="Store_after_succes"/>
</flow>
<sub-flow name="time_now">
<set-variable variableName="serverTime" value="#[server.dateTime.format("yyyy-MM-dd'T'HH:mm:ss'Z'")] " doc:name="Now Time"/>
</sub-flow>
<sub-flow name="retrieve_and_save_time">
<objectstore:retrieve config-ref="ObjectStore__Connector" key="time" defaultValue-ref="#[(server.dateTime.plusHours(-2).format("yyyy-MM-dd'T'HH:mm:ss'Z'"))]" doc:name="retrieve time last succes"/>
<set-variable variableName="subTime" value="#[payload]" doc:name="save retrieve time in var"/>
</sub-flow>
<sub-flow name="dynamic_call">
<set-variable variableName="result" value="#[[]]" doc:name="set emtpy array"/>
<set-payload value="["5598f15c-e4fb-482f-ba41-0ced971ec737", "f6cb0890-3650-47c0-ba53-202229c8c5df", "0de65b3b-b2c0-4dba-a54a-2bbef4e3bcf2"]" doc:name="Payload Array"/>
<foreach doc:name="For Each" >
<set-variable variableName="path" value="?$filter=id eq #[payload]" doc:name="set path"/>
<http:request config-ref="HTTP_Request_Configuration" path="" method="GET" doc:name="HTTP Service Request">
</http:request>
<dw:transform-message doc:name="Append payload">
<dw:set-variable variableName="result"><![CDATA[%dw 1.0
%output application/json
---
flowVars.result ++ payload]]></dw:set-variable>
</dw:transform-message>
</foreach>
<http:request config-ref="HTTP_Request_Configuration" path="/request/change/serviceRequest" method="GET" doc:name="HTTP Request Ticket">
<http:request-builder>
<http:query-params expression="{"?$filter": "callDate lt #[flowVars.serverTime] and callDate gt #[flowVars.subTime]"}"/>
</http:request-builder>
</http:request>
<dw:transform-message doc:name="Append payload and set to JSON">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
flowVars.result ++ payload]]></dw:set-payload>
</dw:transform-message>
<file:outbound-endpoint path="C:\Users" outputPattern="test.json" responseTimeout="10000" doc:name="File"/>
</sub-flow>
<sub-flow name="Store_after_succes">
<objectstore:store config-ref="ObjectStore__Connector" key="time" value-ref="#[server.dateTime.format("yyyy-MM-dd'T'HH:mm:ss'Z'")] " doc:name="ObjectStore"/>
</sub-flow>
</mule>
That's truly abusing base path. It is not intended to be used in that way. The URL generated by abusing basePath is different to the expected. Having spaces encoded as "%020" is a standard and should not cause problems either way.
Try setting a query param instead and change its value in each iteration. Something like:
<http:request config-ref="HTTP_Request_Configuration" path="/somepath" method="{METHOD}" doc:name="HTTP {METHOD}">
<http:request-builder>
<http:query-params expression="#[flowVars.params]"/>
</http:request-builder>
</http:request>
and make the expression the whole string, not just the id, set flowVars.params to something like: {"$filter": "id eq #[payload]"}
I am using a Scatter Gather (component mule esb) witch contains many Saleforce Calls , after the Scatter Gather procces i got the following excpetion :
java.lang.UnsupportedOperationException : getPayloadAsString(), use getPayloadAsString(DataType.STRING_DATA_TYPE)
The config of the Scatter Gather component is by default
There is my xml config
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/sfdc
http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd
http://www.mulesoft.org/schema/mule/ee/tracking
http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/dw
http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<flow name="Test1">
<http:listener config-ref="httpListenerConfig" path="/test1" doc:name="HTTP"
allowedMethods="POST"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
—
payload]]></dw:set-payload>
</dw:transform-message>
<logger level="INFO" doc:name="Logger" message="Before Scatter Gather"/>
<scatter-gather doc:name="Scatter-Gather">
<processor-chain>
<sfdc:query config-ref="Salesforce__Basic_Authentication" query="Query
code....."/>
<logger level="INFO" doc:name="Logger" message="Call Saleforce Number 1"/>
</processor-chain>
<processor-chain>
<sfdc:query config-ref="Salesforce__Basic_Authentication" query="Query
code....."/>
<logger level="INFO" doc:name="Logger" message="Call Saleforce Number 2"/>
</processor-chain>
...
...
</scatter-gather>
<logger level="INFO" doc:name="Logger" message="After Scatter Gather"/>
<foreach doc:name="For Each">
<logger level="INFO" doc:name="Logger" message="First ForEach"/>
<foreach doc:name="For Each">
<logger level="INFO" doc:name="Logger" message="Second ForEach"/>
<flow-ref name="flowRefTest1" doc:name="flowRefTest1"/>
</foreach>
</foreach>
</flow>
</mule>
Any ideas how to resolve this problem guys ?
the reason for that sort of output is because the http endpoint in the beginning is not getting proper response to display so try setting payload in a proper format stating the completion after all the calls to Salesforce are done.
Hope this helps
i have a problem working with transform message component and mule ESB that I do not understand.
I have a simple flow that works fine, at the beginning it is Http endpoint and at the end it is Transform message component, transforms one JSON to another.
Now when I try to store payload before transform message to variable and then set payload to that variable, I get exception on transform message component:
Type mismatch
found :name, :string
required :name, :object (com.mulesoft.weave.engine.ast.dynamic.DynamicDispatchException)
com.mulesoft.weave.engine.ast.dynamic.DynamicDispatchNode:65 (null)
Here is a flow that works, and below that is the flow that doesn't work.
Flow that works:
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8085" doc:name="HTTP Listener Configuration"/>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<dw:transform-message metadata:id="b8a77df6-4692-4c52-b572-b6a175e7467e" doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
id: payload.transfer-id,
created-record-status: 'accepter'
}]]></dw:set-payload>
</dw:transform-message>
</flow>
</mule>
Flow that doesn't work>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8085" doc:name="HTTP Listener Configuration"/>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<set-variable variableName="OriginalPayload" value="#[payload]" doc:name="Variable"/>
<set-payload value="#[flowVars.OriginalPayload]" doc:name="Set Payload"/>
<dw:transform-message metadata:id="b8a77df6-4692-4c52-b572-b6a175e7467e" doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
id: payload.transfer-id,
created-record-status: 'accepter'
}]]></dw:set-payload>
</dw:transform-message>
</flow>
</mule>
When i put logger to log payload before transformation, it is the same in both flows....
Can somebody tell me what am I doing wrong?
Thanks Ivan.
since the set payload is missing mime type you are getting the error use the below xml,I have tested and its working fine.<set-payload value="#[flowVars.OriginalPayload]" doc:name="Set Payload" mimeType="application/json"/>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<http:listener-config name="HTTP_Listener_Confi" host="localhost" port="8085" doc:name="HTTP Listener Configuration"/>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Confi" path="/test" doc:name="HTTP"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<set-variable variableName="OriginalPayload" value="#[payload]" doc:name="Variable"/>
<set-payload value="#[flowVars.OriginalPayload]" doc:name="Set Payload" mimeType="application/json"/>
<dw:transform-message metadata:id="b8a77df6-4692-4c52-b572-b6a175e7467e" doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
id: payload.transfer-id,
created-record-status: 'accepter'
}]]></dw:set-payload>
</dw:transform-message>
</flow>
</mule>
I have made a web app which call mule server which is listening to http inbound point at 8081 for accessing the database.I am accessing the database successfully and getting a message. But I want to access the other rest services after I get the object from the database and run some operations.
I don't know how to achieve this.
Please give me example. I am posting my flow.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<http:endpoint exchange-pattern="request-response" host="localhost" port="8081" method="POST" name="HTTP" doc:name="HTTP"/>
<db:mysql-config name="MySQL_Configuration" host="localhost" port="3306" user="root" password="123456" database="Customer" doc:name="MySQL Configuration"/>
<flow name="muleesbintegrationFlow1" doc:name="muleesbintegrationFlow1">
<http:inbound-endpoint exchange-pattern="request-response" path="crud" doc:name="HTTP" ref="HTTP"/>
<set-session-variable variableName="input" value="#[message.inboundProperties.'http.query.params'.input]" doc:name="input"/>
<set-session-variable variableName="cid" value="#[message.inboundProperties.'http.query.params'.cid]" doc:name="cid"/>
<set-session-variable variableName="fname" value="#[message.inboundProperties.'http.query.params'.fname]" doc:name="fname"/>
<set-session-variable variableName="lname" value="#[message.inboundProperties.'http.query.params'.fname]" doc:name="lname"/>
<choice doc:name="ChoicerOfCrud">
<when expression="#[sessionVars['input']== "insert"]">
<db:insert config-ref="MySQL_Configuration" doc:name="insert">
<db:parameterized-query><![CDATA[INSERT INTO `Customer`.`customer` (`customer_id`, `fname`, `lname`) VALUES (#[sessionVars['cid']], #[sessionVars['fname']], #[sessionVars['lname']]);]]></db:parameterized-query>
</db:insert>
</when>
<when expression="#[sessionVars['input']]=="update"]">
<db:update config-ref="MySQL_Configuration" doc:name="update">
<db:parameterized-query><![CDATA[UPDATE `Customer`.`customer` set
fname = #[sessionVars['fname']],
lname= #[sessionVars['lname']]
where customer_id = #[sessionVars['cid']];]]></db:parameterized-query>
</db:update>
</when>
<when expression="#[sessionVars['input']=="select"]">
<db:select config-ref="MySQL_Configuration" doc:name="selected">
<db:parameterized-query><![CDATA[SELECT * FROM Customer.customer where customer_id =#[sessionVars['cid']];]]></db:parameterized-query>
</db:select>
</when>
<otherwise>
<db:delete config-ref="MySQL_Configuration" doc:name="delete">
<db:dynamic-query><![CDATA[DELETE FROM `Customer`.`customer` WHERE `customer_id`=#[sessionVars['cid']];]]></db:dynamic-query>
</db:delete>
</otherwise>
</choice>
</flow>
</mule>
I recommend to use http:outbound-endpoint to consume a REST service (GET,POST, PUT or DELETE). In this example you can see a flow to invoke a services GET:
<flow name="invoke-ws" doc:name="invoke-ws">
<vm:inbound-endpoint exchange-pattern="request-response" path="vm-ws" doc:name="VM"/>
<logger message="payload is: #[payload]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" method="GET" address="http://ip:port/service/#[payload]" doc:name="HTTP">
<set-property propertyName="Accept" value="application/json"/>
</http:outbound-endpoint>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<logger message="payload is: #[payload]" level="INFO" doc:name="Logger"/>
</flow>
If the service is SOAP over HTTP, I recommend using http://www.mulesoft.org/documentation/display/current/Web+Service+Consumer