Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Invoking Service during application start up  RSS feed

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

In my current application, I'm calling a remote stored proc to get data that is stored in servlet context. My requirement is to call a WS instead of a stored proc to get the same data and store in the context. However, this call is happening during application start up. The service is ssl protected and the certificates are available only after JVM load. With my current design the call fails as the certs are not available.

Currently I'm calling the init class as a plugin in the struts-config. If I want to make the application initialization after JVM load, how to do that in struts? FYI.. the app is using struts 1.0

Your help is much appreciated.
 
Bartender
Posts: 9551
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!