In wso2 ei 6.6 I am calling first api and getting the response application/octet-stream using this response how to create multipart request.
<payloadFactory media-type="xml">
<format>
<root>
<file
xmlns="http://org.apache.axis2/xsd/form-data">$1
</file>
</root>
</format>
<args>
<arg evaluator="xml" expression="$body/">
</args>
</payloadFactory>
If I set like the above payload factory I am getting empty response or encoded binary response. How can I fetch the media type and set multipart in wso2 ei.
Your question is not entirely clear to me whether the problem is with the response of the request but since you mention "How to set multipart"
With the below payload factory you should be able to create a multi part payload including a filename based on the incoming file content.
<payloadFactory media-type="xml">
<format>
<root
xmlns="">
<file xmlns="http://org.apache.axis2/xsd/form-data" filename="$2">$1</file>
</root>
</format>
<args>
<arg evaluator="xml" expression="$body/mediate/fileContent"/>
<arg evaluator="xml" expression="$body/mediate/fileContent/#filename"/>
</args>
Source: I hope this blog might help you:
https://www.yenlo.com/blogs/multipart-form-data-uploads-wso2-ei-esb/
Related
I have a below request (i am using WSO2 Enterprise integrator 6.5.0):
And I wanna get this in jsonpayload which is returned client
<ERROR_RESP>
<ERROR>
<ECODE>ST-VALS-002</ECODE>
<EDESC>Record Not Found for Branch Code-CHO:Currency 1-USD:Currency 2-MN</EDESC>
</ERROR>
<ERROR>
<ECODE>ST-SAVE-024</ECODE>
<EDESC>Failed to Query Data</EDESC>
</ERROR>
</ERROR_RESP>
It is my tried code to achieve it :
<foreach expression="json-eval($.ERROR_RESP.ERROR)">
<sequence>
<payloadFactory media-type="json">
<format>
{
"ErrorCode" : "$1",
"ErrorMessage" : "$2"
}
</format>
<args>
<arg evaluator="json" expression="$.ECODE"/>
<arg evaluator="json" expression="$.EDESC"/>
</args>
</payloadFactory>
<log level="full">
<property name="MESSAGE" value="ENDLOOP"/>
</log>
<loopback/>
</sequence>
</foreach>
enter code here
I did some search but nothings worked, I think foreach expression is not right.
Thanks
Regards,
In your sample the Loopback mediator is used. It will be used to move the message to the out flow (response path). Therefore, the Foreach mediator splits the message and sends the first message to the response path and end the flow.
You can prepare the XML payload and convert it to JSON using the messageType property with axis2 scope as follows.
<foreach expression="//ERROR">
<sequence>
<payloadFactory media-type="xml">
<format>
<ERROR xmlns="">
<ErrorCode>$1</ErrorCode>
<ErrorMessage>$2</ErrorMessage>
</ERROR>
</format>
<args>
<arg evaluator="xml" expression="//ECODE/text()"/>
<arg evaluator="xml" expression="//EDESC/text()"/>
</args>
</payloadFactory>
</sequence>
</foreach>
<property name="messageType" scope="axis2" value="application/json"/>
The final message will be like this:
{
"ERROR_RESP": {
"ERROR": [
{
"ErrorCode": "ST-VALS-002",
"ErrorMessage": "Record Not Found for Branch Code-CHO:Currency 1-USD:Currency 2-MN"
},
{
"ErrorCode": "ST-SAVE-024",
"ErrorMessage": "Failed to Query Data"
}
]
}
}
At the moment, foreach mediator in EI 6.5.0 does not support "json-eval()" expressions. This feature will be included in the upcoming versions.
As a workaround, you can use XPath inside the expression. You can use this blog as an example. https://medium.com/#Manuri/wso2-esb-foreach-mediator-example-87f041e2a912
I'm trying to create Message Mediation Policies, with which I can make an additional http call, process the response and enrich the current message. How can i do this? I use call Mediator, but I don’t understand how to handle the response.
<?xml version="1.0" encoding="UTF-8"?> <sequence name="call_out_handler" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<call blocking="true">
<endpoint>
<http method="get" uri-template="http://192.168.99.100:8888/stubFORAPIMan/ServletWithTimeout"/>
</endpoint>
</call> </sequence>
You can use the PayloadFactory Mediator [1] to handle/format the response you received by calling an endpoint inside the Call mediator.
An example would be like this. Say you want to provide a json object by populating the values from the response you received; you can define the json object format in the "format" section and populate the values by providing the arguments in the "args" section in the PayloadFactory mediator as below.
<payloadFactory media-type="json">
<format>
{
"Data": {
"PaymentSubmissionId": "$1",
"PaymentId": "$2",
"Status": "$3",
"CreationDateTime": "$4"
}
}
</format>
<args>
<arg evaluator="xml" expression="$body//PaymentSubId"/>
<arg evaluator="xml" expression="$body//PaymentId"/>
<arg evaluator="xml" value="AcceptedSettlementInProcess"/>
<arg value="2019-06-05T15:15:22+00:00"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
[1] https://docs.wso2.com/display/EI640/PayloadFactory+Mediator
In this case, how can I get the "MyString" content in WSO2 response?
Request:
<payloadFactory media-type="json">
<format>{
"Name" : "$1",
"group": "$3"
}
</format>
<args>
<arg evaluator="xml" expression="$ctx:Name"/>
<arg evaluator="xml" expression="$ctx:group"/>
</args>
</payloadFactory>
<call>
<endpoint key="ep_Server"/>
</call>
response:
Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">{"MyString":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjEsIlN5c3RlbUlkIjoyMSwiUHJvcGVydHlJZCI6OSwiSXNBZG1pbiI6ZmFsc2UsIkNyZWF0ZURhdGVUaW1lIjoiMjAxNy0xMS0wOFQxMDoyMjoxMi45MDA3MjE4KzA4OjAwIn0.k6FyUGwXOAeC63oGsPWz8ttwo1LeDG3vnTbw7dJ18GY"}</text></soapenv:Body></soapenv:Envelope>
Try this.
<log>
<property name="MyString" expression="json-eval($.MyString)"></property>
</log>
Ref: https://docs.wso2.com/display/ESB500/JSON+Support
In your case the output is not json it's xml containing a text, usually it indicate that you're using text/plain type, I think the issue is there.
Moreover your output is not matching the sample code you've
Could you try to put the following before your call:
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
What is the content type that the service you're calling is returning? Is it valid? If not it could be that wso2 ei is by default considering it's text
I have this below mentioned soap request, I am using WSO2ESB 4.9.
Soap request :
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><jsonArray><jsonElement><a><s>as</s></a><b>Type1</b><c>C1</c><d><t>A1</t></d><e>e1</e></jsonElement><jsonElement><a><s>as</s></a><b>Type2</b><c>C2</c><d><t>A1</t></d><e>e1</e></jsonElement></jsonArray></soapenv:Body></soapenv:Envelope>
I want to iterator over jsonElement/b and get json list : ["Type1", "Type2"].But I am getting below list :
[
"\n\t\t\t\t\t\t\t\t\t\t\tType1\n\t\t\t\t\t\t\t\t\t",
"\n\t\t\t\t\t\t\t\t\t\t\tType2\n\t\t\t\t\t\t\t\t\t"
]
Please any way to get the required list.For each mediator :
<foreach expression="//jsonArray/jsonElement">
<sequence>
<payloadFactory media-type="xml">
<format>
<jsonElement>
$1
</jsonElement>
</format>
<args>
<arg expression="//b" evaluator="xml" />
</args>
</payloadFactory>
</sequence>
</foreach>
Got it working, there is space and newline in foreach <jsonElement>.
Working code:
<foreach expression="//jsonArray/jsonElement">
<sequence>
<payloadFactory media-type="xml">
<format>
<jsonElement xmlns="">$1</jsonElement>
</format>
<args>
<arg expression="//b" evaluator="xml" />
</args>
</payloadFactory>
</sequence>
</foreach>
I am working on a wso2 scenario in which I send a SOAP message to a webservice and then receive and manipulate the answer. For this purpose I have TWO Webservices. One is placed in a test environment (1) and the another is the live one (2).
I have no access to the webservice code, I'm just a user.
The problem is:
Via SOAPUI
I'm able to use the service from Webservices (1) and (2). No error, everything works fine.
Via WSO2
I'm able to use the service from webservice (1) but when I point to the webservice (2) I get a HTML 403 Forbidden response instead of a SOAP/XML message.
Am I missing something or this could be a misconfiguration of the webservice?
Following my in/out requests:
Sequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="pricing" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<smooks config-key="smooks-csv.xml">
<input type="text"/>
<output type="xml"/>
</smooks>
<iterate expression="//product" id="iterateXML" sequential="true"
xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd">
<target>
<sequence>
<payloadFactory media-type="xml">
<format>
<xyz xmlns="http://tempuri.org/">
<safeKey>$6</safeKey>
<storeId>$5</storeId>
<articleId>$1</articleId>
<barcode/>
<sku>$2</sku>
<price>$3</price>
<discount>$4</discount>
</xyz>
</format>
<args>
<arg evaluator="xml" expression="//articleId"/>
<arg evaluator="xml" expression="//sku"/>
<arg evaluator="xml" expression="//price"/>
<arg evaluator="xml" expression="//discount"/>
<arg evaluator="xml" expression="//storeId"/>
<arg evaluator="xml" expression="//key"/>
</args>
</payloadFactory>
<in>
<header name="Action" scope="default" value="http://tempuri.org/xyz"/>
<send>
<endpoint>
<recipientlist>
<endpoint key="PS_PRICING"/>
<endpoint key="fileSave"/>
</recipientlist>
</endpoint>
</send>
<drop/>
</in>
<out>
<send/>
</out>
<log level="full" separator=";">
<property expression="*" name="ResponsePriceUpdate"/>
</log>
</sequence>
</target>
</iterate>
</sequence>
UPDATE:
After testing using TCPMon and TCPTrace I got the following:
Via SOAPUi
If I send the message SOAPUi -> Live Webservice - Works fine! (Picture a)
If I send the message SOAPUi -> TCPMon/TCPTrace -> Live Webservice - 403 Forbidden! (Picture b)
It doesn't make sense at all to me. I'm running out of ideas.
(a)
(b)
For the people who has found this question relevant:
The problem was in the server-side. Server was rejecting some "unknown" sources of incoming traffic.
Maybe add ?wsdl as postfix to the url: http://sample.com/webservice.asmx?wsdl