2

I have 2 war files in my webapps folder of Tomcat and i want to hit a url after all war file deployed fully in tomcat server means(When it shows server is started in some millisecond)

when it shows server is started,now its time to hit a url automatically.when i am hitting that url manually it is working,but i want some automatic way either by server is going to do that automatically or from spring.

Thanks.

ha9u63a7
  • 6,233
  • 16
  • 73
  • 108
Gyana
  • 21
  • 3
  • 1
    Who should "hit the url"? You want the server to send a HTTP request to itself? Why? What are you trying to achieve? – JB Nizet Jun 29 '15 at 10:51
  • actually my 2 war files are independently deploying but 2nd war file has to be deployed properly after that it should hit my first war file to start processing, in that case 1st war file remain idle until hit. but I don't want to wait for user, i want to process that as soon as tomcat server started. – Gyana Jun 29 '15 at 11:08
  • So, use a ServletContextListener, or a Spring ApplicationListener, and do what you want from there. You don't need a request to start doing things in an application. – JB Nizet Jun 29 '15 at 11:11
  • I have used Spring ApplicationListener in 2nd war file to hit 1st war. but when I started the server my 1st war file is getting deployed. but 2nd is still in deploying mode , and It not responding like after 10 min server time out it is showing. when I went for debugging it is ok up to hit the url. but when it is in that line of hitting url,control is not coming. – Gyana Jun 29 '15 at 12:45

3 Answers3

0

So from the tags i assume you use spring... So hook to spring startup events, example is here How to add a hook to the application context initialization event?

Community
  • 1
  • 1
Nadir
  • 1,369
  • 1
  • 15
  • 28
  • I think this spring applicationlistener will not work for me. because it should call after server start up, i have embedded this applicationlistner in 2nd war and add that bean with application-context.xml .but this class is calling in between deploying of 1st and 2nd war. i want that url hit after complete **server-start-up** – Gyana Jun 29 '15 at 13:02
  • There are two things - server start up, and application deployment, and I think you're confusing those two. Server may start up and not deploy any application. You want to hit the url after all your apps are deployed. In that case you have to search for server specific solutions that allow you to do some ordered deployment. Set the order, and use the ApplicationListener only on the last app that will be deployed. – Nadir Jun 30 '15 at 05:22
0

You can use a LifeCycleListener that tells you if Tomcat is completly started. But anyways, if it has started doesnt mean that your apps did start too.

Stefan
  • 12,108
  • 5
  • 47
  • 66
  • I have tried with LifeCycleListner but it is not working with this reference http://stackoverflow.com/questions/22390818/callback-on-tomcat-server-startup-complete – Gyana Jun 29 '15 at 12:06
0

So here you have a couple of options.

The simplest one of to use the LifecycleListener that listens for the applicationReady event and then starts a thread that polls the other app until the other app is ready and it retries as long as it gets http errors when calls the other app. But you should sleep (for example 1 sec) between the calls, otherwise you will produce so much load that the other app will have a hard time to finish its deployment. After the http call to the other app was a success the polling thread finishes.

Another solution is to use things an event server like rabbitMQ and you send a message like "I'm ready" to a queue and the other app fetches the mesage when it's ready. But you need a persistet queue, so the message is not lost when the other app is not there yet and the queue needs to be cleared afterwards etc.

I think I'd try the thread polling first.

Patrick Cornelissen
  • 7,968
  • 6
  • 48
  • 70