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>
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.
Am facing this exception when am calling stored procedure with "clob" as data type for inserting xml data into database using mulesoft,its showing exception on oracle .
this is my config file
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:db="http://www.mulesoft.org/schema/mule/db"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc"
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/db http://www.mulesoft.org/schema/mule/db/current/mule-db.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/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/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.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/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
<flow name="opp_to_sales_orderFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/opportunity" doc:name="HTTP"/>
<sfdc:query config-ref="Salesforce__Basic_Authentication" query="SELECT Id, Product_Name__c, Account.name FROM Opportunity " doc:name="Salesforce"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml skipNullOn="everywhere"
---
list: { (payload map {
linked-hash-map : {
name:$.Account.Name,
id: $.Id,
Product_name: $.Product_Name__c
}
})
}
]]></dw:set-payload>
</dw:transform-message>
<logger level="INFO" doc:name="Logger" message="#[payload]"/>
<byte-array-to-string-transformer encoding="UTF-8" mimeType="application/xml" doc:name="Byte Array to String"/>
<db:stored-procedure config-ref="Oracle_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[call xxnew_order_create.xxenv_order_creation8(
:p_mule_input,
:x_order_cursor
:x_error_code, :x_error_message,
:x_sales_order
)]]></db:parameterized-query>
<db:in-param name="p_mule_input" type="LONGVARCHAR" value="#[message.payload]"/>
<db:out-param name="x_order_cursor" type="CURSOR"/>
<db:out-param name="x_sales_order" type="VARCHAR"/>
<db:out-param name="x_error_code" type="VARCHAR"/>
<db:out-param name="x_error_message" type="VARCHAR"/>
</db:stored-procedure>
<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 message="#[payload]" level="INFO" doc:name="Logger"/>
<catch-exception-strategy doc:name="Exception Handling ">
<logger level="INFO" doc:name="StartLog"/>
<set-payload value="{ "errorMessage" : "#[exception.message]", "exception":"#[exception.getDetailedMessage()]" }" encoding="UTF-8" mimeType="text/html" doc:name="Catch Exception"/>
<set-property propertyName="http.status" value="400" doc:name="http.status"/>
<logger level="INFO" doc:name="EndLog"/>
</catch-exception-strategy>
</flow>
</mule>
thank you
Please paste your config file it is due to type casting before passing as clob you need data is in string format.
Please try to use a groovy component and add the code like below.
clobTest = (java.sql.Clob)payload.your_field bodyText = clobTest.getCharacterStream() targetString = org.apache.commons.io.IOUtils.toString(bodyText) payload.PAYLOADHEADERS=targetString return payload
comma was missing in procedure parameters now its working fine thanks for your response
I am looking to call an internal REST API and pass the payload back in Mule 3.7.3. The request is only the URL and no body but I am getting payload errors like nullPayload.
How can I get this to work?
I am testing it with this public API https://apisandbox.openbankproject.com/obp/v2.0.0/banks
and the code I have mocked up is here:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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.7.3"
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/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"/>
<http:request-config name="HTTP_Request" host="https://apisandbox.openbankproject.com" port="443" basePath="/obp/v2.0.0" doc:name="HTTP Request Configuration"/>
<flow name="account-balance-flow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" allowedMethods="GET" doc:name="HTTP"/>
<set-payload value="#['{}']" doc:name="Set Payload"/>
<http:request config-ref="HTTP_Request" path="/banks" method="GET" doc:name="HTTP"/>
<logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
Host should not contain a URL. It should just be the host, and HTTPS protocol specified separately. Also no need to set the payload for a GET request. updated code that works:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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.7.3"
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/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"/>
<http:request-config name="HTTP_Request" protocol="HTTPS" host="apisandbox.openbankproject.com" port="443" basePath="/obp/v2.0.0" doc:name="HTTP Request Configuration"/>
<flow name="account-balance-flow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" allowedMethods="GET" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request" path="/banks" method="GET" doc:name="HTTP"/>
<logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
I have spent the past few hours trying to get until-successful to work properly, but to no avail even after following the model here: "http://blogs.mulesoft.org/meet-until-successful-store-and-forward-for-mule/". The main flow that uses until-successful is SEND_TO_POST_SERVICE. I want until-successful to continue running the referenced flow until the max retries. Below are my flows and relevant information. The internal Mule server version is 3.4, and the Mule Studio version is 3.4.0
################## Flow
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:core="http://www.mulesoft.org/schema/mule/core"
version="EE-3.4.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<choice-exception-strategy name="Post_Exception_Strategy">
<catch-exception-strategy when="exception.causedBy(java.net.SocketTimeoutException) or exception.causedBy(java.net.ConnectException)" doc:name="Catch Exception Strategy">
<logger message="Network exception occurred" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
<catch-exception-strategy when="exception.causedBy(java.lang.Throwable)" doc:name="Catch Exception Strategy">
<logger message="General exception occurred" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
<flow name="compositeFlow1"
doc:name="compositeFlow1">
<composite-source doc:name="Comp Source">
<inbound-endpoint doc:name="DTCOM"
ref="SUBMISSION_REQUEST_EP"/>
</composite-source>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<flow-ref name="POST_TO_SERVICES"
doc:name="POST_TO_SERVICES_ref"/>
<exception-strategy ref="Post_Exception_Strategy"
doc:name="Reference Exception Strategy"/>
</flow>
<flow name="POST_TO_SERVICES" doc:name="POST_TO_SERVICES" processingStrategy="synchronous">
<!-- Send to the POST Service -->
<async>
<flow-ref name="SEND_TO_POST_SERVICE" doc:name="SEND_TO_POST_SERVICE_ref"/>
</async>
<outbound-endpoint ref="HTTP_EP_1" doc:name="HTTP_EP_1"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<set-variable variableName="statusCode" value="#[message.inboundProperties['http.status']]" doc:name="statusCode"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<logger message="Data submitted to Endpoint HTTP_STATUS_CODE: #[statusCode]" level="INFO" doc:name="Logger"/>
<exception-strategy ref="Post_Exception_Strategy" doc:name="Reference Exception Strategy"/>
</flow>
<spring:beans>
<spring:bean id="myListableObjectStore" class="org.mule.util.store.SimpleMemoryObjectStore"/>
</spring:beans>
<flow name="SEND_TO_POST_SERVICE" doc:name="Send to POST Service">
<choice doc:name="Choice">
<when expression="${send_to_post} == 'true'">
<until-successful objectStore-ref="myListableObjectStore" maxRetries="3" secondsBetweenRetries="2" doc:name="Until_Success">
<flow-ref name="CONNECT_TO_POST_SERVICE" doc:name="CONNECT_TO_POST_SERVICE_ref"/>
</until-successful>
</when>
<otherwise>
<logger message="NOT Posting to SERVICE" level="DEBUG" doc:name="Send_Logger"/>
</otherwise>
</choice>
</flow>
<flow name="CONNECT_TO_POST_SERVICE" doc:name="CONNECT_TO_POST_SERVICE">
<logger message="$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$In Until-Successful for POST" level="INFO" doc:name="USLogger"/>
<processor-chain doc:name="Processor Chain">
<logger message="Sending JSON to POST Service" level="INFO" doc:name="JSON_POST_Logger"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="Content-Type" value="application/json"/>
</message-properties-transformer>
<outbound-endpoint ref="POST_SERVICE_EP" doc:name="POST_SERVICE" exchange-pattern="request-response"></outbound-endpoint>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<logger message="Status Code response from Sending POST JSON = #[message.inboundProperties['http.status']]" level="INFO" doc:name="StatusCodeLog"/>
<logger message="Message from POST Service for #[payload]" level="INFO" doc:name="LoggerMessageOutput"/>
</processor-chain>
</flow>
</mule>
################## Endpoints
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns:https="http://www.mulesoft.org/schema/mule/https"
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.3.1" 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/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.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:endpoint name="POST_SERVICE_EP" exchange-pattern="request-response" address="http://127.0.0.1:8900/post/service/" connector-ref="http_connector" contentType="application/json" doc:name="HTTP"/>
<http:endpoint name="HTTP_EP_1" method="PUT" contentType="application/json" connector-ref="http_connector_2" address="http://127.0.0.1:8900/put/service/" doc:name="HTTP"/>
</mule>
################## Connectors
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:https="http://www.mulesoft.org/schema/mule/https"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" version="EE-3.3.1" 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/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.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:connector name="http_connector" clientSoTimeout="1000000" serverSoTimeout="1000000" doc:name="http_connector" keepAlive="true">
<receiver-threading-profile maxThreadsActive="10" doThreading="true" threadWaitTimeout="-1" maxBufferSize="10000" maxThreadsIdle="5" poolExhaustedAction="WAIT"/>
<dispatcher-threading-profile maxThreadsActive="10" doThreading="true" threadWaitTimeout="-1" maxBufferSize="10000" maxThreadsIdle="5" poolExhaustedAction="WAIT"/>
</http:connector>
<http:connector name="http_connector_2" doc:name="http_connector" keepAlive="true">
<receiver-threading-profile maxThreadsActive="10" doThreading="true" threadWaitTimeout="-1" maxBufferSize="10000" maxThreadsIdle="5" poolExhaustedAction="WAIT"/>
<dispatcher-threading-profile maxThreadsActive="10" doThreading="true" threadWaitTimeout="-1" maxBufferSize="10000" maxThreadsIdle="5" poolExhaustedAction="WAIT"/>
</http:connector>
</mule>
The flow you are flow-refing (ie CONNECT_TO_POST_SERVICE) is a private flow not a sub-flow.
This means that exceptions thrown in it will not be propagated to the caller. Change it to a sub-flow and it should work.
PS. Also remove the processor-chain in CONNECT_TO_POST_SERVICE: it's completely useless.