tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ram.srihar...@agileitinc.com
Subject Re: adding servlet definition to context on the fly :Tomcat 5.5
Date Sun, 05 Oct 2008 05:12:11 GMT
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:

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);
  }


>
> ----- Original Message -----
> From: "Johnny Kewl" <john@kewlstuff.co.za>
> To: "Tomcat Users List" <users@tomcat.apache.org>
> Sent: Sunday, October 05, 2008 5:40 AM
> Subject: Re: adding servlet definition to context on the fly :Tomcat 5.5
>
>
>>
>> ----- Original Message -----
>> From: "Martin Gainty" <mgainty@hotmail.com>
>> To: "Tomcat Users List" <users@tomcat.apache.org>
>> Sent: Saturday, October 04, 2008 11:39 PM
>> Subject: RE: adding servlet definition to context on the fly :Tomcat 5.5
>>
>>
>>
>> doctor john
>>
>> to followup with the addChild method and if an exception is thrown and
>> you
>> determine your container doesnt support child containers..what then?
>>
>> your diagnosis doctor..
>>
>> Martin
>> ---------------------------------------
>> I dont know the history... too young to remember TC 4 ;)
>> He probably lost his call when filters or something like that was
>> introduced... but heres the coders explanation, perhaps it makes sense
>> to
>> you...
>> I just looked at what he was calling before... and its gone ;)
>> addChild is still functional in container... but in wrapper its an
>> exception... some history here somewhere... risk one takes if they work
>> outside the intended API... unless that is in the servlet spec... doubt
>> it...
>>
>> /**
>> * A <b>Wrapper</b> is a Container that represents an individual servlet
>> * definition from the deployment descriptor of the web application.  It
>> * provides a convenient mechanism to use Interceptors that see every
>> single
>> * request to the servlet represented by this definition.
>> * <p>
>> * Implementations of Wrapper are responsible for managing the servlet
>> life
>> * cycle for their underlying servlet class, including calling init() and
>> * destroy() at appropriate times, as well as respecting the existence of
>> * the SingleThreadModel declaration on the servlet class itself.
>> * <p>
>> * The parent Container attached to a Wrapper will generally be an
>> * implementation of Context, representing the servlet context (and
>> * therefore the web application) within which this servlet executes.
>> * <p>
>> * Child Containers are not allowed on Wrapper implementations, so the
>> * <code>addChild()</code> method should throw an
>> * <code>IllegalArgumentException</code>.
>> *
>> * @author Craig R. McClanahan
>> * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar.,
>> 24
>> oct. 2006) $
>> */
>>
>> --------------------.
>
> A little more homework... would actuall be much easier if we saw the
> code...
> but the only thing that I can find in TC that is doing more or less what
> he
> "may" be doing is in the invoker servlet...
>
> looks like this....
>                     wrapper = context.createWrapper();
>                     wrapper.setName(name);
>                     wrapper.setLoadOnStartup(1);
>                     wrapper.setServletClass(servletClass);
>                     context.addChild(wrapper);
>                     context.addServletMapping(pattern, name);
>
> So if is calling  addChild on StandardWrapper... he has no chance..
> If his calls look something like the above... then its possible that
> invoker
> servlet is active on TC 4 and its not on TC 5...
> Possibly he has to turn on invoker servlet?
>
> In either case... its open heart surgery that I dont even see in embedded
> TC....
>
> Ram if you dont come right... post your code can we can see for sure what
> you doing... we as curious as hell ;)
>
> ---------------------------------------------------------------------------
> 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: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>



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


Mime
View raw message