• 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

starting a webapp from another webapp

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks.

Is there some internal tomcat API that allows starting a webapp from another webapp in the same tomcat instance, or is the only way to accomplish this is by sending HTTP requests to the tomcat manager?

Thanks!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While there is sure to be an internal API for this (which would be used by the Tomcat Manager as well), standard web apps are not allowed access to Tomcat's internal classes. Setting the context to be privileged may help with that, but I'm not sure if it's sufficient.

Check the TomcatFaq for links to articles about embedding Tomcat - those approaches would use the APIs you'd need for this.
 
Jeff Harbinson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:While there is sure to be an internal API for this (which would be used by the Tomcat Manager as well), standard web apps are not allowed access to Tomcat's internal classes. Setting the context to be privileged may help with that, but I'm not sure if it's sufficient.



Thanks for the info.

If I were to make my app privileged, how would I go about using the management servlet(s)?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You wouldn't use the servlet (that's only for HTTP access) - you'd need to figure out the actual API calls (maybe starting with the embedding code I mentioned).

But the easiest way may indeed be to make an URLConnection from your web app to the Manager servlet.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeff Harbinson wrote:Hi folks.

Is there some internal tomcat API that allows starting a webapp from another webapp in the same tomcat instance, or is the only way to accomplish this is by sending HTTP requests to the tomcat manager?

Thanks!



That's quite an unusual request. Could you explain what you are trying to achieve - there may be a better way?

Regards
 
Saloon Keeper
Posts: 27762
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
There is already a webapp to do that. It's the Tomcat manager/admin webapp(s). And it's what you're invoking when you use the HTTP-based control interface.

Then again, you can probably use JMX. JSR-88 handles deployment, and I think also start/stop, and there's another JSR for general control, although I forget its number.
 
Jeff Harbinson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:There is already a webapp to do that. It's the Tomcat manager/admin webapp(s). And it's what you're invoking when you use the HTTP-based control interface.

Then again, you can probably use JMX. JSR-88 handles deployment, and I think also start/stop, and there's another JSR for general control, although I forget its number.



Ooh - JMX may be a good option. I wasn't aware that tomcat supported it.

To answer a previous question as to why I want to do this - I want to monitor another server. If that other server stops responding, I then want to start the local webapp.
 
Tim Holloway
Saloon Keeper
Posts: 27762
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

Jeff Harbinson wrote:

Tim Holloway wrote:There is already a webapp to do that. It's the Tomcat manager/admin webapp(s). And it's what you're invoking when you use the HTTP-based control interface.

Then again, you can probably use JMX. JSR-88 handles deployment, and I think also start/stop, and there's another JSR for general control, although I forget its number.



Ooh - JMX may be a good option. I wasn't aware that tomcat supported it.

To answer a previous question as to why I want to do this - I want to monitor another server. If that other server stops responding, I then want to start the local webapp.



You're probably better off just running a cluster unless you're really tight for resources. It takes time to launch a webapp. A cluster can fail over much faster.
 
Jeff Harbinson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:

You're probably better off just running a cluster unless you're really tight for resources. It takes time to launch a webapp. A cluster can fail over much faster.



For various reasons that I won't enumerate here, that's not an option. Our failover solution needs to be a warm spare.
 
Jeff Harbinson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:You wouldn't use the servlet (that's only for HTTP access) - you'd need to figure out the actual API calls (maybe starting with the embedding code I mentioned).

But the easiest way may indeed be to make an URLConnection from your web app to the Manager servlet.



For those of you familiar w/ these internal tomcat classes -

I'm looking at the Embedded class:
http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/catalina/startup/Embedded.html
Is there a more straight forward way to start a webapp, as opposed to the multiple steps mentioned in the javadoc? Ideally, I'd just be able to refer to a context already defined in server.xml and just ask tomcat to start it...

Thanks.
 
Tim Holloway
Saloon Keeper
Posts: 27762
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

Jeff Harbinson wrote:

Ulf Dittmer wrote:You wouldn't use the servlet (that's only for HTTP access) - you'd need to figure out the actual API calls (maybe starting with the embedding code I mentioned).

But the easiest way may indeed be to make an URLConnection from your web app to the Manager servlet.



For those of you familiar w/ these internal tomcat classes -

I'm looking at the Embedded class:
http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/catalina/startup/Embedded.html
Is there a more straight forward way to start a webapp, as opposed to the multiple steps mentioned in the javadoc? Ideally, I'd just be able to refer to a context already defined in server.xml and just ask tomcat to start it...

Thanks.



You shouldn't be placing application contexts in server.xml. That's been deprecated since about 1985. One reason being that the tomcat control can't manage individual webapps in server.xml. When server.xml gets modified, the entire Tomcat server has to be restarted.
 
Jeff Harbinson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:

Jeff Harbinson wrote:

Ulf Dittmer wrote:You wouldn't use the servlet (that's only for HTTP access) - you'd need to figure out the actual API calls (maybe starting with the embedding code I mentioned).

But the easiest way may indeed be to make an URLConnection from your web app to the Manager servlet.



For those of you familiar w/ these internal tomcat classes -

I'm looking at the Embedded class:
http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/catalina/startup/Embedded.html
Is there a more straight forward way to start a webapp, as opposed to the multiple steps mentioned in the javadoc? Ideally, I'd just be able to refer to a context already defined in server.xml and just ask tomcat to start it...

Thanks.



You shouldn't be placing application contexts in server.xml. That's been deprecated since about 1985. One reason being that the tomcat control can't manage individual webapps in server.xml. When server.xml gets modified, the entire Tomcat server has to be restarted.



Yes; I am aware of this. I should've said context.xml (old habits die hard).

Regardless - is there an easier way to start a context than using Embedded?
 
Tim Holloway
Saloon Keeper
Posts: 27762
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
Embedded doesn't start a Context, it starts a whole (embedded) Tomcat server. It's what JBoss uses to launch its Tomcat component, for example. It's nothing but a JavaBean designed to permit instantiating and controlling Tomcat from a container application. And that application shouldn't itself be a webapp. Plus, starting an entire Tomcat will keep you serverless for an even longer interval than starting a webapp.

JMX appears to be your best bet. Either directly or via the HTTP JMX proxy.

 
Jeff Harbinson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:

JMX appears to be your best bet. Either directly or via the HTTP JMX proxy.



I'm exploring the JMX option - seems like it will work (I've been able to start/stop contexts through jconsole).

Can somebody explain how I find the full class names of the MBeans? Thanks!
 
Tim Holloway
Saloon Keeper
Posts: 27762
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 class name of an MBean is typically the same name as the class that it controls with "MBean" appended to the classname. However, the ObjecName that you see in jconsole should be all you need. For example: "Catalina:type=Manager,path=/servlets-examples,host=localhost"
 
Jeff Harbinson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:The class name of an MBean is typically the same name as the class that it controls with "MBean" appended to the classname. However, the ObjecName that you see in jconsole should be all you need. For example: "Catalina:type=Manager,path=/servlets-examples,host=localhost"



Thanks. I'll have to do some reading - my JMX experience is very, very limited. And a couple years ago.
 
Jeff Harbinson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:The class name of an MBean is typically the same name as the class that it controls with "MBean" appended to the classname. However, the ObjecName that you see in jconsole should be all you need. For example: "Catalina:type=Manager,path=/servlets-examples,host=localhost"



Just FYI - I've successfully written an app that starts/stops tomcat contexts via JMX. Thanks everybody!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic