abhinav pandey
abhinav pandey

Reputation: 584

How to know if a web service has started

I have the following scenario:

Now the usual startup scenario is :

Now the problem:

In case the Java application starts first, is there any way for it to know that the web service has started?

I thought of pinging the web service regularly but that is likely to have quiet some overhead. Any solution is welcome.

Upvotes: 3

Views: 462

Answers (3)

icza
icza

Reputation: 417612

"Pinging" the web service regularly is not a big overhead. Why would it be?

Just wait a little between retries. A common strategy is to increase the wait time between tries up to a maximum. E.g. try and if not ready, wait 1 sec, then try again and if still not ready, wait 2 sec, then 4 sec etc. up to like max 8 sec between retries.

Meanwhile display a message to the user like:

"Waiting for web service to start..."

Optionally including the number of attempts made so far like:

"Waiting for web service to start... (retrying #2)"

Also alternatively you can make a small, static text file available as part of of the webapp like "ping.txt" and try to get that as your test whether the app is ready and available, you don't have to call the webservice itself. It can also point to a Servlet in which case you can make sure the servlet container is also up (of course disable caching of this ping url).

Also as an another alternative if your webservice module has significant time to stand up, the target of the "ping" may be the wsdl document of the webservice. Most webservice frameworks provide a way to access/download the dynamically generated WSDL document of the webservice. If that URL responds and sends back the dynamic WSDL document, the wsdl module is also up.

Upvotes: 1

Yogesh
Yogesh

Reputation: 214

You can simply check logs from var/log/..../access.log eg. tail -f /var/log/apache2/access.log

Upvotes: -1

Steve C
Steve C

Reputation: 19445

You have to cater for connectivity problems in your client application at all times - not just startup, therefore there is no point in "pinging". This applies to any kind of remote connectivity solution.

When it's time to call the service just call it. If it's down the connection will fail and you can inform the user in an appropriate way. You must do this whether you ping or not, as the service may disappear between the last ping and your actual call.

The remote service could go up and down any number of times while the client is active.

Upvotes: 1

Related Questions