• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Aync Callback Web Service Client using Dispatch API

 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have written Aync Callback Web Service Client using Dispatch API (below shown is the code).
I want to know whether I have coded it correctly .


Output is

4 - Asynchronous with Future Start: Sun Nov 24 19:42:42 IST 2013
4 - Asynchronous with Future End: Sun Nov 24 19:42:42 IST 2013
Async Source Payload Response = <ns2:addResponse xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://arith/"><return>31</return></ns2:addResponse>
- 4.1 simulating async work
4 - Asynchronous request with Future respondet at: Sun Nov 24 19:42:43 IST 2013 with Response


Thanks
Abhay Agarwal
 
Himai Minh
Ranch Hand
Posts: 1360
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your server code with @WebServiceProvider or @WebService?
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Server code is with @WebService annotation

 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2533
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abhay Agarwal

Your code looks good to me.

Regards,
Frits
 
Himai Minh
Ranch Hand
Posts: 1360
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing is we need to make sure file contains a valid xml file; otherwise sourceToXMLString method cannot convert Source result cannot be transformed into xmlResult.
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frits

Thanks for the confirmation.

I was reading JAX-WS 2.2 JSR Specification [ Maintain Release May 13, 2011] and found below mentioned code samples for Dispatch API.
4.3.5.1 Synchronous, Payload-Oriented
4.3.5.2 Synchronous, Message-Oriented
4.3.5.3 Synchronous, Payload-Oriented With JAXB Objects
4.3.5.4 Asynchronous, Polling, Message-Oriented
4.3.5.5 Asynchronous, Callback, Payload-Oriented


So I just thought of writing a working example for each of these scenario/combination.
I wrote for all but was not sure about this Async Callback combination code. So I posted my query on coderanch.

Thanks
Abhay Agarwal


 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Himai

I agree with you.

Thanks
Abhay
 
a sarkar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhay,
Why do you need to poll (while (!f.isDone())) if you've configured a callback handler? The main thread shouldn't care whether the server has responded or not because that defeats the purpose of asynchrony. Seems like a mix of both request-and-poll and request-and-register async variations.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2533
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a sarkar wrote:Abhay,
Why do you need to poll (while (!f.isDone())) if you've configured a callback handler? The main thread shouldn't care whether the server has responded or not because that defeats the purpose of asynchrony. Seems like a mix of both request-and-poll and request-and-register async variations.

Yes, you are right it is a mix of callback and polling (I overlooked that). You don't have to call (!f.isDone()), but f.get() to get the result from the async callback handler.
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I do not do that , my code in Async Handler do not get called.
So How I achieve same functionality without f.isDone condition ?

~ abhay
 
Himai Minh
Ranch Hand
Posts: 1360
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not see the main difference between the callback and polling mechanisms.
It seems to me that callback uses a handler to check the status of the response. But polling does not use a handler to check the status. In polling, the client gets the response directly and the client checks if the response is complete or not.
Correct me if I am wrong.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2533
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhay Agarwal wrote:If I do not do that , my code in Async Handler do not get called.
So How I achieve same functionality without f.isDone condition ?
~ abhay

Just changing your code slightly (and to show you that the Handler is called)


Gives the result of:
Asynchronous call Starts: Mon Nov 25 21:53:09 CET 2013
Client continues other work
...AsyncHandler called
Client decides to check the result Mon Nov 25 21:53:18 CET 2013 with Response
<ns2:addResponse xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://arith/"><return>25</return></ns2:addResponse>
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting the code. Thanks for all the help.

~abhay
 
Afra Tamam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your server code?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2533
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Afra Tamam wrote:What is your server code?

Hi Afra Tamam,

Welcome to Javaranch!

You can find the code of the MathService and I_MathService in the beginning of this thread.
 
a sarkar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himai Minh wrote:I do not see the main difference between the callback and polling mechanisms.
It seems to me that callback uses a handler to check the status of the response. But polling does not use a handler to check the status. In polling, the client gets the response directly and the client checks if the response is complete or not.

I don't think that's technically correct, there's a critical difference b/w the 2. The callback mechanism does not "use a handler to check the status of the response". The server calls the registered handler when it's done processing. I believe it's an example of Observer design pattern and is most common way of async processing; AJAX does it, Swing does it. On the other hand, in the polling mechanism, the client constantly bugs the server for status, preferably in a separate thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic