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>
Related
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 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.
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'm not able to refer the query from flowVariable inside database connector. I have read that it was a known issue in mule 3.5. I'm not sure if it is still an open issue in 3.8. Do any one know about it ?
Below is the flow -
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:db="http://www.mulesoft.org/schema/mule/db" 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/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.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">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<db:mysql-config name="MySQL_Configuration5" host="localhost" port="3306" user="root" password="root" database="world" doc:name="MySQL Configuration"/>
<flow name="selectFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/db/select" allowedMethods="GET" doc:name="HTTP"/>
<db:select config-ref="MySQL_Configuration5" doc:name="local mysql database">
<db:parameterized-query><![CDATA[select * from country where code='IND']]></db:parameterized-query>
</db:select>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
<flow name="deleteFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/db/delete" allowedMethods="DELETE" doc:name="HTTP"/>
<db:delete config-ref="MySQL_Configuration5" doc:name="local mysql database">
<db:parameterized-query><![CDATA[delete from countrylanguage where countrycode='PAK']]></db:parameterized-query>
</db:delete>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
<flow name="postFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/db/insert" allowedMethods="POST" doc:name="HTTP"/>
<set-variable variableName="jsonString" value="#[payload]" doc:name="Variable"/>
<flow-ref name="cleanUpBeforeInserting" doc:name="cleanUpBeforeInserting"/>
<json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.Collection"/>
<flow-ref name="InsertEachRecord" doc:name="Flow Reference"/>
</flow>
<flow name="cleanUpBeforeInserting">
<db:delete config-ref="MySQL_Configuration5" doc:name="Database">
<db:parameterized-query><![CDATA[delete from countrylanguage where countrycode='PAK']]></db:parameterized-query>
</db:delete>
<set-payload value="#[flowVars.jsonString]" doc:name="Set Payload"/>
<logger message="************* cleaned up data **************** " level="INFO" doc:name="Logger"/>
</flow>
<sub-flow name="InsertEachRecord">
<foreach doc:name="For Each">
<set-variable variableName="sqlStatement" value="Insert into countrylanguage (countrycode, language, percentage, isofficial) values(#[payload.CountryCode], #[payload.Language],#[payload.Percentage], #[payload.IsOfficial])" doc:name="Variable"/>
<logger message="#[flowVars.sqlStatement]" level="INFO" doc:name="Logger"/>
<db:insert config-ref="MySQL_Configuration5" doc:name="Database">
<db:parameterized-query><![CDATA[#[flowVars.sqlStatement]]]></db:parameterized-query>
</db:insert>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</foreach>
</sub-flow>
</mule>
It works fine if I replace the #[flowVars.sqlStatement] with Insert into countrylanguage (countrycode, language, percentage, isofficial) values(#[payload.CountryCode], #[payload.Language],#[payload.Percentage], #[payload.IsOfficial])
Any pointers would be helpful. Thanks in advance.
Instead using <db:parameterized-query> try with <db:dynamic-query> like following
<db:insert config-ref="MySQL_Configuration5" doc:name="Database">
<db:dynamic-query><![CDATA[#[flowVars.sqlStatement]]]></db:dynamic-query>
</db:insert>
In Mulesoft, How can I manage multiple twitter user accounts dynamically because at present it requires consumerkey, consumersecret, accesskey and accesstoken in connector configuration for an application which can own only one user.
Please anyone can explain?
<twitter:config name="Twitter__Configuration" accessKey="#[flowVars.accessToken]" consumerKey="#[flowVars.consumerKey]" consumerSecret="#[flowVars.consumerSecret]" doc:name="Twitter: Configuration" accessSecret="#[flowVars.accessTokenSecret]"/>
<flow name="twitterFlow1">
<db:select config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select * from twittercredentials;]]></db:parameterized-query>
</db:select>
<set-variable variableName="consumerKey" value="#[message.payload[0]['consumerkey']]" doc:name="Variable" />
<set-variable variableName="consumerSecret" value="#[message.payload[0]['consumersecret']]" doc:name="Variable" />
<set-variable variableName="accessToken" value="#[message.payload[0]['accesstoken']]" doc:name="Variable" />
<set-variable variableName="accessTokenSecret" value="#[message.payload[0]['accesstokensecret']]" doc:name="Variable" />
</flow>
<flow name="twitterFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/twitterconnect" doc:name="HTTP"/>
<flow-ref name="twitterFlow1" />
<twitter:show-user config-ref="Twitter__Configuration" doc:name="Twitter"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
assigned the values in variables and accessed as flowvars in the global element which fails.
I think in this post from mule community forum you can find the answer to your question.
Basically you can use mule expression language in twitter globalk connector in this way:
<twitter:config name="Twitter" accessKey="#[flowVars.accessKey]"
accessSecret="#[flowVars.accessSecret]" consumerKey="#
[flowVars.consumerKey]" consumerSecret="#[flowVars.consumerSecret]"/>
Hope this helps
Full example:
This is an example flow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:twitter="http://www.mulesoft.org/schema/mule/twitter" 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/twitter http://www.mulesoft.org/schema/mule/twitter/current/mule-twitter.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<twitter:config name="Twitter" accessKey="#[flowVars['accessKey']]" accessSecret="#[flowVars['accessSecret']]" consumerKey="Cannot be parametrized" consumerSecret="Cannot be parametrized" useSSL="false" doc:name="Twitter"/>
<flow name="twitterFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<message-properties-transformer scope="invocation" doc:name="Message Properties">
<add-message-property key="accessKey" value="#['myVarAccessKey']"/>
<add-message-property key="accessSecret" value="#['myVarAccessSecret']"/>
</message-properties-transformer>
<twitter:update-status config-ref="Twitter" status="ciao" doc:name="Twitter"/>
</flow>
</mule>
Here also a screenshot of a wireshark capture using IP filtering (twitter ip families) for debug the http call: