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

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.

Related

Mocking a connector throws error like Element not defined in Mule Registery

I am creating the Munit tests and mocking the salesforce connector for the query. The Query response in the flow returns the payload in application/java type. So below is the Mock the setting
<munit:test name="salesforce-sys-implementation-test-suite-salesforce-Quote-create-flowTest" doc:id="40f70f6a-3453-4a8b-9ed8-673e4796c0be" description="Test">
<munit:behavior>
<munit-tools:mock-when doc:name="Mock when" doc:id="5bfeb53b-2da1-45f9-bad3-67cf4d658fc2" processor="salesforce:query">
<munit-tools:with-attributes >
<munit-tools:with-attribute whereValue="Query Existing Quote" attributeName="doc:name" />
<munit-tools:with-attribute whereValue="19c396a3-8656-4600-beba-9e011e78d2b4" attributeName="doc:id" />
</munit-tools:with-attributes>
<munit-tools:then-return >
<munit-tools:payload value="[{Product_Description__c=false, Shipment_Schedule__c=false, Executive_Summary_checkbox__c=false, type=Quote, Milestones_checkbox__c=false, Terms_and_Conditions__c=true, Timeline_Tool__c=false, Signature__c=false, Executive_Summary__c=null, Quote_Sent_To__r=null, Contact_Information__c=true, Gantt_Chart__c=false, Animal_Health_Policy__c=true, Opportunity={RecordTypeId=012U0000000QtmpIAC, Id=null, type=Opportunity}, Materials_and_Pricing__c=false, Cancelation_Policy__c=true, To_accept_this_statement_of_work__c=true, Customer_Signature__c=false, Id=0Q02D0000005vu7SAA, Fees_and_Invoicing__c=true}]" mediaType="application/java" encoding="UTF-8" />
</munit-tools:then-return>
</munit:behavior>
<munit:execution>
<munit:set-event doc:name="Set Event" doc:id="b09dba54-76cc-401b-85aa-5657849861c4">
<munit:payload value="#[MunitTools::getResourceAsString('samples/quote.json')]" encoding="UTF-8" mediaType="application/json" />
</munit:set-event>
<flow-ref doc:name="Flow Reference" doc:id="875fa5b7-290d-4d3f-abfe-3098bf6c7ce1" name="salesforce-Quote-create-flow"/>
</munit:execution>
<munit:validation >
<set-variable value="#[output application/json --- readUrl('classpath://samples/quoteResponse.json', 'application/json')]" doc:name="Set Variable" doc:id="6fd61167-5025-4da3-8277-c9303ba9da57" variableName="expectedPayload"/>
<munit-tools:assert-that doc:name="Assert that Not Null Response" doc:id="dc4d4008-83bd-4da6-8773-fc4aa0285d0c" is="#[MunitTools::notNullValue()]" expression="#[vars.expectedPayload.Id]"/>
</munit:validation>
</munit:test>
It throws error when I run the test
Element '[{Product_Description__c=false,....., Opportunity={RecordTypeId=012U0000000QtmpIAC, Id=null, type=Opportunity}}]' is not defined in the Mule Registry
How to set the response payload on the Mock which is the Query response here which of application /java type
It looks like you missed the # before the brackets at the value to indicate it is an expression. I'm guessing that without considering an expression MUnit tries to use the value as a literal id to search in the Mule Registry, but that is not something you need to care about. Just add the missing # and try again.
Example:
<munit-tools:payload value="#[output application/java
--- {Product_Description__c:false,...}]" />

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

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>

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 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.

Mule 3.2 flow and cxf:jaxws-service

I am relatively new to mule and trying to define a mule flow which takes request XML via soap-based Web service. The XML is based on a complex schema and I have generated classes using WSDL2Java
After receiving the request cxf:jaxws-service executes the method submitOrder(SubmitOrderRequest parameters). After this method's execution I would like to transform the request XML to a little bit different format. Then this XML needs to be forwarded to another web service. The problem is that the mule message that comes out of ServiceImpl contains SubmitOrderResponse whereas I still want to work on SubmitOrderRequest.
<flow name="testService">
<http:inbound-endpoint address="http://localhost:62005/test"
exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="com.test.ServicePortType" />
</http:inbound-endpoint>
<component class="com.test.ServiceImpl" />
<!-- transformer ref="MVIRequestTransformer" / -->
<!-- xm:object-to-xml-transformer / -->
<!-- logger message="XML payload is #[payload]" level="INFO" / -->
<!-- SEND TRASNFORMED MESSAGE TO ANOTHER SERVICE -->
</flow>
#WebService(endpointInterface = "com.pennmutual.services.mvi.MVIServicePort")
public class ServiceImpl implements ServicePortType {
...
#Override
public SubmitOrderResponse submitOrder(SubmitOrderRequest parameters) {
...
}
...
}
What are my options are. I can think of the following –
1. Put the request object somewhere in the context and retreive it later on for processing.
2. Change the return type of submitOrder to Object and return SubmitOrderRequest instead of SubmitOrderResponse.
Please suggest the best possible way to handle this situation. I am using mule 3.2.
I think there are two elegant way to do that (excluding the one that involves changing the webservice interface)
Store the request into a session variable and restore it afterwards.
Here is how your flow would look like:
<flow name="testService">
<http:inbound-endpoint address="http://localhost:62005/test" exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="com.test.ServicePortType" />
</http:inbound-endpoint>
<message-properties-transformer scope="session">
<add-message-property value="payload" key="originalPayload" />
</message-properties-transformer>
<component class="com.test.ServiceImpl" />
</flow>
Use the enricher around the component to store the returned value into a variable so that it won't become the payload of your flow. Following an example of how to achieve this
<flow name="Echo" doc:name="Echo">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="6090" path="echo" encoding="UTF-8" />
<cxf:jaxws-service serviceClass="org.mule.example.echo.Echo" />
<enricher target="#[variable:echo]">
<component class="org.mule.example.echo.Echo" />
</enricher>
<logger level="ERROR" message="#[variable:echo]"/>
</flow>
You can find more informations on the enricher here