452201 Set the container classloader for osgi during webbundle undeploy

This commit is contained in:
Jan Bartel 2015-01-01 15:53:33 +01:00
parent c92712779b
commit b59782acf8
3 changed files with 51 additions and 6 deletions

View File

@ -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);
}
}
}

View File

@ -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();
}

View File

@ -382,10 +382,10 @@ public class ServerInstanceWrapper
_deploymentManager.setUseStandardBindings(false);
List<AppLifeCycle.Binding> deploymentLifeCycleBindings = new ArrayList<AppLifeCycle.Binding>();
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()))