diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiDeployer.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiDeployer.java index eab610f066e..46af4885d95 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiDeployer.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiDeployer.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.osgi.boot; import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.bindings.StandardDeployer; import org.eclipse.jetty.deploy.graph.Node; +import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper; import org.eclipse.jetty.osgi.boot.utils.EventSender; @@ -34,6 +35,15 @@ import org.eclipse.jetty.osgi.boot.utils.EventSender; public class OSGiDeployer extends StandardDeployer { + private ServerInstanceWrapper _server; + + /* ------------------------------------------------------------ */ + public OSGiDeployer (ServerInstanceWrapper server) + { + _server = server; + } + + /* ------------------------------------------------------------ */ public void processBinding(Node node, App app) throws Exception { @@ -41,14 +51,14 @@ public class OSGiDeployer extends StandardDeployer //OSGi Enterprise Spec only wants an event sent if its a webapp bundle (ie not a ContextHandler) if (!(app instanceof AbstractOSGiApp)) { - super.processBinding(node,app); + doProcessBinding(node,app); } else { EventSender.getInstance().send(EventSender.DEPLOYING_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath()); try { - super.processBinding(node,app); + doProcessBinding(node,app); ((AbstractOSGiApp)app).registerAsOSGiService(); EventSender.getInstance().send(EventSender.DEPLOYED_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath()); } @@ -58,6 +68,21 @@ public class OSGiDeployer extends StandardDeployer throw e; } } - + } + + + /* ------------------------------------------------------------ */ + protected void doProcessBinding (Node node, App app) throws Exception + { + ClassLoader old = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(_server.getParentClassLoaderForWebapps()); + try + { + super.processBinding(node,app); + } + finally + { + Thread.currentThread().setContextClassLoader(old); + } } } diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiUndeployer.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiUndeployer.java index 314a87a0cea..645723af5ac 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiUndeployer.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiUndeployer.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.osgi.boot; import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.bindings.StandardUndeployer; import org.eclipse.jetty.deploy.graph.Node; +import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper; import org.eclipse.jetty.osgi.boot.utils.EventSender; @@ -35,11 +36,30 @@ import org.eclipse.jetty.osgi.boot.utils.EventSender; */ public class OSGiUndeployer extends StandardUndeployer { + private ServerInstanceWrapper _server; + + + /* ------------------------------------------------------------ */ + public OSGiUndeployer (ServerInstanceWrapper server) + { + _server = server; + } + + /* ------------------------------------------------------------ */ public void processBinding(Node node, App app) throws Exception { EventSender.getInstance().send(EventSender.UNDEPLOYING_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath()); - super.processBinding(node,app); + ClassLoader old = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(_server.getParentClassLoaderForWebapps()); + try + { + super.processBinding(node,app); + } + finally + { + Thread.currentThread().setContextClassLoader(old); + } EventSender.getInstance().send(EventSender.UNDEPLOYED_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath()); ((AbstractOSGiApp)app).deregisterAsOSGiService(); } diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java index c4bc8c529c5..94b0eec5090 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java @@ -382,10 +382,10 @@ public class ServerInstanceWrapper _deploymentManager.setUseStandardBindings(false); List deploymentLifeCycleBindings = new ArrayList(); - deploymentLifeCycleBindings.add(new OSGiDeployer()); + deploymentLifeCycleBindings.add(new OSGiDeployer(this)); deploymentLifeCycleBindings.add(new StandardStarter()); deploymentLifeCycleBindings.add(new StandardStopper()); - deploymentLifeCycleBindings.add(new OSGiUndeployer()); + deploymentLifeCycleBindings.add(new OSGiUndeployer(this)); _deploymentManager.setLifeCycleBindings(deploymentLifeCycleBindings); if (!providerClassNames.contains(BundleWebAppProvider.class.getName()))