Filter for Apache OFBiz

Help
lonb
2010-06-23
2013-04-17
  • lonb
    lonb
    2010-06-23

    Apache OFBiz uses an embedded Tomcat engine to serve pages and uses dynamic classloading across components.  None of the built-in filters worked, so with a bit of futzing around, this one got the job done (I put it in the mentorgen package, for easy of deployment):

    package com.mentorgen.tools.profile.instrument.clfilter;
    /**
     * A filter that accepts classes that are loaded by Tomcat's 
     * web app class loader (this has only been tested with Tomcat 5.5.x)
     * 
     * @author <a href="lbinder@folica.com">Lon F. Binder</a>
     * @see com.mentorgen.tools.profile.instrument.clfilter.ClassLoaderFilter
     */
    public class OFBizClassLoaderFilter implements ClassLoaderFilter {
        private static final String CLASSLOADER_TOMCAT = "org.apache.catalina.loader.WebappClassLoader";
        private static final String CLASSLOADER_URLBASED = "java.net.URLClassLoader";
        public boolean canFilter() {
            return true;
        }
    
        public boolean accept(ClassLoader loader) {
            String loaderName = loader.getClass().getName();
            return CLASSLOADER_TOMCAT.equals(loaderName) || CLASSLOADER_URLBASED.equals(loaderName);
        }
    
    } // Everyone likes the end of class