WSO2 ESB - How to get and set cookies in WSDL calls in - cookies

I use WSO2 ESB and want to connect 2 web services together - on a timer pull data from one service and push it to another.
The problem is that one of the services authenticates callers with cookies. You first need to call a GetSession method with the username and password. The response to this call sets a cookie. Then with this cookie you make other calls.
I couldn't find anywhere in the documentation, how can I get a cookie from the result of one call and set it for a subsequent call. Is it at all achievable? If so - how?
Here is my sequence code:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="SampleName" trace="enable">
<payloadFactory media-type="xml">
<format>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetSessionWithCredentials xmlns="blabla">
<User>bla</User>
<Password>bla</Password>
</GetSessionWithCredentials>
</Body>
</Envelope>
</format>
</payloadFactory>
<call>
<endpoint key="conf:/Tracker"></endpoint>
</call>
<payloadFactory media-type="xml">
<format>
<GetTrackingList xmlns="blabla"></GetTrackingList>
</format>
</payloadFactory>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Cookie" expression="$trp:Cookie"></property>
<call>
<endpoint key="conf:/Tracker"></endpoint>
</call>
<log level="full"></log>
</sequence>
Thanks a lot

get Cookie header : <property name="Cookie" expression="$trp:Cookie"/>
If you want to get one cookie and it's value, use xpath expression with 'substring' for exemple
set cookie header with value JSESSIONID=1 : <property name="Cookie" value="JSESSIONID=1" scope="transport"/>

Related

How to implement sequential back-end calls in WSO2 EI/ESB?

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>

WSO2 API MANAGER - How to get endpoint with mediator

How can i get the endpoint production or sandbox url in customsequence?
Or how can i use two payload factories in the same customsequence using the endpoint saved in the api manager publisher?
For example, i have a custom sequence that made a call in the same endpoint, returning different data:
<payloadFactory description="" media-type="xml">
<format>
<ser:users xmlns:ser="http://service.test.com">
<arg0 xmlns="">$1</arg0>
</ser:users>
</format>
<args>
<arg value="user" />
</args>
</payloadFactory>
<call blocking="true">
<endpoint>
<address format="soap11" uri="http://url_soap?wsdl"/>
</endpoint>
</call>
<property expression="//return/text()" name="token" scope="default" type="STRING" xmlns:x="http://ws.wso2.org/dataservice"/>
Thanks
printscreen urls

WSO2 API Manager VFS write sequence ignores file parameters

In our project we are using WSO2 API Manager v 2.1.0. Our goal is to write a fault sequence that will log some information in custom logfile, example timestamp, name of the API etc. I was able to create a file and write to it, but it does not work as expected. Things I need to have is
Control the file name
Append content to file instead of overwriting it each time
This is the sequence I am using (simplified easier reading):
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="admin--FaultyAPI2:v1.0.0--Fault">
<clone continueParent="true">
<target>
<sequence>
<property xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://org.apache.synapse/xsd" name="destination" expression="get-property('To')"/>
<format>
{
"destination_host" : "$1"
}
</format>
<args>
<arg xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:ns3="http://org.apache.synapse/xsd" evaluator="xml" expression="get-property('destination')"/>
</args>
</payloadFactory>
<property name="transport.vfs.ReplyFileName" value="test.txt" scope="transport" type="STRING"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint>
<http uri-template="vfs:file:///home/install/out?transport.vfs.Append=true"/>
</endpoint>
</send>
</sequence>
</target>
</clone>
</sequence>
Following documentation I have used transport.vfs.ReplyFileName to specify the file name and ?transport.vfs.Append=true path parameter to tell it to append to file. The problem is that those two things are ignored.
First thing is that the file created is not test.txt but it is the endpoint URI that failed (the one I have setup in API Manager). So if I call /fault endpoint the file created is fault under location specified.
The second thing is that it is not appending to a file, but overwriting it each time the sequence is triggered. It is even worse! It creates actual path /home/install/out?transport.vfs.Append=true on file system and saves the file under this directory.
Those features seems to work under WSO ESB, but not API Manager. Any ideas anyone?
First of all, I have tested this in WSO2 EI, not in API Manager, but it seemed to me, the same problems you described appeared.
Controlling the filename
I've had some issues with this as well. The problem is that when you call the sequence through an API, the filename is not constructed based on the "transport.vfs.ReplyFileName" transport property, but based on the "REST_URL_POSTFIX" axis2 property. You can solve this by setting the "REST_URL_POSTFIX" property to the correct filename or by removing that property.
Appending the content
You are using an http endpoint, but you should use an address endpoint. In that case the path parameter will be recognized.
Example
I think your code should look more like this:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="admin--FaultyAPI2:v1.0.0--Fault" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<clone continueParent="true">
<target>
<sequence>
<payloadFactory media-type="json">
<format>
{
"destination_host" : "$1"
}
</format>
<args>
<arg evaluator="xml" expression="get-property('destination')" xmlns:ns3="http://org.apache.synapse/xsd" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"/>
</args>
</payloadFactory>
<property name="transport.vfs.ReplyFileName" scope="transport" type="STRING" value="test.txt"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="REST_URL_POSTFIX" action="remove" scope="axis2" />
<send>
<endpoint>
<address uri="vfs:file:///home/install/out?transport.vfs.Append=true"/>
</endpoint>
</send>
</sequence>
</target>
</clone>
</sequence>

SOAP messages are not sent using wso2 ESB REST API

I'm trying to expose SOAP backend as REST API using wso2 ESB. I'm using payload factory to send the soap body message, but it doesn't work.
This is my API resource in wso2 esb code :
<?xml version="1.0" encoding="UTF-8"?>
<api context="/akademik" name="SampleAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/students?symbol={symbol}">
<inSequence>
<log level="custom">
<property expression="$url:symbol" name="symbol"/>
</log>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:sem="http://semogabisa.te.net/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sem:sayHi>
<arg0>$1</arg0>
</sem:sayHi>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$url:symbol"/>
</args>
</payloadFactory>
<header scope="default">
<m:complexHeader xmlns:m="http://org.synapse.example">
<m:property key="Content-Type" value="application/xml"/>
</m:complexHeader>
</header>
<send>
<endpoint>
<address format="soap11" uri="http://localhost:8084/HelloWorld"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
Soap messages are not sent to the backend web service, it says null.
I've test the backend service with SOAPUI with same soap envelope format and it's working
I think you make some mistake on the header mediator. "HelloWorld" back end service didn't need the SOAP header based on your SOAP UI request. so remove the header mediator.
Select Synapse if you want to manipulate SOAP headers. Select Transport if you want to manipulate HTTP headers.
And it's seems back end is SOAP11, SOAP11 type is "text/xml". Your may need set this property.
<property name="messageType" value="text/xml" scope="axis2"/>
When you send message out from ESB, you need set property "messageType", then ESB will formatter the message that match back end required.
You may probably need this property, if you found ESB append some context to your back end URI when send message to back end.
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
Good Tips:
Please open your "synapse.transport.http.wire" as DEBUG, this will output every message in and out from ESB. This log will including HTTP header and body. After you got the wire log, you can compare wire log with your SOAPUI request, then find out which part is wrong.
https://docs.wso2.com/display/ESB481/Setting+Up+Logging

how to integrate wso2 DSS server and wso2 ESB

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