WSO2 Enterprise Integrator Version - 7.1.0 ----- 3 Soap calls are made in a single API - soap

when 2 soap calls are made as explained below in the code
<api xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteAPI" context="/stockquote">
<resource uri-template="/view/{symbol}" methods="GET">
<inSequence>
<payloadFactory>
<format>
<m0:getQuote xmlns:m0="http://services.samples">
<m0:request>
<m0:symbol>$1</m0:symbol>
</m0:request>
</m0:getQuote>
</format>
<args>
<arg expression="get-property('uri.var.symbol')"/>
</args>
</payloadFactory>
<header name="Action" value="urn:getQuote"/>
<call>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>
</endpoint>
</call>
<property name="messageType" description="transformxml" scope="axis2" type="STRING" value="application/json"/>
<property name="getQuoteResponse" description="Response of getQuote" expression="json-eval($.)"/>
<header name="Action" value="urn:placeOrder"/>
<call>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>
</endpoint>
</call>
<property name="messageType" description="transformxml" scope="axis2" type="STRING" value="application/json"/>
<property name="placeOrderResponse" description="Response of placeOrder" expression="json-eval($.)"/>
</inSequence>
<outSequence>
</outSequence>
</resource>
</api>
We are having the getQuoteResponse (First Soap call) is always persists till the end and in the logs the getQuoteResponse is getting printed in the base64 encoded format.
We are not able to do anything with the placeOrderResponse (Second Soap call).
Kindly help to get the placeOrderResponse to be stored in a variable and getQuoteResponse shouldn't persist through the api orchestration.

Related

WSO2 EI 6.6.0 TenantMgtAdminService through proxy

I'm trying to access retrieveTenants method from TenantMgtAdminService.
For this I've created a custom proxy in EI 6.6.0 with the following code :
<?xml version="1.0" encoding="UTF-8"?><proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy_RetrieveTenants" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
<target>
<inSequence>
<property name="POST_TO_URI" scope="axis2" value="true"/>
<property xmlns:ns="http://org.apache.synapse/xsd" expression="fn:concat('Basic ', base64Encode('ws.palmsoft:YWRtaW46YWRtaW4'))" name="Authorization" scope="transport"/>
<call>
<endpoint>
<wsdl uri="https://localhost:9443/services/TenantMgtAdminService.TenantMgtAdminServiceHttpsSoap12Endpoint HTTP/1.1"/>
<property name="action" scope="axis2" value="urn:retrieveTenants"/>
<property name="Host" scope="axis2" value="localhost:9443"/>
<property name="Content-Type" scope="axis2" value="application/soap+xml"/>
</endpoint>
</call>
</inSequence>
<outSequence>
<call/>
</outSequence>
<faultSequence/>
</target>
<description/>
</proxy>
When I try the proxy I get the following error :
[2020-03-16 12:33:49,874] ERROR {org.apache.axis2.description.ClientUtils} - The system cannot infer the transport information from the /services/Proxy_RetrieveTenants.Proxy_RetrieveTenantsHttpSoap12Endpoint URL.
[2020-03-16 12:33:49,877] ERROR {org.apache.synapse.core.axis2.Axis2Sender} - Unexpected error during sending message out org.apache.axis2.AxisFault: The system cannot infer the transport information from the /services/Proxy_RetrieveTenants.Proxy_RetrieveTenantsHttpSoap12Endpoint URL.
I'm able to access the same method through SoapUI.
Please what would be wrong with my proxy?
Thks
Érico
Can you please modify the proxy service as follows and try this again.
<?xml version="1.0" encoding="UTF-8"?><proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy_RetrieveTenants" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
<target>
<inSequence>
<property name="POST_TO_URI" scope="axis2" value="true"/>
<property xmlns:ns="http://org.apache.synapse/xsd" expression="fn:concat('Basic ', base64Encode('admin:admin'))" name="Authorization" scope="transport"/>
<property name="ContentType" scope="axis2" value="text/xml"/>
<property name="SOAPAction" scope="transport" value="urn:retrieveTenants"/>
<payloadFactory media-type="xml">
<format>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ser="http://services.mgt.tenant.carbon.wso2.org">
<soap:Header/>
<soap:Body>
<ser:retrieveTenants/>
</soap:Body>
</soap:Envelope>
</format>
<args/>
</payloadFactory>
<call>
<endpoint>
<address format="soap12" uri="https://localhost:9443/services/TenantMgtAdminService.TenantMgtAdminServiceHttpsSoap12Endpoint"/>
</endpoint>
</call>
<respond/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
<description/>

WSO2 ESB with x-www-form-urlencoded messaage type service call

I have used following code for sending x-www-form-urlencoded message to backed server.
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="FormDataReceiver">
<http uri-template="http://www.eaipatterns.com/MessageEndpoint.html" method="post">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</http>
</endpoint>
Also used following API code.
<api xmlns="http://ws.apache.org/ns/synapse" name="FORM" context="/Service">
<resource methods="POST">
<inSequence>
<log level="full"></log>
<property name="name" value="Mark" scope="default" type="STRING"></property>
<property name="company" value="wso2" scope="default" type="STRING"></property>
<property name="country" value="US" scope="default" type="STRING"></property>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<root xmlns="">
<name>$1</name>
<company>$2</company>
<country>$3</country>
</root>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$ctx:name"></arg>
<arg evaluator="xml" expression="$ctx:company"></arg>
<arg evaluator="xml" expression="$ctx:country"></arg>
</args>
</payloadFactory>
<log level="full"></log>
<property name="messageType" value="application/x-www-form-urlencoded" scope="axis2" type="STRING"></property>
<property name="DISABLE_CHUNKING" value="true" scope="axis2" type="STRING"></property>
<call>
<endpoint key="FormDataReceiver"></endpoint>
</call>
<respond></respond>
</inSequence>
</resource>
</api>
But still that message send as rest call manner.
I want something like following message body into backed server. This example message should send through the message body. In here I have used WSO2 Given Example. I have added same wso2esb link for your further reference. wso2. Actually I need to send message XML={{my_xml_message_here}}. Please help me to continue this. Thanks lot.
name=Mark&company=wso2
There is missing Content-Type in header for this type of request. Need to add:
<header name="Content-Type" scope="transport" value="application/x-www-form-urlencoded"/>

How do I define a sequence to do a form post in WSO2 ESB?

I'm trying to define a sequence to do a HTTP post. I can't get my post variables to be sent in the request. I have
<sequence xmlns="http://ws.apache.org/ns/synapse" name="CDN" trace="enable">
<property name="messageType" value="application/x-www-form-urlencoded" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="http://posttestserver.com/post.php"/>
<property name="foo" value="bar" scope="axis2"/>
</endpoint>
</send>
</sequence>
You can use payload factory to set the post body. Use some thing like following according to your need
<payloadFactory>
<format>
<m0:getQuote xmlns:m0="http://services.samples">
<m0:request>
<m0:symbol>$1</m0:symbol>
</m0:request>
</m0:getQuote>
</format>
<args>
<arg expression="get-property('uri.var.symbol')"/>
</args>
</payloadFactory>
You have to change the following lines as you need
<arg expression="get-property('uri.var.symbol')"/>
Please look http://docs.wso2.org/display/ESB470/PayloadFactory+Mediator

wso2esb - REST API Failure doing XML to XML mapping

I am not able to make a call to REST backend from a browser[Rest client] using WSO2 ESB when trying the scenarios listed in Red.
Content Type and MessageFormatter already tried, am i doing something wrong or this is a limitation of REST API.
Source Code for Scenario A :
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="InvokeASservice" context="/invokeWS" hostname="10.203.101.76">
<resource methods="GET" uri-template="/{str1}">
<inSequence>
<log level="full" separator=",">
<property name="sequence" value="** Request Recieved**"/>
</log>
<property name="REST_URL_POSTFIX" expression="fn:concat('/get?id=',get-property('uri.var.str1'))" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="http://10.203.101.76:9765/services/PersonInfoService.PersonInfoServiceHttpEndpoint/"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full" separator=",">
<property name="sequence" value="** Message recieved**"/>
</log>
<property name="ContentType" value="application/xml" scope="axis2"/>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
Browser Error:
#####################Update#####################
Scenario A seems to work after changing the source
<api xmlns="http://ws.apache.org/ns/synapse" name="InvokeASservice" context="/invokeWS" hostname="10.203.101.76">
<resource methods="GET" uri-template="/{str1}">
<inSequence>
<log level="full" separator=",">
<property name="sequence" value="** Request Recieved**"/>
</log>
<property name="REST_URL_POSTFIX" expression="fn:concat('/get?id=',get-property('uri.var.str1'))" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="http://10.203.101.76:9765/services/PersonInfoService.PersonInfoServiceHttpEndpoint/"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
But, Scenario C is still a unsolved puzzle with the response coming in xml format.
tried adding the following to outSequence. Does not help
<outSequence>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<send/>
</outSequence>

Malformed Response - Invoking one ESB REST service from another

I am relatively new to WSO2 ESB,
Trying to invoke a REST Web service with GET parameter which is hosted on WSO2 ESB through another REST API.
This is a simple Web service(SampleREST) which replies with welcome messsage in XML format,
When i am invoking this service directly; i can see the correct response on browser, shown below
<Message xmlns="http://ws.apache.org/ns/synapse">WelcomeRanjan</Message>
Now i created another REST web service(InvokeSampleRest) which in turn invokes SampleREST web service with the parametrized GET,
the Invoke WebService Client returns me the XML response wrapped inside the mediator xml tag and other malformed tags, shown below
<mediate><<Message xmlns>"http://ws.apache.org/ns/synapse">WelcomeRanjan</Message></<Message xmlns></mediate>
Here is my Code for the SampleREST API
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="SampleREST" context="/SampleRest" hostname="10.203.245.47">
<resource methods="GET" uri-template="/{str1}">
<inSequence>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<payloadFactory>
<format>
<Message>$1</Message>
</format>
<args>
<arg expression="get-property('uri.var.str1')"/>
</args>
</payloadFactory>
<log level="full" separator=",">
<property name="sequence" value="*** Got Request ***"/>
</log>
<send/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
The code for the InvokeSampleREST code is as shown below( i am calling SampleREST service from here )
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="InvokeSampleREST" context="/InvokeSampleREST" hostname="10.203.245.47">
<resource methods="GET" uri-template="/{str1}">
<inSequence>
<log level="full" separator=","/>
<property name="REST_URL_POSTFIX" expression="fn:concat('/Welcome',get-property('uri.var.str1'))" scope="axis2" type="STRING"/>
<log level="full">
<property name="sequence" value="****Message Sent *** "/>
</log>
<send>
<endpoint>
<address uri="http://10.203.245.47:8280/SampleRest/"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full" separator=",">
<property name="out" value="** Ouput of Rest call ***"/>
</log>
<property name="ContentType" value="application/xml" scope="axis2" type="STRING"/>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
Appreciate any help.
Thanks,
Ranjan
Why are you using two APIs? You can design your flow, in a single API. I mean you can merge them together.
BTW, you need to set the contentType property in your backend API(ie:At SampleREST API)
Because, when you send back the response to "InvokeSampleREST" API, System doesnt know the content-type of the incoming response and try to handle it as text message.
Eg:
<api name="SampleREST" context="/SampleRest" hostname="localhost">
<resource methods="GET" uri-template="/{str1}">
<inSequence>
<header name="To" action="remove"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<payloadFactory>
<format>
<Message>$1</Message>
</format>
<args>
<arg expression="get-property('uri.var.str1')"/>
</args>
</payloadFactory>
<log level="full" separator=",">
<property name="sequence" value="*** Got Request ***"/>
</log>
<property name="Content-Type"
value="application/xml"
scope="transport"
type="STRING"/>
<send/>
</inSequence>
<faultSequence/>
</resource>
Try doing the following change at the InvokeSampleREST API.
At the outSequence, set the messageType as follows before the <send> mediator.
<property name="messageType" value="application/xml" scope="axis2"/>