You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Henning Blohm <he...@gmail.com> on 2010/02/01 12:10:08 UTC
Embedding tomcat and bug in org.apache.catalina.startup.Catalina
Hi,
this is a question about embedding Tomcat into an application so that
it can still be configured using server.xml and web applications can be
added or removed programmatically.
I am using Tomcat 6.0.24.
The way I tried to make it work is by instantiating an instance of
Catalina, feeding in all necessary config and then adding
StandardContext instances as needed to a named host of a named service
etc. However there is a bug (I believe) in Catalina that made me
subclass Catalina and add a getServer() method:
public class MyCatalina extends Catalina {
public Server getServer() {
return this.server;
}
}
This is due to Catalina declaring its own protected member variable
"server" and a corresponding "setServer" method, while Catalina's super
class Embedded has a private member "server" and a "getServer" method,
so that Catalina sets its "service" member, but when asking, will return
super.server which is consistently null.
With that fix, the sample code below works as expected. Still: As I
ran into the problem noted above, I was wondering whether the whole
approach makes sense or whether there is a better way of using
server.xml while embedding tomcat but without using the Catalina class.
Thanks,
Henning
Sample code:
//
//
MyCatalina c = new MyCatalina();
File cf = new File("conf/server.xml");
c.setConfig(cf.getAbsolutePath());
c.setUseShutdownHook(false);
c.setAwait(false);
c.start();
// add a web app from a folder
File wc = new File("webapp");
StandardContext sc = (StandardContext)
c.createContext("/test",wc.getAbsolutePath());
File wd = new File("work");
if (!wd.exists()) {
wd.mkdir();
}
sc.setWorkDir(wd.getAbsolutePath());
// could be made configurable!
Container ch =
c.getServer().findService("Catalina").getContainer().findChild("localhost");
ch.addChild(sc);
Re: Embedding tomcat and bug in
org.apache.catalina.startup.Catalina
Posted by Henning Blohm <he...@gmail.com>.
ok, done.
Thanks,
henning
Am Mittwoch, den 03.02.2010, 13:08 +0300 schrieb Konstantin Kolinko:
> public class MyCatalina extends Catalina {
> > public Server getServer() {
> > return this.server;
> > }
> > }
> >
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Embedding tomcat and bug in org.apache.catalina.startup.Catalina
Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/2/1 Henning Blohm <he...@gmail.com>:
> Hi,
>
> this is a question about embedding Tomcat into an application so that
> it can still be configured using server.xml and web applications can be
> added or removed programmatically.
>
> I am using Tomcat 6.0.24.
>
> The way I tried to make it work is by instantiating an instance of
> Catalina, feeding in all necessary config and then adding
> StandardContext instances as needed to a named host of a named service
> etc. However there is a bug (I believe) in Catalina that made me
> subclass Catalina and add a getServer() method:
>
> public class MyCatalina extends Catalina {
> public Server getServer() {
> return this.server;
> }
> }
>
> This is due to Catalina declaring its own protected member variable
> "server" and a corresponding "setServer" method, while Catalina's super
> class Embedded has a private member "server" and a "getServer" method,
> so that Catalina sets its "service" member, but when asking, will return
> super.server which is consistently null.
>
I agree that it is a bug. Please add it to bugzilla.
You can include a link to your message,
http://marc.info/?l=tomcat-user&m=126502245412565&w=2
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org