views:

89

answers:

2

Hi all,

a simple and theoric question, the answer is probably one, but I would like to listen to some opinions and suggestions. I am in need of realizing a web services (in java) that will launch a time consuming process, which is going to parse some input file and do dome db staff.

What are the best approach to let the user knows that the whole process not only started, but came to an end, with parsing, updating db... ? Because I cannot hang the user waiting for the whole process to finish.

Note: the user is authenticated before starting the process.

EDIT: the web service is accessed not only via web browser, but clients can access it with any client built with the language they want, as long as they refer to the wsdl.

thanks

+3  A: 

I would give the user a token when they submit the data and have them poll (asynchronously) to another method with their token.

Then, in the 1st method I would add the data to a queue and have another process running on the server check that queue and perform the processing. Then update the token in the DB to notify the user that their job has completed.

I've worked on things like this before and found that firing off a long-running process on a system that is based on HTTP/web is a bad idea as the underlying systems can often time-out the calls to the webservice that are long-running.

Greg B
+1; why do you speak of "temptation"? What's the dark side of this approach?
chiccodoro
@chiccodoro Figure of speach, but you're right. It's the only way I'd do it!
Greg B
@Greg B - The last month I have been doing just that exact thing. +1
Jordan S. Jones
+3  A: 

For your scenario, You should implement asynchronous web services. With asynchronous web services, you have two options.

  1. (as someone already mentioned) you can do polling of the service to see if the process is done
  2. You can ask the server to callback

The first approach is easy to implement and it would work with many WS- libraries. However this comes with a drawback of your server having to waste bandwidth for client's polling requests. After all, it's polling. and most of the times, polling is a bad idea.

The latter one wouldn't be as straightforward as the former one to implement. And you I don't know if every JAX-WS library would support it. To support you, i did a quick google search and found this link.

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

That might help you a little.

Roshan Amadoru
+1 for mentioning callback. I would definitely recommend a callback design rather than polling. This only works of course when the client is *capable* of listening for a callback, for example if the client is a web app. If you are implementing callback then client should include callback details such as a URL.
Qwerky