web service consumer soap fault extraction - mule

I am using web service consumer and calling a soap service and it will return below soap fault incase of number of hits reaches more than the limit. When the soap fault is caught in the error handler under the type WSC:SOAP_FUALT, I want to read the faultstring and if it is "Maximum request limit reached, please try again later.", I dont want to consider it as failure and point the payload for retry.
So please let me know how to extract the fault string inorder to put a check on it.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>Internal Server Error</faultcode>
<faultstring>Maximum request limit reached, please try again later.</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

The soap fault message returned by Web Service Consumer is stored within the errorMessage field in the error of the flow.
So you can use error.errorMessage.payload.Envelope.Body.Fault.faultstring to access that string in your error handler block, and use it in the when condition of the error handler itself to execute that handler when this message matches the required criteria. For example:
XML Code:
<on-error-continue enableNotifications="true"
logException="true" doc:name="On Error Continue"
doc:id="38283c80-4c20-46da-85e3-f47d5d5755b7" type="WSC:SOAP_FUALT"
when="#[(error.errorMessage.payload.Envelope.Body.Fault.faultstring default '') startsWith ('Maximum request limit reached')]">
<logger message="Error message caught by the error handler: #[error.errorMessage.payload.Envelope.Body.Fault.faultstring]" level="INFO" doc:name="Logger" doc:id="1f329e43-d401-412f-9479-f58bef4089c4" />
</on-error-continue>

You can use a simple DataWeave expression to extract the string:
%dw 2.0
output application/java
---
payload.Envelope.Body.Fault.faultstring
Output:
Maximum request limit reached, please try again later.

Related

Timeout Configuration

I am configuring transaction and response timeout for API in Mule 4, Is there anyway that I set different timeout for different methods(GET,POST,DELETE) for single API in Mule Soft because the API has different SLA for different operations ?
As the http timeout is set at the connector level that does not allow you to set timeouts per method.
One way you could try to achieve this is via separating your interface flow from your logic. Then have your interface flow call your logic flow via something like vm where you can set a timeout individually. You can then catch the timeout error and do what you want with it.
Here is an example that has a flow for a POST method. All this flow does is offload the logic to another floe and invokes that logic using v:publish-consume and awaits the response. It sets a timeout of 2 seconds(configurable with properties etc.) and catches VM:QUEUE-TIMEOUT errors and sets an 'SLA exceeded'error message:
<flow name="myPOSTInterface">
<vm:publish-consume queueName="postQueue" config-ref="vm" timeout="2" timeoutUnit="SECONDS" />
<logger level="INFO" message="Result from logic flow: #[payload]" />
<error-handler>
<on-error-continue type="VM:QUEUE_TIMEOUT">
<set-payload value="#[{error: 'SLA exceeded'}]" />
</on-error-continue>
</error-handler>
</flow>
<flow name="myPOSTLogic">
<vm:listener config-ref="vm" queueName="postQueue" />
<set-payload value="#[{result: 'Result from my logic'}]" />
</flow>

how to query bufferInput stream in mule esb

I am spending a lot time to understand how to convert a bufferInput stream or Dataweaveoutputhandler to other datatypes such as string or object or xml
I am constantly getting this type of error whenever I changed expression
Execution of the expression "xpath3('/*',payload,'NODESET')" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: BufferInputStream (org.mule.api.transformer.TransformerMessagingException). Message payload is of type: BufferInputStream
Please help me to know if anyone has solved this issue.
Exception is thrown by wrong xpath3 expression, not wrong payload type. You use xpath3 in splitter? Paste some xml, below working xpath3 expression example.
<splitter expression="#[xpath3('//YOUR_NODENAME',payload, 'NODESET')]" doc:name="Splitter"/>
If you want to log payload just try:
<logger message="Response := #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
Apache provide us with great library to convert between various datatypes.
http://axis.apache.org/axis2/java/core/apidocs/org/apache/axis2/databinding/utils/ConverterUtil.html#convertToDataHandler(java.lang.String)
kindly go with this.
Thanks!

How to validate part of message in WSOESB and choose first?

Here is how it works.
I do have dss service that returns message of format
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dss="https://rmis33.r-mis.ru/services/dss">
<soapenv:Header/>
<soapenv:Body>
<dss:Requests>
<dss:Request>...</dss:Request>
<dss:Request>...</dss:Request>
<dss:Request>...</dss:Request>
....
<dss:Request>...</dss:Request>
</dss:Requests>
</soapenv:Body>
</soapenv:Envelope>
I have to split message on Request element and validate it, then choose first that pass validation over XSD.
It is hard to do on database level because it has a lot of elements(sub-elements) and XSD was already provided.
You can use validate mediator to validate XML messages against XML schema.There is a complete sample which demonstrates validating messages.

append specieal charecters in payload tag in Mule ESB

i want payload value like below in <http:outbound-endpoint>:
<set-variable variableName="url" value="#[json:url]" doc:name="Variable"></set-variable>
<set-variable variableName="payload" value="#[json:param]" doc:name="Variable"></set-variable>
<http:outbound-endpoint exchange-pattern="request-response" address="http://admin:admin##[url.substring(7)]" method="POST" doc:name="HTTP" password="admin" user="admin">
<set-payload value="action=start&params={input:#[payload]}&createTask=false&parts=all"/>
</http:outbound-endpoint>
but it is giving error.
thanks.
You can get rid of the error by replacing & with &
However, that is not your only problem.
payload is a reserved variable to hold the current payload. You can not use set-variable with variableName="payload", your setting will just be ignored when you call #[payload] later.
Your POST data would be something like action=start&params={input:yourdata}&createTask=false&parts=all. This is some kind of hybrid of JSON and HTTP GET syntax, and I doubt that this is what you are trying to achieve. If you want to send a POST request in key=val format, set a payload of type Map. If you want to send the request as JSON, set a payload with a JSON String, you have the object-to-json-transformer to help in Mule. If you want to have parameters in the URL, put them in the URL. But you can not mix these different syntaxes.

Having trouble with mule append-string-transfomer

I am using this configuration expression.
<flow name="quartz">
<quartz:inbound-endpoint name="quartzstart" jobName="job1" repeatInterval="5000">
<quartz:envent=generator-job/>
<byte-array-to-string-transformer/>
<append-string-transformer message="Check Message"/>
<tcp:outbound-endpoint host="localhost" port="7778" connector-ref="protocol"/>
</flow>
It triggers every 5 seconds.
I was expecting the received message to be
Check Message
but the message I received was
(NullPayload)Check Message
How can I receive only "Check Message" ?
It seems that the toString of a null payload is returning (NullPayload).
You could set-payload with an empty string before the appender, or if this is your full logic just set-payload with "Check Message".