• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Default methods executed by Jetty/Tomcat while loading/reloading the .war

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have created a dynamic web Application for RESTful web Service using JAX-RS Jersey implementation and deployed as a .war file in a container ( works fine in both Tomcat and Jetty)
Next, the other requirement is when the web container loads the .war, I need one method to be called ( to check the location of 'myTemp' folder for the files in the same host machine and copy the files from within the .war file to the folder 'myTemp')

So, just wanted to know if there is a way where Tomcat or Jetty executes some method on its own while loading/reloading the .war file OR any out of the box support provided by the container?

Please help.

Regards,
FK
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ServletContextListener
 
Faraz Ka
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear. I tried ServletContextListener and it worked for me for Tomcat.
Not sure if the same logic can be applied for Jetty. Please confirm if it can be used with Jetty as well.

Thanks again.
Faraz
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The ServletContextListener is a J2EE standard service that is employed whenever a webapp goes up or down. So for Jetty not to act just like Tomcat, Jetty would have to update the WAR without stopping it. Which is a questionable thing to do.

Beyond that, if you are creating files within the WAR, you are violating the J2EE standards and playing with fire. DON'T DO IT. Yes, I know it works in a lot of different versions and brands of servers when certain options are in effect. But just because you can do something, doesn't mean it's safe to do if the standard doesn't support it. And this is very definitely unsafe. I think in fact, you're trying to kludge around that very lack of safety.

You would be far better off if you designated a directory that's totally external to both your war and the webapp server itself to hold mutable files in.
 
Faraz Ka
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim for the valuable information.
What I am trying out is as follows

In my Dynamic Web Application I am creating a folder and place some files ( set of xmls and .ini files) and then export the web Application as a war file to be run on Jetty.
When its getting loaded in Jetty, the ServletContextListener ( through some custom code) will push these files ( xml and .ini) to some other location in the main OS directory ( lets say C:\Users\Administrator) from where it is picked by other agent ( REST in my case)

Please suggest if you still see challenge in this design/implementation.

Regards,
Faraz
 
Tim Holloway
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds good to me. It's what I would do when I wasn't using an OS installer to deploy my WARS.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic