Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if a web service has started

I have the following scenario:

  • There is a web service hosted on jBoss.
  • The web service is used by a java application.

Now the usual startup scenario is :

  • jBoss starts and loads the web app.
  • The application is then started and it uses the web service.

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.

like image 546
abhinav pandey Avatar asked Jan 21 '26 04:01

abhinav pandey


2 Answers

"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.

like image 195
icza Avatar answered Jan 22 '26 18:01

icza


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.

like image 21
Steve C Avatar answered Jan 22 '26 17:01

Steve C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!