On Mon, 23 Dec 2002, Randy Secrist wrote:
> Date: Mon, 23 Dec 2002 11:25:51 -0700 > From: Randy Secrist <[EMAIL PROTECTED]> > Reply-To: Tomcat Users List <[EMAIL PROTECTED]> > To: Tomcat Users List <[EMAIL PROTECTED]> > Subject: Sealing Violation due to inclusion of LifeCycle? > > I have been building classes inherited from the > org.apache.catalina.realmbase package, and have been struggling with > where to put them. One of the reason's I have been doing this is to > expose TC's realm implementation within my web applications. The best > solution I have found so far is to just drop the apache classes I need > for my webapps into a .jar in the common/lib directory. > > I have been getting most of the functionality I want, but once I > override the stop() method of RealmBase, I start getting a sealing > violation due to the inclusion of LifeCycle, and LifeCycleException when > tomcat starts up. I can see that once my hack gets deeper and deeper > into TC code, I will windup with class loader issues, which I would like > to avoid. > > Mostly, I am wondering (hoping) if there is a way to expose my custom > user database (defined within GlobalNamingResource) within my webapps > without having to worry so much about class loader issues, as I often > find down in development that certian apache classes are not exposed > within the class loader my web apps are using. I am hoping that the > same class I can play with inside my applications, would be the same > singleton instance that tomcat uses when it starts - but I haven't found > an easy way to expose this. Does this violate some sort of MVC ideology? > The fundamental documentation on how class loaders work in Tomcat is: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/class-loader-howto.html If you look at the directory structure of a standard Tomcat distribution, you'll see that the org.apache.catalina.* classes (from catalina.jar) are loaded into the Catalina class loader, which is not visible to webapps. Therefore, any classes you write that need these APIs must also be stored in the Catalina class loader (putting them in the Common class loader won't help you, because they still wouldn't be able to see the base classes). The configuration option Tomcat supports for this is the "privileged" attribute on a <Context> element, which makes the the webapp's parent class loader be the Catalina loader instead of the Shared loader. This is the technique used by the admin and manager webapps that are shipped with Tomcat. WARNING: Use of this technique gives your webapp access to ***all*** of the internal objects of the servlet container, and is therefore very dangerous unless you are absolutely sure that your webapp cannot be abused by malicious users. > Randy > Craig -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>