Re: adding servlet definition to context on the fly :Tomcat 5.5
[EMAIL PROTECTED] wrote: Hi, I had written some code to dynamically add a servlet to a context in a deployed applicaiton in Tomcat 4.1. This code basically uses the catalina loader to obtain the server-engine-host-and context, and invokes the addChild method after configuring a StandardWwrapper to represent the servlet I am adding. This all works fine in Tomcat4.1 and I am able to access the servlet through the right url immediately, without having to restart Tomcat. However, I tried the same code in Tomcat 5.5 and it does not work. It does not throw any errors, but simply does not recognize the url pattern once i actually try to invoke the new servlet. I was wondering if anyone had tried this before, and if so if they have any suggestions as to why this does not work in Tomcat 5.5? Are you calling addServletMapping() on the context after you have added the wrapper? It looks like this was unnecessary in 4.1.x but is required in 5.5.x. If that isn't it, I would suggest attaching you favourite IDE and debugging your way through the request mapping process to see where it is going wrong. This certainly should be possible. As an aside, version 3 of the servlet spec is expected to include this sort of functionality in the Servlet API. Mark - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: adding servlet definition to context on the fly :Tomcat 5.5
Johnny Kewl wrote: I'd luv to see that code... the stuff you playing with is in Tomcat core... must have been difficult to debug... perhaps its an embedded app? But I think this answers your question... public void addChild(Container child) { throw new IllegalStateException (sm.getString(standardWrapper.notChild)); } is what addChild now looks like in 6... if they did allow it, now they dont (; I don't know where you found that code but that isn't the StandardContext.addChild() code for 6.0.x. Even if it was, the OP was asking about 5.5.x, not 6.0.x Mark - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: adding servlet definition to context on the fly :Tomcat 5.5
thank you for the code send i see deploymentDescriptor as a string attribute of mbean org.apache.catalina.core.StandardContext I also see com.sun.xml.rpc.tools.wsdeploy.DeploymentDescriptorParser class but I am unable to locate the javadoc documentation for DeploymentDescriptor could you display link for DeploymentDescriptor thanks, Martin __ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. Date: Sat, 4 Oct 2008 23:12:11 -0600 Subject: Re: adding servlet definition to context on the fly :Tomcat 5.5 From: [EMAIL PROTECTED] To: users@tomcat.apache.org 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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 bWrapper/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 * codeaddChild()/code method should throw an * codeIllegalArgumentException/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
RE: adding servlet definition to context on the fly :Tomcat 5.5
Hi Martin, DeploymentDescriptor is simply a bean that holds the web.xml info we want to add on the fly , its not a Tomcat class. basically it holds the init params, servlet name/class and servlet mapping...those were the only aspects of web.xml we wanted to add on the fly. Similarly WebAppConfiguration is another bean that contains application context root, repository information etc. Ram PS: As Mark suggested I am stepping thro the Tomcat code usingremote debugging in Eclipse...will post more info if i can find out what exactly I am missing in the Tomcat 5.5 case thank you for the code send i see deploymentDescriptor as a string attribute of mbean org.apache.catalina.core.StandardContext I also see com.sun.xml.rpc.tools.wsdeploy.DeploymentDescriptorParser class but I am unable to locate the javadoc documentation for DeploymentDescriptor could you display link for DeploymentDescriptor thanks, Martin __ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. Date: Sat, 4 Oct 2008 23:12:11 -0600 Subject: Re: adding servlet definition to context on the fly :Tomcat 5.5 From: [EMAIL PROTECTED] To: users@tomcat.apache.org 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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 bWrapper/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
Re: adding servlet definition to context on the fly :Tomcat 5.5
- 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: 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); } ok now see what you up to... will give it a little try... stand back... doing a kidney transplant.. ha ha --- 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]
RE: adding servlet definition to context on the fly :Tomcat 5.5
hello ram- i could'nt locate javadoc for either the WebAppConfiguration or DeploymentDescriptor classes thanks for the explanation Martin __ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. Date: Sun, 5 Oct 2008 08:19:19 -0600 Subject: RE: adding servlet definition to context on the fly :Tomcat 5.5 From: [EMAIL PROTECTED] To: users@tomcat.apache.org Hi Martin, DeploymentDescriptor is simply a bean that holds the web.xml info we want to add on the fly , its not a Tomcat class. basically it holds the init params, servlet name/class and servlet mapping...those were the only aspects of web.xml we wanted to add on the fly. Similarly WebAppConfiguration is another bean that contains application context root, repository information etc. Ram PS: As Mark suggested I am stepping thro the Tomcat code usingremote debugging in Eclipse...will post more info if i can find out what exactly I am missing in the Tomcat 5.5 case thank you for the code send i see deploymentDescriptor as a string attribute of mbean org.apache.catalina.core.StandardContext I also see com.sun.xml.rpc.tools.wsdeploy.DeploymentDescriptorParser class but I am unable to locate the javadoc documentation for DeploymentDescriptor could you display link for DeploymentDescriptor thanks, Martin __ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. Date: Sat, 4 Oct 2008 23:12:11 -0600 Subject: Re: adding servlet definition to context on the fly :Tomcat 5.5 From: [EMAIL PROTECTED] To: users@tomcat.apache.org 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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
Re: adding servlet definition to context on the fly :Tomcat 5.5
- 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... just want to understand the plain functionality... You have one web app running... WebApp MAIN Then you are able to drop another web app in WebApp EXTRA You have some kind of invoker in MAIN, that you Add EXTRA servlets to. So Main in the end is running EXTRA servlets that are dropped in late... neat idea. Its not unlike the invoker servlet idea, but you working cross context and still have cool things available like init params... Problem is that it heart surgery... which means normal debugging is an issue, thus the problem, its hard to see. If this is the scheme? I'm just wondering if maybe its something silly... like in the old TC you have crossContext=true setup, and thats not setup now... I know Chuck always says... no more in servlet config, now must be in webapps... so just wondering if its forgotten or changed. I'm thinking the classloaders will have to share if I get the overall idea. ??? --- 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]
Re: adding servlet definition to context on the fly :Tomcat 5.5
- 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]
adding servlet definition to context on the fly :Tomcat 5.5
Hi, I had written some code to dynamically add a servlet to a context in a deployed applicaiton in Tomcat 4.1. This code basically uses the catalina loader to obtain the server-engine-host-and context, and invokes the addChild method after configuring a StandardWwrapper to represent the servlet I am adding. This all works fine in Tomcat4.1 and I am able to access the servlet through the right url immediately, without having to restart Tomcat. However, I tried the same code in Tomcat 5.5 and it does not work. It does not throw any errors, but simply does not recognize the url pattern once i actually try to invoke the new servlet. I was wondering if anyone had tried this before, and if so if they have any suggestions as to why this does not work in Tomcat 5.5? More generally I am looking for a way to dynamically add a servlet definition in Tomcat 5.5. This can be done by editing the web.xml in case the application is deployed unpacked..however if the application is packed as a WAR, then I cannot edit the web.xml on the fly and wait for the watched resource mechanism to take effect. Thanks Ram - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: adding servlet definition to context on the fly :Tomcat 5.5
- Original Message - From: [EMAIL PROTECTED] To: users@tomcat.apache.org Sent: Saturday, October 04, 2008 5:34 PM Subject: adding servlet definition to context on the fly :Tomcat 5.5 Hi, I had written some code to dynamically add a servlet to a context in a deployed applicaiton in Tomcat 4.1. This code basically uses the catalina loader to obtain the server-engine-host-and context, and invokes the addChild method after configuring a StandardWwrapper to represent the servlet I am adding. This all works fine in Tomcat4.1 and I am able to access the servlet through the right url immediately, without having to restart Tomcat. I'd luv to see that code... the stuff you playing with is in Tomcat core... must have been difficult to debug... perhaps its an embedded app? But I think this answers your question... public void addChild(Container child) { throw new IllegalStateException (sm.getString(standardWrapper.notChild)); } is what addChild now looks like in 6... if they did allow it, now they dont (; Dont think you can blame TC... whoever made that app was doing open heart surgery ;) I've never tried this, but its really interesting... I think I would start by having a good look at... HttpServlet source code... its an abstract class with a little introspection... but I (think... maybe) that the way to go is to make a servlet... that does what HttpServlet servlet does... and then load your sevlet classes into your servlet... and call them... I (think... maybe) maybe that it will come down to doing your own servlet mapping... and detection of new classes added... possibly your own uri to a manager function... ie I think you can make a servlet intelligent enough to do this... without climbing into the engine and doing a liver transplant... and then because you now inside the official API... this will never happen again. In the end it will be something like http://domain/contect/addons/ANY_ADD_ON_SERVLETS ... I'd give that a bash... dont think its a good idea trying the current method even if you do find an open vein ;) Good Luck... --- 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]
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 __ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. From: [EMAIL PROTECTED] To: users@tomcat.apache.org Subject: Re: adding servlet definition to context on the fly :Tomcat 5.5 Date: Sat, 4 Oct 2008 21:20:39 +0200 - Original Message - From: [EMAIL PROTECTED] To: users@tomcat.apache.org Sent: Saturday, October 04, 2008 5:34 PM Subject: adding servlet definition to context on the fly :Tomcat 5.5 Hi, I had written some code to dynamically add a servlet to a context in a deployed applicaiton in Tomcat 4.1. This code basically uses the catalina loader to obtain the server-engine-host-and context, and invokes the addChild method after configuring a StandardWwrapper to represent the servlet I am adding. This all works fine in Tomcat4.1 and I am able to access the servlet through the right url immediately, without having to restart Tomcat. I'd luv to see that code... the stuff you playing with is in Tomcat core... must have been difficult to debug... perhaps its an embedded app? But I think this answers your question... public void addChild(Container child) { throw new IllegalStateException (sm.getString(standardWrapper.notChild)); } is what addChild now looks like in 6... if they did allow it, now they dont (; Dont think you can blame TC... whoever made that app was doing open heart surgery ;) I've never tried this, but its really interesting... I think I would start by having a good look at... HttpServlet source code... its an abstract class with a little introspection... but I (think... maybe) that the way to go is to make a servlet... that does what HttpServlet servlet does... and then load your sevlet classes into your servlet... and call them... I (think... maybe) maybe that it will come down to doing your own servlet mapping... and detection of new classes added... possibly your own uri to a manager function... ie I think you can make a servlet intelligent enough to do this... without climbing into the engine and doing a liver transplant... and then because you now inside the official API... this will never happen again. In the end it will be something like http://domain/contect/addons/ANY_ADD_ON_SERVLETS ... I'd give that a bash... dont think its a good idea trying the current method even if you do find an open vein ;) Good Luck... --- 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] _ Get more out of the Web. Learn 10 hidden secrets of Windows Live. http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
Re: adding servlet definition to context on the fly :Tomcat 5.5
- Original Message - From: Martin Gainty [EMAIL PROTECTED] 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 bWrapper/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 * codeaddChild()/code method should throw an * codeIllegalArgumentException/code. * * @author Craig R. McClanahan * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $ */ . From: [EMAIL PROTECTED] To: users@tomcat.apache.org Subject: Re: adding servlet definition to context on the fly :Tomcat 5.5 Date: Sat, 4 Oct 2008 21:20:39 +0200 - Original Message - From: [EMAIL PROTECTED] To: users@tomcat.apache.org Sent: Saturday, October 04, 2008 5:34 PM Subject: adding servlet definition to context on the fly :Tomcat 5.5 Hi, I had written some code to dynamically add a servlet to a context in a deployed applicaiton in Tomcat 4.1. This code basically uses the catalina loader to obtain the server-engine-host-and context, and invokes the addChild method after configuring a StandardWwrapper to represent the servlet I am adding. This all works fine in Tomcat4.1 and I am able to access the servlet through the right url immediately, without having to restart Tomcat. I'd luv to see that code... the stuff you playing with is in Tomcat core... must have been difficult to debug... perhaps its an embedded app? But I think this answers your question... public void addChild(Container child) { throw new IllegalStateException (sm.getString(standardWrapper.notChild)); } is what addChild now looks like in 6... if they did allow it, now they dont (; Dont think you can blame TC... whoever made that app was doing open heart surgery ;) I've never tried this, but its really interesting... I think I would start by having a good look at... HttpServlet source code... its an abstract class with a little introspection... but I (think... maybe) that the way to go is to make a servlet... that does what HttpServlet servlet does... and then load your sevlet classes into your servlet... and call them... I (think... maybe) maybe that it will come down to doing your own servlet mapping... and detection of new classes added... possibly your own uri to a manager function... ie I think you can make a servlet intelligent enough to do this... without climbing into the engine and doing a liver transplant... and then because you now inside the official API... this will never happen again. In the end it will be something like http://domain/contect/addons/ANY_ADD_ON_SERVLETS ... I'd give that a bash... dont think its a good idea trying the current method even if you do find an open vein ;) Good Luck... --- 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] _ Get more out
Re: adding servlet definition to context on the fly :Tomcat 5.5
- Original Message - From: Johnny Kewl [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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 bWrapper/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 * codeaddChild()/code method should throw an * codeIllegalArgumentException/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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
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: 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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 bWrapper/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 * codeaddChild()/code method should throw an * codeIllegalArgumentException/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