WSRequest Asynchronous
Hi ,
I'm new to WSO2 Mashup Server.
and having troubles using WSRequest in a asynchronous way.
Below is the source:
//**********************************************************
function newsEventHandler()
{
if(wsrequest.readyState == 4)
{
// GetResponse
}
}
//**********************************************************
getNewsData.inputTypes = {"city" : "string"};
function getNewsData(city)
{
wsrequest.onreadystatechange = newsEventHandler;
wsrequest.open(options,rest_url,true);
var request = "";
wsrequest.send(request);
}
//***********************************************************
Any one has idea , how can I set "wsrequest.onreadystatechange" from external HTML page or handle eventHandler ?
Thanx
- Login or register to post comments
- Printer friendly version
- 366 reads











Two ways
Async requests from the Mashup Server should work well, but you need to be aware that each operation is essentially synchronous. A function is invoked on the request, and sends the response on completion of the function.
I have had luck with adding a loop containing system.wait() to an operation, and then setting a flag in the callback. That prevented operation from sending a response until the async calls within it were complete. In my case this allowed async calls (parallel calls to another service in my case) to be performed and consolidated into a single request-response operation.
I haven't tried the other flavor - where the request-response operation returns immediately, the callback changes some state on the server, and another operation can be used to poll for the state. However I believe it should work fine. (Most of my testing has been in ensuring stubs work asynchronously, which is a fairly comprehensive test.)
This is a pretty high-level answer - let me know if you'd benefit from more detail.
- Jonathan
Tnx
Tnx Jonathan , let me try it.