----- Original Message ----- From: <[EMAIL PROTECTED]>
To: "Tomcat Users List" <users@tomcat.apache.org>
Sent: Sunday, October 05, 2008 7:12 AM
Subject: Re: adding servlet definition to context on the fly :Tomcat 5.5


Hi Johnny,

Th code i used is basically the one you have in your last email...
I have an app running in privileged mode, and it has to add a servlet
definition on the fly to another app...so in my app i call a method and
pass the description of the other application as well as the servlet
definition i want to add:

Ram... listen I got it going, but not on TC 5... it works on TC 6.
Got to tell you I cant see how this ever worked on TC 4 or 5... the reason is the class loader structure doesnt lend itself to it. Webapps cant see the Container... so I'm wondering how you structured it without changing TC completely?
Possibly this code came out of an embedded app....

Anyway... the tip is, if you want to make your life relatively easy... move to TC 6 its has a flat classloader structure, so you only got to jump thru a few hoops... The code looks OK... but I'd suggest you add much more debugging points... so you can watch what its doing...

And then my first gut feel stands... I would much rather go for a specialized "invoker" type servlet with my own custom classloader... possibly too much work but a much better solution...

... if anyone knows how one can structure this sort of code in TC 4 or 5.... I'd luv to hear it.

But its an excellent idea... this idea of "Servlet Injection" or "Servlet Late Binding"... if there is anything out there that does this, I'd be keen to hear it. Otherwise its something we going to add to the our PAS.... drop a servlet in one TC, it runs in others idea...
... thanks nice idea....

Good Luck!

public void addServlet(WebAppConfiguration webApp, DeploymentDescriptor
descriptor) {
   org.apache.catalina.Server server = ServerFactory.getServer();
   String contextRoot = webApp.getContextRoot();
   Service[] services = server.findServices();
   Context context = null;
   String initParamName = descriptor.getInitParamName();
   String initParamValue = descriptor.getInitParamValue();
   String servletName = descriptor.getServletName();
   String servletClass = descriptor.getServletClass();

   for (int i = 0; i < services.length; i++) {
     Engine engine = (Engine) services[i].getContainer();
     Host host = (Host) engine.findChild(engine.getDefaultHost());
     context = (Context) host.findChild(contextRoot);
     if (context != null){
       break;
     }
   }
   if (context == null)
     return;
   StandardWrapper
   w = (StandardWrapper)context.createWrapper();
     w.setName(servletName);
     w.setServletName(servletName);

     w.setServletClass(servletClass);
     w.addInitParameter(initParamName, initParamValue);
     context.addChild(w);
     context.addServletMapping(descriptor.getUrlPattern(), servletName);
 }

---------------------------------------------------------------------------
HARBOR : http://www.kewlstuff.co.za/index.htm
The most powerful application server on earth.
The only real POJO Application Server.
See it in Action : http://www.kewlstuff.co.za/cd_tut_swf/whatisejb1.htm
---------------------------------------------------------------------------

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to