Are your application and web service deployed in the same container? Perhaps it is time to reconsider your deployment strategy. A web service should "always" be available (at least in the eyes of its dependencies).
I don't think Struts has any features that one could use to implement the desired function. However, Struts is built on top of the Java Servlet Specification, so one could use the functionality found in that API. It provides classes to listen for servlet lifecycle events
, but unfortunately, the ServletContextListener
will only get called when a servlet context initialization begins. There is no way that I can see to be informed when the initialization process is complete.
One could use a ServletContextListener to create an executor
to schedule a task to read from the web service. This is not an ideal solution because you would need to figure out a reasonable delay for the web service to come up, but your delay cannot be so long that a user would be able to access the application before it is initialized.
Another way one could use servlet lifecycle events is to create a HttpSessionListener
which would be activated when someone logs in. Of course, you'd only want to know about the first login to initialize the application.
Another option would be to use lazy initialization. The first time someone accesses a feature in your application that requires the data from the web service, it would be fetched from the web service and cached.