Mule 4 - How to do error handling inside a cache scope? - mule

I'm using cache scope and object store to cache data returned from a Salesforce Query using Salesforce Connector.
I've added On error continue to catch any Salesforce Connector exceptions.
If there is an exception in Salesforce Connector (like Salesforce Connectivity), the application throws an exception and executes On error continue block, but when it is called again application hangs at the cache scope and doesn't give any response/error message. Also, On error continue block is executed thrice when the application is executed first time.
It's running fine in debug mode.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:os="http://www.mulesoft.org/schema/mule/os" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:salesforce="http://www.mulesoft.org/schema/mule/salesforce"
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/salesforce http://www.mulesoft.org/schema/mule/salesforce/current/mule-salesforce.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/os http://www.mulesoft.org/schema/mule/os/current/mule-os.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="6a5b02b3-836d-43b5-9dbe-41719d20258f" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<salesforce:sfdc-config name="Salesforce_Config" doc:name="Salesforce Config" doc:id="3facafa3-5d07-4717-901a-487f0cdeabb2" >
<salesforce:basic-connection username="..." password="..." securityToken="..." url="https://login.salesforce.com/services/Soap/u/48.0" />
</salesforce:sfdc-config>
<ee:object-store-caching-strategy name="Caching_Strategy" doc:name="Caching Strategy" doc:id="4ebcc02a-3c51-445b-bee5-0c95e4ce6e01" keyGenerationExpression="#['1']" >
<os:private-object-store persistent="false" maxEntries="1" entryTtl="1" />
</ee:object-store-caching-strategy>
<flow name="test-errorFlow" doc:id="49520788-7379-45cb-9276-cdb6b268398c" >
<http:listener doc:name="Listener" doc:id="ce5faf93-3153-4f93-8313-90d465f920c6" config-ref="HTTP_Listener_config" path="/test" allowedMethods="GET">
<http:response statusCode="#[vars.httpStatus]" />
<http:error-response statusCode="#[vars.httpStatus]" >
<http:body ><![CDATA[#[error]]]></http:body>
</http:error-response>
</http:listener>
<ee:cache doc:name="Cache" doc:id="ae4e7d76-0f98-4202-9a51-59373ea3ee1c" cachingStrategy-ref="Caching_Strategy">
<salesforce:query doc:name="Query" doc:id="1498398a-7b1f-4a27-aff8-3991d4e9cbca" config-ref="Salesforce_Config">
<salesforce:salesforce-query><![CDATA[Select Id, Name from Account]]></salesforce:salesforce-query>
</salesforce:query>
</ee:cache>
<ee:transform doc:name="Transform Message" doc:id="f864be76-86a9-4726-b1f1-586ffeabb0db" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
</ee:message>
</ee:transform>
<error-handler >
<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="038cd795-2174-4d9a-b759-2921dd12a64e" type="ANY">
<logger level="INFO" doc:name="Logger" doc:id="186587c2-0beb-416a-b589-7239a2cba7dd" message="#[error]"/>
</on-error-continue>
</error-handler>
</flow>
</mule>

'On error continue' means to finish flow even if error occurs. But finishing flow does not mean that it did its job - in particular cache value was not obtained. That's the reason the erst is failing.
Rearrange your flow - if cache value is null - run cache again and again ( for example https://docs.mulesoft.com/mule-runtime/4.3/until-successful-scope ) and only success continue your regular flow with existing real cache value.

The problem is likely that there is nothing to cache, because the error aborted the execution.
You can either use a Try scope to handle the error inside the Cache scope, or call to another flow with a flow-ref, and handle the error inside that other flow.
Example:
<ee:cache doc:name="Cache" cachingStrategy-ref="Caching_Strategy">
<try>
<salesforce:query doc:name="Query" config-ref="Salesforce_Config">
<salesforce:salesforce-query><![CDATA[Select Id, Name from Account]]></salesforce:salesforce-query>
</salesforce:query>
<error-handler>
<on-error-continue>
....
</on-error-continue>
</error-handler>
</try>
</ee:cache>

Related

How to raise a Custom Error With Internal payload (error.errorMessage.payload) in MUnit

A little description of the flow: I have a flow that is making an HTTP call to a REST Webservice. There are a couple of errors that we get as statusCode=500 but with different "errorCodes" inside the response body. This request connector is wrapped inside a try block with multiple on-error-continue based on the content of the response body in its "when" attribute. eg: error.errorMessage.payload.errorCode==CODE_A. Adding an image and source code of the flow below
<?xml version="1.0" encoding="UTF-8"?>
<mule 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:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="dee432d7-a176-448c-a1ac-a374a86fa85b" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="test2Flow" doc:id="be602af1-cfcf-46f1-a312-ea6a5544503b" >
<http:listener doc:name="Listener" doc:id="f160fa61-15be-4744-b823-973e20740e73" config-ref="HTTP_Listener_config" path="/test"/>
<logger level="INFO" doc:name="Some logic before request" doc:id="6354a117-e918-4937-a1d9-df4ae0ef6386" message="Some logic before request"/>
<try doc:name="Try" doc:id="15bd106a-c116-4d87-958e-8ad698026739" >
<http:request method="GET" doc:name="Request" doc:id="a046919e-f149-45d6-9a70-db37cac0540f" url="http://example.com/some-resource" />
<error-handler >
<on-error-continue enableNotifications="true" logException="true" doc:name="when error.errorMessage.payload.errorCode==CODE_A" doc:id="20fc0575-da65-41b4-81f7-d364227b1639" when='error.errorMessage.payload.errorCode=="CODE_A"'>
<logger level="INFO" doc:name="Some logic for CODE_A" doc:id="a699ccd0-952c-415f-b288-4ea027f2cff2" message="Some logic for CODE_A" />
</on-error-continue>
<on-error-continue enableNotifications="false" logException="false" doc:name="when error.errorMessage.payload.errorCode==CODE_B" doc:id="63dc8aa5-5fae-4235-a4ae-a80903a76362" when='error.errorMessage.payload.errorCode=="CODE_B"' >
<logger level="INFO" doc:name="Some logic for CODE_B" doc:id="9364ff1e-4bcd-48d5-a37a-a207828cda9d" message="Some logic for CODE_B" />
</on-error-continue>
</error-handler>
</try>
<logger level="INFO" doc:name="Some logic After request" doc:id="fd754198-d6b5-40dd-b23f-c8619faee7e6" message="Some logic After request" />
</flow>
</mule>
What I am trying to do: I am trying to write MUnit to verify if the correct error-handler block is executed based on response. However, I do not see any option to mock an error with its errorMessage part filled.
What I am looking for: I am trying to find out one of these
Anyway to mock error with errorMessage using the simple mock-when'sthen-return element. I do not think it is possible, but if there is a way please let me know.
Maybe there is a way to use a Java class for raising complex errors. I am thinking if I can use mock-when'sthen-call to call a flow and then raise an error using it.
Any other way to do it.
Note:
Mule version: 4.3.0 MUnit version: 2.3.0
I can not make change in the REST webservice, I do not own that.
I am trying to avoid any code change, For example, I can ignore status code in the message validator and do the error handling using response directly, with something like choice. But I will do it as the last resort
You can try using something like this when mocking error for HTTP requests:
Create the following DW file:
httpError.dwl
var detailMessage = 'Internal server error'
var myJsonResponse = '{"errorCode":"ERROR_A"}'
var typedValue = java!org::mule::runtime::api::metadata::TypedValue::new(myJsonResponse, java!org::mule::runtime::api::metadata::DataType::JSON_STRING)
var errorMessage = java!org::mule::runtime::api::message::Message::of(typedValue)
var errorType = java!org::mule::extension::http::api::error::HttpError::INTERNAL_SERVER_ERROR
---
java!org::mule::extension::http::api::request::validator::ResponseValidatorTypedException::new(detailMessage, errorType, errorMessage)
In your MUnit test suite file, create the following flow:
<flow name="munit-set-error-code-event-flow" doc:id="3b7e266c-2f3b-4105-8fdb-8ea44d5f128e" >
<munit:set-event doc:name="Generate error" doc:id="4ee8b870-6c8b-4570-bc70-7ec0086a1bca" cloneOriginalEvent="true">
<munit:error id="HTTP:INTERNAL_SERVER_ERROR" exception="#[${file::httpError.dwl}]" />
</munit:set-event>
</flow>
And, finally, in your actual MUnit test flow, configure the then-call option to call the above flow. Eg:
<munit:test name="test-test-suite-testFlowTest" doc:id="5670a9cd-758a-4f2c-a55f-57b48a9f3b41" description="Test" timeOut="1200000">
<munit:behavior >
<munit-tools:mock-when doc:name="Mock when" doc:id="466fd55c-80b4-4e27-82ed-f561223a3b4f" processor="http:request">
<munit-tools:with-attributes >
<munit-tools:with-attribute whereValue="08c4fba6-ef4b-4006-bd7d-deb1fd0f5304" attributeName="doc:id" />
</munit-tools:with-attributes>
<munit-tools:then-call flow="munit-set-error-code-event-flow" />
</munit-tools:mock-when>
</munit:behavior>
<munit:execution >
<flow-ref doc:name="Flow-ref to testFlow" doc:id="c57b3265-b453-432c-88fd-db2df7125fdc" name="testFlow"/>
</munit:execution>
</munit:test>
Although I'm not sure if this is something recommended to do, it should work for what you want to achieve.
Let me know if it works.

Need Help for interpretation of Error Handling Scenario for Mulesoft

My Mulesoft POC contains globalErrorHandler as well as localErrorHandler having OnErrorContinue scope, I noticed yet it throws a MULE:EXPRESSION error ,Can anyone let me know the reason for it . The code is below enclosed with the pic of the flow .
Code
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="f8f3f4bb-341a-43ec-acf8-9ed33419f5ef" basePath="/error" >
<http:listener-connection host="0.0.0.0" port="8082" />
</http:listener-config>
<configuration doc:name="Configuration" doc:id="689a9085-287e-43e4-8e3d-5eeac857dc64" defaultErrorHandler-ref="globalError_Handler"/>
<flow name="example-errorFlow" doc:id="c37abd41-2143-4da1-848a-a8c240853b60" >
<http:listener doc:name="Listener" doc:id="9cda3f2d-a48d-40bd-96a4-54d856d0438e" config-ref="HTTP_Listener_config" path="/"/>
<set-payload value='"MAIN"' doc:name="Set Payload" doc:id="a1b3890f-6157-4716-84d3-8f6ccd6e9af5" />
<ee:transform doc:name="Transform Message" doc:id="9fc2571b-7038-4359-82db-be624d48b343" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
["RESPONSE"] ++ payload ]]></ee:set-payload>
</ee:message>
</ee:transform>
<error-handler >
<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" type= "HTTP:NOT_FOUND" doc:id="e6f2b028-e3ca-4eff-b878-0f41dd53d693" >
<set-payload value='"HTTP:NOT_FOUND"' doc:name='"HTTP:NOT_FOUND"' doc:id="c465edf3-bbac-4fca-bfb1-f2a6678e1173" />
</on-error-continue>
</error-handler>
</flow>
<error-handler name="globalError_Handler" doc:id="05e153b7-d663-4aa1-85c0-8fefbf76c39b" >
<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="c0e80820-db0f-4b3f-b0e2-c74c47e3a5e7" >
<set-payload value="global Error Handler" doc:name="global Error Handler" doc:id="0055b184-4dd6-4d20-8284-27534570f723" />
</on-error-continue>
</error-handler>
</mule>
FlowImage
The error is coming from your Transform component but you are handling only HTTP:NOT FOUND error.
Handle all exceptions as described here
https://simpleflatservice.com/mule4/OnErrorContinue.html
In particular - simple remove error type and you will see actual message and can fix it.
Post it here and we can help.
In the transform you're trying to use ++ function with an Array and String which is incorrect (in your case its ["RESPONSE"] ++ payload where payload = "MAIN"), coming to flow error handling you're handling a specific error from HTTP namespace, whereas the error you get is from MULE namespace of type EXPRESSION, so thats the reason the local error handler is unable to handle that error.
To handle this either use MULE:EXPRESSION or MULE:ANY which can serve as a parent error type for MULE:EXPRSSION and HTTP:NOT_FOUND errors
The MULE namespace is an implicit namespace you can also call it as a parent namespace which can handle any runtime based error.
To better understand errors, their hierarchy and global error handler consider visiting the resource mentioned below.
https://youtu.be/9WcG9teCrvo

How to update the value of a Key in ObjectStore in Mule4?

My requirement is, i need to count messages which are processed for a day.
So, i created a subflow, where I created a persistent objectstore . I retrive it initially with the default value 0. Then , I pass that to java AtomicInteger class to do increment each time, when request comes in. Now I store the new value.
<sub-flow name="impl-message-counter:\counter-set-flow" doc:id="929c5fa5-74a2-4e8e-b1a0-43209b57222c" >
<os:retrieve doc:name="Retrieve" doc:id="565ecf6c-ffba-491e-b2c9-35ef4b4f52ad" key="counter" objectStore="Object_store" target="count">
<os:default-value ><![CDATA[0]]></os:default-value>
</os:retrieve>
<java:new constructor="AtomicInteger(int)" doc:name="New" doc:id="f0e75c0b-914a-44ee-9e24-a597025afd77" class="java.util.concurrent.atomic.AtomicInteger" target="atomicinteger">
<java:args ><![CDATA[#[output application/java
---
{
arg0 : vars.count as Number {class: "java.lang.Integer"}
}]]]></java:args>
</java:new>
<java:invoke doc:name="Invoke" doc:id="60779082-ad71-4770-b871-8d86044aa62a" instance="#[vars.atomicinteger]" class="java.util.concurrent.atomic.AtomicInteger" method="incrementAndGet()" target="newVal"/>
<os:store doc:name="Store" doc:id="8f85aa4f-5bce-4248-8a3b-a8cde27a1307" key="counter" objectStore="Object_store">
<os:value><![CDATA[#[vars.newVal]]]></os:value>
</os:store>
</sub-flow>
In the above flow, i want to add a check processor, to see the day is passed or not. If it passes midnight I wnat to reassign it to 0. Else continue with increment;
<choice doc:name="Choice" doc:id="120b1f05-7afe-4cfc-a103-0b26f9df7140" >
<when expression="#[now().hour==23 and now().minutes==59 and now().seconds==60]">
<os:store doc:name="Store" doc:id="3d995b22-a648-4c7f-af54-33d70b23705c" key="counter" objectStore="Object_store" >
<os:value ><![CDATA[#[0]]]></os:value>
</os:store>
</when>
<otherwise >
<os:store doc:name="Store" doc:id="8f85aa4f-5bce-4248-8a3b-a8cde27a1307" key="counter" objectStore="Object_store">
<os:value><![CDATA[#[vars.newVal]]]></os:value>
</os:store>
</otherwise>
</choice>
But above will work? I think it will skip if same key present in same objectstore? How can I update existing key?
This is good idea but you have to be aware that object store is unreliable. You can check it if you write a simple test and do load and stress test. Especially in cluster.
First and usually it works but later and especially on concurrent requests at the same moment it fails. So, use it if with caution and do not rely on it. Worst part - it will break you flow. What we can do is -
https://simpleflatservice.com/mule4/IgnoreUnreliableObjectStorage.html - wrapping every single call to object store to try block and simply ignore any failure or unexpected results.
Here is code
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:os="http://www.mulesoft.org/schema/mule/os"
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/os http://www.mulesoft.org/schema/mule/os/current/mule-os.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<flow name="selftestFlow" doc:id="79a89806-adea-4017-a838-8b8c3e2002df" >
<http:listener doc:name="Listener" doc:id="63128e3f-34f5-4f04-9b8a-0bebe67f763c" config-ref="HTTP_Listener_config" path="/counter"/>
<try doc:name="Try" doc:id="d5d83aa3-b271-41b0-98a6-381823164de4" >
<os:retrieve doc:name="Retrieve" doc:id="f6d3cccd-a7be-44fa-a51d-36bddbc5892f" key="test" target="localTest">
<os:default-value><![CDATA[N/A]]></os:default-value>
</os:retrieve>
<error-handler >
<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="b14ab2e4-c871-4af8-a488-9c70284a525f" />
</error-handler>
</try>
<ee:transform doc:name="Transform Message" doc:id="bc50c855-34b4-4661-9f42-2b18e441782d" >
<ee:message >
</ee:message>
<ee:variables >
<ee:set-variable variableName="localTest" ><![CDATA[%dw 2.0
output application/java
---
if (vars.localTest is Number) ( vars.localTest as Number + 1 ) else ( 1 as Number )]]></ee:set-variable>
</ee:variables>
</ee:transform>
<try doc:name="Try" doc:id="2d54c616-7fb6-41ba-bc05-0918199bcba4" >
<os:store doc:name="Store" doc:id="2847d9db-d2f6-4bc4-a0a5-dca0eafbdd49" key="test">
<os:value><![CDATA[#[vars.localTest]]]></os:value>
</os:store>
<error-handler >
<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="90e6616a-af11-4af6-a82f-e9823f764ceb" />
</error-handler>
</try>
<ee:transform doc:name="Transform Message" doc:id="bdc2a164-3d80-427f-b95d-a7dfc2b69400" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{ counter: vars.localTest }]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
</mule>

How to read file in middle of the flow

I am trying to read two simultaneously file in middle of the flow and combine them into one payload. To reading the files in middle of the flow I am using mule requester component. While triggering the flow (localhost:8081/requester/requester)I am getting error :
"Exception(s) were found for route(s):
0: The endpoint "src\main\resources\input1\employees.xml" is malformed and cannot be parsed. If this is the name of a global endpoint, check the name is correct, that the endpoint exists, and that you are using the correct configuration (eg the "ref" attribute). Note that names on inbound and outbound endpoints cannot be used to send or receive messages; use a named global endpoint instead. (org.mule.api.endpoint.MalformedEndpointException).
1: The endpoint "src\main\resources\input2\employees2.xml" is malformed and cannot be parsed. If this is the name of a global endpoint, check the name is correct, that the endpoint exists, and that you are using the correct configuration (eg the "ref" attribute). Note that names on inbound and outbound endpoints cannot be used to send or receive messages; use a named global endpoint instead. (org.mule.api.endpoint.MalformedEndpointException)."
<?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:mulerequester="http://www.mulesoft.org/schema/mule/mulerequester" xmlns:file="http://www.mulesoft.org/schema/mule/file" 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/mulerequester http://www.mulesoft.org/schema/mule/mulerequester/current/mule-mulerequester.xsd http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.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/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">
<file:connector name="file-connector-config" autoDelete="false" streaming="true" validateConnections="true" doc:name="File" />
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="/requester" doc:name="HTTP Listener Configuration" />
<flow name="muleRequester">
<http:listener config-ref="HTTP_Listener_Configuration" path="/requester" doc:name="HTTP" />
<logger message="Invoking Mule Requester" level="INFO" doc:name="Logger" />
<scatter-gather doc:name="Scatter-Gather">
<mulerequester:request resource="src\main\resources\input1\employees.xml" returnClass="java.lang.String" doc:name="Retrieve File1"/>
<mulerequester:request resource="src\main\resources\input2\employees2.xml" returnClass="java.lang.String" doc:name="Retrieve File2"/>
</scatter-gather><dw:transform-message doc:name="Transform Message">
<dw:set-payload>< [CDATA[%dw 1.0 %output application/json
---
{
payload1: payload[0],
payload2: payload[1]
}]]></dw:set-payload>
</dw:transform-message>
<file:outbound-endpoint path="src/main/resources/output" responseTimeout="10000" doc:name="File"/>
<logger message="Payload after file requester #[payload]" level="INFO" doc:name="Logger" />
</flow>
I am not using maven. Do I need to download any other jar or where I can do the correction?
resource needs to be an Mule endpoint url. Mule requester module can work with many transports such as jms, file, ftp. So the path to the file is not enough. Here is an example of an endpoint url for reading a file:
<mulerequester:request resource="file://src/main/resources/in/ReadME.txt?connector=file-connector-config" doc:name="Retrieve File" returnClass="java.lang.String" />
You can also point to a global endpoint like you have defined like so:
<mulerequester:request config-ref="muleRequesterConfig" resource="myFileEndpoint" doc:name="Mule Requester" />

How to configure mule cxf proxy client correctly

Hi I'm playing around with a SOAP request, I am having trouble with the cxf proxy client. I'm basically sending a soap request to the http endpoint, removing the SOAP envelope, then trying to add it back it back on with the proxy client.
I'm expecting to get an unathorized response (as I'm removing the wsse headers).
However, I get the following soap response: "Response code 500 mapped as failure. Message payload is of type: BufferInputStream"
and the console logs the following (Note this is only the start of it)
WARN 2015-05-13 12:38:28,886 [[sandbox2].HTTP_Listener_Configuration.worker.01] org.apache.cxf.phase.PhaseInterceptorChain: Interceptor for {http://support.cxf.module.mule.org/}ProxyService#{http://support.cxf.module.mule.org/}invoke has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Response code 500 mapped as failure. Message payload is of type: BufferInputStream
at org.mule.module.cxf.transport.MuleUniversalConduit$2.handleMessage(MuleUniversalConduit.java:194) ~[mule-module-cxf-3.6.1.jar:3.6.1]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) ~[cxf-api-2.5.9.jar:2.5.9]
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:531) ~[cxf-rt-core-2.5.9.jar:2.5.9]
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:462) ~[cxf-rt-core-2.5.9.jar:2.5.9]
Here is my flow
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" 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.6.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/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8086" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="8080" basePath="my-app/RetrieveAct.svc" doc:name="HTTP Request Configuration"/>
<flow name="myFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<logger message="message received #[payload] " level="INFO" doc:name="Logger"/>
<cxf:proxy-service namespace="PfPolicyService" payload="body" doc:name="CXF"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<cxf:proxy-client payload="body" doc:name="CXF"/>
<response>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</response>
<http:request config-ref="HTTP_Request_Configuration1" path="http://localhost:8080/my-app/RetrieveAct.svc" method="POST" doc:name="HTTP">
<http:request-builder>
<http:header headerName="soapAction" value="getUserAcct"/>
</http:request-builder>
</http:request>
</flow>
</mule>
Can anyone explain what I am doing wrong and how to correct the issue?
Thanks
The issue you're experiencing is because your modification of the SOAP request is ending up as an invalid SOAP request, therefore the server cannot parse it and it is returning a 500 http status code.
You can use CXF's logging interceptors to be able to inspect the final result of what you're sending.
Your mule flow seems okey to me, the proxied service might blow up for all sorts of reasons.
Add logging interceptors to the proxy client and see whether this enables you to pinpoint the issue:
<cxf:proxy-client payload="body">
<cxf:inInterceptors>
<spring:bean class="org.apache.cxf.interceptor.LoggingInInterceptor">
<spring:property name="prettyLogging" value="true" />
</spring:bean>
</cxf:inInterceptors>
<cxf:outInterceptors>
<spring:bean class="org.apache.cxf.interceptor.LoggingOutInterceptor">
<spring:property name="prettyLogging" value="true" />
</spring:bean>
</cxf:outInterceptors>
</cxf:proxy-client>
Or alternatively, use TPCMon to capture network traffic.
Setting up a service mock and proper test case first would be a good sanity check, before doing integration testing.