diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java index c0a742d2e14..b018deb25f8 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.annotations; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; +import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -726,7 +727,15 @@ public class AnnotationConfiguration extends AbstractConfiguration public Resource getJarFor (ServletContainerInitializer service) throws MalformedURLException, IOException { - String loadingJarName = Thread.currentThread().getContextClassLoader().getResource(service.getClass().getName().replace('.','/')+".class").toString(); + //try the thread context classloader to get the jar that loaded the class + URL jarURL = Thread.currentThread().getContextClassLoader().getResource(service.getClass().getName().replace('.','/')+".class"); + + //if for some reason that failed (eg we're in osgi and the TCCL does not know about the service) try the classloader that + //loaded the class + if (jarURL == null) + jarURL = service.getClass().getClassLoader().getResource(service.getClass().getName().replace('.','/')+".class"); + + String loadingJarName = jarURL.toString(); int i = loadingJarName.indexOf(".jar"); if (i < 0) @@ -830,7 +839,6 @@ public class AnnotationConfiguration extends AbstractConfiguration { ArrayList nonExcludedInitializers = new ArrayList(); - //We use the ServiceLoader mechanism to find the ServletContainerInitializer classes to inspect long start = 0; diff --git a/jetty-jspc-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/jetty-jspc-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml new file mode 100644 index 00000000000..dd49e822570 --- /dev/null +++ b/jetty-jspc-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + jspc + + + + + + + + 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 dc94d6d2f54..e142d391166 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 @@ -376,10 +376,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())) diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java index 6db338eacc5..fc5b5ef380d 100644 --- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java +++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java @@ -185,26 +185,20 @@ public class EnvConfiguration extends AbstractConfiguration @Override public void destroy (WebAppContext context) throws Exception { - ClassLoader old_loader = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(context.getClassLoader()); - ContextFactory.associateClassLoader(context.getClassLoader()); - try { - //unbind any NamingEntries that were configured in this webapp's name space - + //unbind any NamingEntries that were configured in this webapp's name space NamingContext scopeContext = (NamingContext)NamingEntryUtil.getContextForScope(context); scopeContext.getParent().destroySubcontext(scopeContext.getName()); } catch (NameNotFoundException e) { LOG.ignore(e); - LOG.debug("No naming entries configured in environment for webapp "+context); + LOG.debug("No jndi entries scoped to webapp {}", context); } - finally + catch (NamingException e) { - ContextFactory.disassociateClassLoader(); - Thread.currentThread().setContextClassLoader(old_loader); + LOG.debug("Error unbinding jndi entries scoped to webapp "+context, e); } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java index 79ac67b6c47..44271cbb137 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java @@ -268,7 +268,7 @@ public class SslContextFactory extends AbstractLifeCycle } SecureRandom secureRandom = (_secureRandomAlgorithm == null)?null:SecureRandom.getInstance(_secureRandomAlgorithm); - SSLContext context = SSLContext.getInstance(_sslProtocol); + SSLContext context = _sslProvider == null ? SSLContext.getInstance(_sslProtocol) : SSLContext.getInstance(_sslProtocol, _sslProvider); context.init(null, trust_managers, secureRandom); _context = context; } @@ -309,7 +309,7 @@ public class SslContextFactory extends AbstractLifeCycle TrustManager[] trustManagers = getTrustManagers(trustStore,crls); SecureRandom secureRandom = (_secureRandomAlgorithm == null)?null:SecureRandom.getInstance(_secureRandomAlgorithm); - SSLContext context = _sslProvider == null ? SSLContext.getInstance(_sslProtocol) : SSLContext.getInstance(_sslProtocol,_sslProvider); + SSLContext context = _sslProvider == null ? SSLContext.getInstance(_sslProtocol) : SSLContext.getInstance(_sslProtocol, _sslProvider); context.init(keyManagers,trustManagers,secureRandom); _context = context; } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java index b395e725262..57cbc71ea46 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java @@ -405,6 +405,15 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo return _threadsIdle.get(); } + /** + * @return The number of busy threads in the pool + */ + @ManagedAttribute("total number of busy threads in the pool") + public int getBusyThreads() + { + return getThreads() - getIdleThreads(); + } + /** * @return True if the pool is at maxThreads and there are not more idle threads than queued jobs */