Class OSGiWebappClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable, ClassVisibilityChecker, org.osgi.framework.BundleReference

public class OSGiWebappClassLoader extends WebAppClassLoader implements org.osgi.framework.BundleReference
OSGiWebappClassLoader Extends the webapp classloader to also use the classloader of the Bundle defining the webapp.
  • Field Details

    • JAR_WITH_SUCH_CLASS_MUST_BE_EXCLUDED

      public static final Set<String> JAR_WITH_SUCH_CLASS_MUST_BE_EXCLUDED
      when a logging framework is setup in the osgi classloaders, it can access this and register the classes that must not be found in the jar.
  • Constructor Details

    • OSGiWebappClassLoader

      public OSGiWebappClassLoader(ClassLoader parent, WebAppContext context, org.osgi.framework.Bundle contributor) throws IOException
      Parameters:
      parent - The parent classloader.
      context - The WebAppContext
      contributor - The bundle that defines this web-application.
      Throws:
      IOException - if unable to cerate the OSGiWebappClassLoader
  • Method Details

    • addClassThatIdentifiesAJarThatMustBeRejected

      public static void addClassThatIdentifiesAJarThatMustBeRejected(Class<?> zclass)
    • addClassThatIdentifiesAJarThatMustBeRejected

      public static void addClassThatIdentifiesAJarThatMustBeRejected(String zclassName)
    • findClass

      protected Class<?> findClass(String name) throws ClassNotFoundException
      Overrides:
      findClass in class WebAppClassLoader
      Throws:
      ClassNotFoundException
    • getBundle

      public org.osgi.framework.Bundle getBundle()
      Returns the Bundle that defined this web-application.
      Specified by:
      getBundle in interface org.osgi.framework.BundleReference
      Returns:
      The Bundle object associated with this BundleReference.
    • getResources

      public Enumeration<URL> getResources(String name) throws IOException
      Overrides:
      getResources in class WebAppClassLoader
      Throws:
      IOException
    • getResource

      public URL getResource(String name)
      Description copied from class: WebAppClassLoader
      Get a resource from the classloader NOTE: this method provides a convenience of hacking off a leading / should one be present. This is non-standard and it is recommended to not rely on this behavior
      Overrides:
      getResource in class WebAppClassLoader
    • findResource

      public URL findResource(String name)
      Overrides:
      findResource in class URLClassLoader
    • loadAsResource

      protected Class<?> loadAsResource(String name, boolean checkSystemResource) throws ClassNotFoundException
      Try to load the class from the bundle classloader. We do NOT load it as a resource as the WebAppClassLoader does because the url that is returned is an osgi-special url that does not play properly with WebAppClassLoader's method of extracting the class from the resource. This implementation directly asks the osgi bundle classloader to load the given class name.
      Overrides:
      loadAsResource in class WebAppClassLoader
      Parameters:
      name - the name of the class to load
      checkSystemResource - if true and the class isn't a system class we return it
      Returns:
      the loaded class
      Throws:
      ClassNotFoundException - if the class cannot be found
      See Also:
    • addClassPath

      public void addClassPath(String classPath) throws IOException
      Parse the classpath ourselves to be able to filter things. This is a derivative work of the super class
      Overrides:
      addClassPath in class WebAppClassLoader
      Parameters:
      classPath - Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.
      Throws:
      IOException - if unable to add classpath