• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Asynchronous Web service call

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am in a position to use Axis2 - Jax WS and create a web service which will be processing some records that might take a few secs. Now this web service call needs to be asynchronous as the client should not be waiting for me to process and they need to keep sending me requests.

In this case, what should I do ? Should I have some extra binding information in the wsdl to make is asynchronous support ?
Or since its a https service on a WAS server, can I still access the service asynchronously using any client side logic without making any change in the wsdl and the server side. If the latter can be done, does that mean, by default my simple web service can be called asynchronously ?

Also, am little confused here over synchronous/ asynchronous and sequential/parallel processing of my records.

Please guide me
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not divide the problem?

1. A call to start processing a set of records - reply is "ok" or "unable to start"

2. A call to see if processing is complete - reply is "yes" or "no" or "error prevented processing"

3. A call to get the results

Bill
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sathiesh
As you know in J2ee environment asynchronous processing can be achieved using a Queue in the middle.
When a webservice needs to be asynchronous it is SOAP over JMS instead of SOAP over http/https.
The endpoint url looks different when it is a asynchronous webservice . It has information like the queue factory embeded in it.
You can refer the below link to do this .
http://www.ibm.com/developerworks/websphere/library/tutorials/0903_adams/index.html

Alternatively you can code a regular webservice (SOAP over Https) and have the webservice just post the message on to queue.
The business logic can then reside in the MDB.
Though this approach is not truely synchronous , the time the client has to wait for a response is very negligible as the webservice does nothing more than just post the message on to a queue. The webservice can just return a empty respose if you decide to have generic faults like service unavailable.
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
If you are using JAX-WS and wsimport to generate the client artifacts, you can generate client artifacts that will contain asynchronous versions (as well as regular, synchronous, version) of operation stubs using a binding file.
The binding file is to look like this:


As you can see, you need to specify the following things in the binding file:
1. The location of the WSDL for which you are creating client artifacts.
2. The port type which contain the operation(s) you want to be able to invoke asynchronously.
3. The operation(s) you want to be able to invoke asynchronously.

As you generate client artifacts with wsimport, you add the -b option and the path to the binding file.
For a complete example, see section 4.8 of my SCDJWS 5 Study Notes available here: http://www.slideshare.net/krizsan/scdjws-5-study-notes-3085287

Finally, I want to stress that the web service in itself does not change - it remains synchronous. However, the client thread sending requests to the web service will be able to proceed doing other things immediately after having sent the request and process the response of the request at some later point in time when it is available.
Best wishes!
 
Sathiesh Kumar Vs
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys..

I cannot go with dividing into separate calls as again, that would increase the service hits for me
Also configuring MDB is little difficult because I need to configure in all the servers i Use

Ivan, your suggestion would suit me.
I am using RAD to create this web service. Which again uses ws:import i guess.
Here, how would I link this external binding file to WSDL,so that my server stubs will have the Async methods generated.
I tried out looking over the web, but couldn't find the exact way of doing it.
Can you please advice me, how will import this external binding file to my WSDL ?

Guys, Again thanks for your replies
 
Ranch Hand
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satiesh,
You should see this http://today.java.net/pub/a/today/2006/09/19/asynchronous-jax-ws-web-services.html, which I think suits very much to your requirement.

@Lingan:

When a webservice needs to be asynchronous it is SOAP over JMS instead of SOAP over http/https.


Not anymore in JAX-WS
 
Sathiesh Kumar Vs
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

As I mentioned earlier, I am using RAD7 to generate these stubs.. Not sure if that is the problem. When I am generating server stubs with the external binding <enableAsyncMapping>true</enableAsyncMapping> stubs are creating generated but when publishing the service I am getting an exception :

com.ibm.ws.exception.RuntimeWarning: javax.xml.ws.WebServiceException: The server-side SEI com.americanexpress.ws.jupiter.postitinerary.PostItineraryService contains the asynchronous method postItineraryAsync. Asynchronous methods are not allowed for server-side artifacts.

Can anyone suggest what s the problem ?
Also, like using wsimport for client stubs, how can I generate server stubs ? Please help.
 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you mentioned that you are using Axis2, have you checked their documentation on asynchronous calls. Does this suit you ?
 
Sathiesh Kumar Vs
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Raja,

The approaches in the document suit me very well..

When I am trying to use Client side asynchrony, I am having problems in creating the ServiceClient as at runtime, i am getting many NoClassDefFound and ClassCastExceptions which are because of missing proper runtime dependent jars..

When I tried the server side asynchrony, The service is not publishing saying that the server side artifacts cannot have asynchronous methods
 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satish,

May be I have missed reading this point earlier, but are you looking for client side asynchrony or serverside asynchrony. Personally I have not tried serverside asynchrony, but in your case, if you are looking for client side asynchrony, I guess, you can easy have the missing jar files. It would have mentioned about the class it was looking for in the exception. As I mentioned, please try to look into AXIS 2 documentation, for better understanding.
 
Sathiesh Kumar Vs
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried my possibilities at server side and i couldn't do it... For client side asynchrony, I followed the example given at

http://www.developer.com/java/web/article.php/3863416/Using-Axis2-and-Java-for-Asynchronous-Web-Service-Invocation-on-the-Client-Side.htm

which uses ServiceClient API, Now am not getting exceptions as i downloaded the jars and added..

Now, when I call the service, I am able get the logs only printed on the client side, but not the code written in my service impl or call back handler...
Any idea of what would be the problem ?
 
Sathiesh Kumar Vs
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys,

Got the issue resolved.. Thanks for your support
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sathiesh,

can you post what the resolution was? I am having a similar issue.

thanks,
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Sathiesh Kumar Vs

Can you post simple client and server classes. My requirement is,

I want to trigger the threads(in JAVA proj. exposed as web-service) when Request is made. That request should trigger threads and no need of response to client. I mean, he click's the button from UI(JSP) , the request triggers threads, Response is a simple message from Jquery. In Java(back-end) the threads should do all works. For this I need Asynchronous Web service call.

Thanks:
Ramakrishna K.C
 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic