I am using Anypoint Studio 6.1 and Mule 3.8.1 and have a JSON example in main/src/api called response-flow1.json. I want to set my payload to response-flow1.json if certain rules are met. How can I reference response-flow1.json in a Set Payload?
Thanks
To save the trouble of loading a file (Only if it's a small JSON), you can set your JSON payload in a variable in a properties file. Then call it like this:
<set-payload value="#[${samplejson}]" doc:name="Set Payload"/>
If this is not the answer you were looking for, please provide more information and I'll be glad to help. Thank you!
You can try the following: -
<set-payload value="#[Thread.currentThread().getContextClassLoader().getResourceAsStream('response-flow1.json')]" doc:name="Set Payload"/>
Best practice will be keeping the response-flow1.json under resource folder
We have the option to use the dataweave:
<set-payload value="#[dw('readUrl("classpath://examples/filename.json","application/json")')]" doc:name="Set Mock Payload"/>
Related
When setting up the all the possible response codes and their descriptions for an endpoint in API Management Service, I can only choose an existing status code from a dropdown list, but it doesn't allow me to add a custom status code, such as 499. I use the 499 status code in my API for a specific type of error relevant to my applicatoin. Is there any way to add this to the list of responses?
You could dynamic mocking using APIM with an APIM policy called return-response.
<return-response>
<set-status code="200" reason="OK" />
<set-header name="content-type" exists-action="override">
<value>"application/json"</value>
</set-header>
<set-body>{
"id": "cat12345",
"name": "Garfield",
"tag": "Sleepy Cat"
}</set-body>
</return-response>
For more details, you could refer to this tutorial.
Not with forms UI. But if you select an API, there'll be a pencil in Frontend block on Design tab. It allows you to edit your API specification in OpenAPI 2/3 spec. Using that it should be possible to add a custom response statuses code.
I am using the Mule Requestor to receive a collection of files via FTP.
In order to do this with a collection I am using the Collection Splitter which works great. The only problem is that when I am returning to the HTTP Connector it throws the following exception:
java.lang.UnsupportedOperationException: getPayloadAsBytes(), use
getPayload(DataType.BYTE_ARRAY_DATA_TYPE)
I am guessing this has something to do with the payload type that is trying to be inserted into the response, but I am fairly new in the Mule arena. Any idea what could be causing this and what I should do to resolve the issue?
I have tried setting the payload after the logger, that didn't work.
Code:
<flow name="fileGetter">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP" allowedMethods="GET"></http:listener>
<mulerequester:request-collection config-ref="Mule_Requester" resource="ftp_For_Requester_Dependent" doc:name="Mule Requester</mulerequester:request-collection>
<collection-splitter doc:name="Collection Splitter"></collection-splitter>
<logger level="INFO" doc:name="Logger" message="#[message.inboundProperties.originalFilename]"></logger>
</flow>
The reason you are getting java.lang.UnsupportedOperationException: getPayloadAsBytes(), use getPayload(DataType.BYTE_ARRAY_DATA_TYPE) is obvious, since you are splitting the payload, at the end your HTTP in causing the issue as there will be a split response .
One solution would be, use an aggregator at the end of your flow and that will prevent this exception.
A <collection-aggregator/> at the end will be a good choice and help to prevent this
UPDATE
Keep it under <async> block and it will run successfully
I have a service response is :
<Response>
<BackUrl>www.hao123.com</url>
<resultCode>0</resultCode>
</Response>
I set messageType:"application/json". The response is:
{Response:{"BackUrl":"coship.com","resultCode":"0";}}.
But I need transform this message to a json string like:
{"BackUrl":"http://www.coship.com","resultCode":"0"}
How ro remove node "Response". I tried to use script mc.setPayloadJSON in ESB 4.5.1. But errors happened.
https://wso2.org/jira/browse/ESBJAVA-1618?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel#issue-tabs
Anyone can help me? Thank you very much.
There is an issue reported as mentioned, and it is not resolved yet. But, you can set messgae type as
<property name="messageType" value="application/json" scope="axis2"/>
and check?
here is a post which may useful to you
I'm transforming XML request to SOAP via XSLT in WSO2ESB, just wondering is it possible to make request parameter available to be used in response?
E.g.
<request>
<test>123</test>
<param1>testing</param1>
</request>
-> converted to SOAP
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">#S:Body><ns2:testrequest xmlns:ns2="http://xml.testing.com/test"><teststring>testing</teststring></ns2:testrequest></S:Body></S:Envelope></soapenv:Body></soapenv:Envelope>
In the response
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:testresponse xmlns:ns2="http://xml.testing.com/test"><responsestring>success</responsestring></ns2:testresponse></S:Body></S:Envelope></soapenv:Body></soapenv:Envelope>
I want to return in XML
<responsestring>
<test>123</test>
<return1>success</return1>
</responsestring>
As you see, 123 isn't send to the server and has not received from the server. However, client is sending this parameter and i would like to just use this parameter in request and send back in response, is this possible? By how? I'm very new to synapse and very new to WSO2ESB, could anyone please enlighten me?
Thanks.
Yes it is possible. You can use property mediator in the Insequence to set the required value as a property and then add it in the outsequence to response using enrich mediator.
Got it working now.
Simply by adding the property mediator in both insequence and outsequence together with the XSLT, where the xslt is trying to get the value from test property. That's it!
Insequence
<property xmlns:ns="http://org.apache.synapse/xsd" name="TEST" expression="//request/*[local-name()=test]" scope="default"/>
outsequence
<xslt key="xxxx.xslt">
<property name="test" expression="get-property('TEST')"/>
</xslt>
I am trying to use Mule 3.2.0 s Collection Aggregator. I tried using Mule Studio but seems it is still not available in Mule studio for configuration though the icon does appear in the "Flow Control" section.
My use case is -
I get a message from a VM Inbound endpoint. I now want to pass that to 3 different flows - all using the same request object but performing different operations - say A,B,C. All of them update their respective databases but they are all part of a common Order_ID(somethig internal to our application). The 3 processes may take different processing times but once done each of them return the same success response. I want to use an aggregator which will aggregate all these responses without timing out and then forward that to a Java component or another VM Endpoint for further processing.
The Mule documentation for Collection Aggregator doesn't seem to be very informative so if some one who has used Collection Agg can help me out with the xml config for the above scenario it will be very helpful
Instead of Collection Aggregator use All message processor. It sends the same message to every processor inside it and aggregates the results after they finish.
http://www.mulesoft.org/documentation/display/MULE3USER/Routing+Message+Processors#RoutingMessageProcessors-All
Sample config: (I send "foo" to the vm endpoint)
<flow name="main" processingStrategy="asynchronous">
<vm:inbound-endpoint path="in"/>
<all>
<flow-ref name="flow1"/>
<flow-ref name="flow2"/>
</all>
<logger message="#[payload:]" level="INFO"/>
</flow>
<flow name="flow1">
<append-string-transformer message="bar1"/>
</flow>
<flow name="flow2">
<append-string-transformer message="bar2"/>
</flow>
Console output:
INFO 2012-08-15 17:26:01,749 [main.stage1.02] org.mule.api.processor.LoggerMessageProcessor: [foobar1, foobar2]
HTH
I would go with to use ALL component and the endpoint you use should be request-response (two-way where the flow waits for the response).
Thus the ALL component will aggregate the response an then returns you a CopyOnWriteArrayList with all the response from the flows A,B and C. This Array list you can transform in any desired way using a custom transformer by extending AbstractTransformer in your java class.
Cheers,
Naveen Raj