public class OsgiServletContextClassLoader extends ClassLoader implements org.osgi.framework.BundleReference
A ClassLoader added in Pax Web to replace all pax-swissbox/xbean bundle classloaders and to be used
as the ClassLoader for OsgiServletContext.
In Whiteboard scenario, an OsgiServletContext should get a ClassLoader from a bundle that
was used to register ServletContextHelper OSGi service and in case of
servlets (and filters), the ServletContext obtained from ServletConfig
should return (in ServletContext.getClassLoader()) the ClassLoader of a bundle associated with
the Bundle that registered this Servlet or Filter OSGi service.
In practice (and in WAB scenario), the actual ClassLoader returned from OsgiServletContext should
also be able to reach to resources/classes for given server runtime (Jetty, Tomcat, Undertow) and engines like JSP.
To this end, When an instance of OsgiServletContext is created by server-specific
ServerController, an instance of OsgiServletContextClassLoader will
be created and set as the ClassLoader of the runtime-specific ServletContext.
This ClassLoader doesn't follow the delegation model - it has no parent and simply collects the resources
and attempts classloading from all the bundles. It never calls ClassLoader.defineClass(byte[], int, int) on its own.
To get the picture, here are three methods for all three supported runtimes:
org.eclipse.jetty.server.handler.ContextHandler#setClassLoader(java.lang.ClassLoader)org.apache.catalina.core.ContainerBase#setParentClassLoader(java.lang.ClassLoader)io.undertow.servlet.api.DeploymentInfo#setClassLoader(java.lang.ClassLoader)By default (outside of OSGi), here are the actual classloader classes used:
org.eclipse.jetty.webapp.WebAppClassLoaderorg.apache.catalina.loader.ParallelWebappClassLoader and org.apache.catalina.loader.WebappLoaderorg.jboss.as.web.host.WebDeploymentBuilder#getClassLoader()
in Wildfly/EAP.This ClassLoader implements BundleReference
| Constructor and Description |
|---|
OsgiServletContextClassLoader() |
| Modifier and Type | Method and Description |
|---|---|
void |
addBundle(org.osgi.framework.Bundle bundle)
Adds a
Bundle to be reachable from this ClassLoader |
void |
addBundles(org.osgi.framework.Bundle... bundle)
Adds
bundles to be reachable from this ClassLoader |
protected Class<?> |
findClass(String name) |
protected URL |
findResource(String name) |
protected Enumeration<URL> |
findResources(String name) |
org.osgi.framework.Bundle |
getBundle() |
List<org.osgi.framework.Bundle> |
getBundles() |
Class<?> |
loadClass(String name) |
void |
makeImmutable()
After adding all bundles that back up this
ClassLoader, this method prevents adding more bundles. |
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSignerspublic org.osgi.framework.Bundle getBundle()
getBundle in interface org.osgi.framework.BundleReferencepublic void addBundle(org.osgi.framework.Bundle bundle)
Bundle to be reachable from this ClassLoaderbundle - public void addBundles(org.osgi.framework.Bundle... bundle)
bundles to be reachable from this ClassLoaderbundle - public List<org.osgi.framework.Bundle> getBundles()
public void makeImmutable()
ClassLoader, this method prevents adding more bundles.public Class<?> loadClass(String name) throws ClassNotFoundException
loadClass in class ClassLoaderClassNotFoundExceptionprotected URL findResource(String name)
findResource in class ClassLoaderprotected Enumeration<URL> findResources(String name) throws IOException
findResources in class ClassLoaderIOExceptionprotected Class<?> findClass(String name) throws ClassNotFoundException
findClass in class ClassLoaderClassNotFoundExceptionCopyright © 2006–2024 OPS4J - Open Participation Software for Java. All rights reserved.