I'm trying to implement service chaining using Integration-studio 7.0.0
For.eg
Service 1(GET) - getCityById/{cityId}
response=> {"cityName":"Mumbai"}
Service 2(POST) - getStateByCityName
(it accepts above cityName inside body)
response=> {"stateName":"Maharashtra"}
Service 3(GET) - getCountryByStateName/{stateName}
response=> {"countryName":"India"}
Service 1 returns me response as {"cityName":"Mumbai"}.
I set that response inside the payload and call service 2.
But service 2 doesn't get called.
Kindly let me know,how should i proceed further
Thanks for ur help in advance!
Below is the code
<?xml version="1.0" encoding="UTF-8"?>
<api context="/country1" name="CountryDetails" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<call>
<endpoint key="CITY"/>
</call>
<payloadFactory media-type="json">
<format>{"cityName":"$1"}</format>
<args>
<arg evaluator="json" expression="$.cityName"/>
</args>
</payloadFactory>
<call>
<endpoint key="StateAPI"/>
</call>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Related
I want to implement sequential back-end calls in WSO2 Integration Studio.
After the first back-end call, I want to send a few fields from the response from the first back-end call to the second back-end call.
I tried using payload factory mediator inside a for-each loop after the http back-end call, but it is giving only last object.
Any other way to get it done?
You do not need a foreach loop here. You can implement a Service Chain pattern. You can create a Payload using the PayloadFactory mediator to use in second call which uses the values from the first call's response. Have a look at the following sample.
<api xmlns="http://ws.apache.org/ns/synapse" name="ServiceChaining" context="/servicechain">
<resource methods="GET">
<inSequence>
<call>
<endpoint>
<http uri-template="http://www.mocky.io/v2/5eb1cf1d320000749428f99e"/>
</endpoint>
</call>
<payloadFactory media-type="json">
<format>{"Hello" : {"test1" : "$1", "test3": "$2"}}</format>
<args>
<arg evaluator="json" expression="$.key1"/>
<arg evaluator="json" expression="$.key3"/>
</args>
</payloadFactory>
<call>
<endpoint>
<http method="POST" uri-template="http://www.mocky.io/v2/5185415ba171ea3a00704eed"/>
</endpoint>
</call>
<respond/>
</inSequence>
</resource>
</api>
I've just started looking at WSO2 enterprise integrator.
I'm currently stuck when I'm trying to create an API which calls a backend service which requires authentication.
I'm currently stuck trying to add a simple header which its suppose to send to the backend as it needs authentication to access it.
I'm using their eclipse tooling and my XML currently looks like this.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/one" name="singleRestApi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<header name="Authorization" scope="transport" value="Basic ZWNYGWRtaH42Q2xvdGRBZG1pbjmeMw=="/>
<send>
<endpoint key="repos"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
Currently following the integration tutorials: here
Any help or direction would be greatly appreciated.
You should try to put your Authorization in a property instead of an header (if you want to do a simple basic authentication)
<?xml version="1.0" encoding="UTF-8"?>
<api context="/one" name="singleRestApi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
<property name="Authorization" scope="transport" value="Basic ZWNYGWRtaH42Q2xvdGRBZG1pbjmeMw=="/>
<send>
<endpoint key="repos"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
the <property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
part is to remove the api context (after /one) when sending to your backend endpoint, if you need to keep it you can remove this line
I have a simple proxy in WSO2 ESB, and sometimes backend service
process request for a long time and I catch a timeout on the ESB. I dont want to increase timeout, I just want to handle this error in sequence and send error message back.
But when endpoint is timed out I cant send payloaded message back
ESB log:
ERROR - ClientUtils The system cannot infer the transport information from the /services/restEventReaderSoap URL.
ERROR - Axis2Sender Unexpected error during sending message out org.apache.axis2.AxisFault: The system cannot infer the transport information from the /services/restEventReaderSoap URL.
at org.apache.axis2.description.ClientUtils.inferOutTransport(ClientUtils.java:81)
at org.apache.synapse.core.axis2.DynamicAxisOperation$DynamicOperationClient.executeImpl(DynamicAxisOperation.java:115)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:482)`
Proxy config:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="restEventReaderSoap"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<send>
<endpoint>
<address uri="http://myserver/RestInformation" format="soap11">
<timeout>
<duration>1000</duration>
<responseAction>fault</responseAction>
</timeout>
</address>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence>
<payloadFactory media-type="xml">
<format>
<Send>
<id>$1</id>
</Send>
</format>
<args>
<arg value="Error"/>
</args>
</payloadFactory>
<send/>
</faultSequence>
</target>
</proxy>
Where is my error and what I have to do?
try adding the following in you fault handler :
<header action="remove" name="To" scope="default"/>
<property name="RESPONSE" scope="default" type="STRING" value="true"/>
Check that your service url is correctly pointing towards your wso2 server.
We have 2 rest APIs and have to edit and send the one rest API response as a request message to the another rest API.
Ex: First api response is
<?xml version="1.0"?>
<api>
<attribute_set_id>4</attribute_set_id>
<type_id>simple</type_id>
<sku>test_dress</sku>
</api>
Now we have to edit that response as
<?xml version="1.0"?>
<api>
<id>4</id>
<product_id>simple</product_id>
<sku>test_dress</sku>
</api>
and send that response as a request message to the another rest api.
Is it possible through WSO2 ESB and please provide any sample to work for above scenario.
Please let me know if I need to give more details.
Thanks,
Geetha Gupta
Little sample you must customize to meet your needs :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="MyProxy"
transports="http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<!-- send current message to rest api 1 (sample with a dynamic value inside rest url) -->
<property name="uri.var.MyPath" value="mypath"/>
<call>
<endpoint>
<http method="POST" uri-template="http://myhost/{uri.var.MyPath}/restapi1"/>
</endpoint>
</call>
<!-- here come the response from rest api 1 : transform this response -->
<payloadFactory media-type="xml">
<format>
<api>
<id>$1</id>
<product_id>$2</product_id>
<sku>$3</sku>
</api>
</format>
<args>
<arg evaluator="xml" expression="//api/attribute_set_id/text()"/>
<arg evaluator="xml" expression="//api/type_id/text()"/>
<arg evaluator="xml" expression="//api/sku/text()"/>
</args>
</payloadFactory>
<!-- call rest api 2 -->
<call>
<endpoint>
<http method="POST" uri-template="http://myhost/{uri.var.MyPath}/restapi2"/>
</endpoint>
</call>
<!-- send back response from restapi2 -->
<send/>
</inSequence>
<outSequence/>
</target>
</proxy>
What you need is the XSLT mediator (https://docs.wso2.com/display/ESB460/XSLT+Mediator).
Refer http://architects.dzone.com/articles/xslt-mediator-tutorial for an example for this.
You can do it through following steps
Read response and assign the response parameters to some variables by using <proprty>
Set dynamic payload with these parameters by using <payloadFactory>
After you can call another rest using <send> mediator
My current scenario is that i have a web service exposed from data service which returns me email address of the user when i give it the name of the user. Now i want to use this web service in ESB and get the email id from this web service in a property and show it in console using LOG mediator.
What should i do now and how?
Sorry for this silly question but i am newest member of wso2 esb. So please help me on this.
Now ihave a response like:
<brs:getRecipientKeyResponse xmlns:brs="http://brs.carbon.wso2.org">
<brs:MailRecipient xsi:type="ax2338:MailRecipient" xmlns:ax2338="http://email.samples/xsd" xmlns:ax2337="http://email.samples/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ax2337:recipient>kevin</ax2337:recipient>
</brs:MailRecipient>
</brs:getRecipientKeyResponse>
Ihave to get the recipient element from this response and put this in payload. My complete sequence for this is:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="receiveSeq">
<log>
<property name="getRecipient" value="------------Trying to get data Fom BRS Response----------------------------"/>
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ax2337="http://email.samples/xsd" name="Recipient" expression="//ax2337:recipient"/>
</log>
<payloadFactory>
<format>
<p:GetEmailDetails xmlns:p="http://ws.wso2.org/dataservice">
<xs:name xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:name>
</p:GetEmailDetails>
</format>
<args>
<arg xmlns:ns="http://org.apache.synapse/xsd" xmlns:ax2337="http://email.samples/xsd" expression="//ax2337:recipient"/>
</args>
</payloadFactory>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="getName" expression="get-property('Recipient')"/>
</log>
<send receive="DBSeq">
<endpoint key="emailServiceEP"/>
</send>
</sequence>
<!--this part is not able to get data --->
<property xmlns:ns="http://org.apache.synapse/xsd" name="getName" expression="get-property('Recipient')"/>
u just use the the your wso2dss tryit service in that request side code copy into the payloadfactory insted of " ? " keep the $1 ,$2 ..like this and pass the argument below as per ur above order order is play a vital role for this response i think it will help for u
<payloadFactory>
<format>
<p:insert_emp_operation xmlns:p="http://ws.wso2.org/dataservice">
<xs:eno xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:eno>
<xs:ename xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:ename>
<xs:esal xmlns:xs="http://ws.wso2.org/dataservice">$3</xs:esal>
</p:insert_emp_operation>
</format>
<args>
<arg expression="get-property('eno')"/>
<arg expression="get-property('ename')"/>
<arg expression="get-property('esal')"/>
</args>
</payloadFactory>
<send receive="Error_Seq">
<endpoint>
<address uri="http://localhost:9764/services/emp_DataService/" format="soap11"/>
</endpoint>
</send>
Since you have the Dataservice is implemented, give that as endpoint url to your proxy which can be created in wso2esb. When you send request to your proxy,in the outsequence, you will receive the response of your dataservice. Just do a log with "level=full" you will see the full response. Use the property mediator and do an xpath to pick the value which you needed.
Sample conf:
<proxy name="StockQuoteProxy">
<target>
<endpoint>
<address uri="DS endpoint"/>
</endpoint>
<outSequence>
<log level="full">
<property name="email" expression="xpath from the email attribute in the rseponse"/>
</log>
<send/>
</outSequence>
</target>
</proxy>
Here is esb sample guide on how to create proxies;
http://docs.wso2.org/wiki/display/ESB460/Proxy+Service+Samples