I am making REST calls to a web service hosted on a different server form my GWT client javascript whose response needs to be captured and rendered on UI . I do this via resty-gwt . But I am unable to capture that response at the instance when the javascript method is called from html which in turn invokes the rest call. Also, I want to make sure that if I invoke two calls from javascript one after the other (which in turn invoke rest calls) the second call is made only when first call is completed. Is there a way to achieve the same ?
1 Answers
I think there are 2 different problems in your question :
A) unable to capture that response
B) Create a sequence of calls
For A) you should give us more info, code snippet. Is your problem linked to CORS ?
For B) Here are my suggestions
If you are using 2 asynchronous calls there is no way to gaurantee that one will return before the second one. Nevertheless you can achieve some kind of synchronisation differently.
I see 2 options
1) Wait for the first call to return to launch the second one. It means sending the second call inside the onSuccess (and maybe also inside onFailure depending on your logic) of the first call.
This option is not optimal in terms of performance because you may have to wait unecessary time before sending the second request. It depends if you need some information coming from the answer of the first request to send the second one.
2) Send both calls independently. Then, inside the onSuccess method of each call save a boolean (ok1 and ok2). Inside the 2 onSuccess methods call the same method ex : afterBothSuccess()
inside this method check the value of ok1 and ok2
if (ok1 && ok2)
//here you are guaranteed that both your calls have returned with success

- 3,699
- 1
- 29
- 44
-
The problem is related to CORS as requests are being responded smoothly.I want to leave it to the user to make the next call but however block the second invocation unless first request is fulfilled. – Chhavi Gangwal Apr 23 '14 at 09:13
-
Sorry I do not understand your comment – Ronan Quillevere Apr 23 '14 at 09:37
-
My actual issue was to capture success and failure responses via jsni methods, which is now resolved by an alternate way :) Thanks for your suggestion BTW! – Chhavi Gangwal Jun 20 '14 at 13:13