Make ServiceLoader.load work with jetty-osgi-boot to support annotations.
This commit is contained in:
parent
b6f36dadb2
commit
eacdaf7073
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.osgi.boot;
|
|||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
|
@ -72,7 +73,35 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
|
|||
|
||||
public static String[] getDefaultConfigurations ()
|
||||
{
|
||||
return __defaultConfigurations;
|
||||
if (annotationsAvailable())
|
||||
{
|
||||
String[] configs = new String[__defaultConfigurations.length+1];
|
||||
System.arraycopy(__defaultConfigurations, 0, configs, 0, 4);
|
||||
configs[4] = "org.eclipse.jetty.osgi.annotations.AnnotationConfiguration";
|
||||
configs[5] = __defaultConfigurations[__defaultConfigurations.length-1];
|
||||
return configs;
|
||||
}
|
||||
|
||||
|
||||
return Arrays.copyOf(__defaultConfigurations, __defaultConfigurations.length);
|
||||
}
|
||||
|
||||
private static boolean annotationsAvailable()
|
||||
{
|
||||
boolean result = false;
|
||||
try
|
||||
{
|
||||
Thread.currentThread().getContextClassLoader().loadClass("org.eclipse.jetty.annotations.AnnotationConfiguration");
|
||||
result = true;
|
||||
LOG.debug("Annotation support detected");
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
result = false;
|
||||
LOG.debug("No annotation support detected");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -247,7 +276,7 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
|
|||
if (getConfigurationClasses() != null)
|
||||
_webApp.setConfigurationClasses(getConfigurationClasses());
|
||||
else
|
||||
_webApp.setConfigurationClasses(__defaultConfigurations);
|
||||
_webApp.setConfigurationClasses(getDefaultConfigurations());
|
||||
|
||||
if (getDefaultsDescriptor() != null)
|
||||
_webApp.setDefaultsDescriptor(getDefaultsDescriptor());
|
||||
|
|
|
@ -66,6 +66,13 @@
|
|||
<version>${exam.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.aries.spifly</groupId>
|
||||
<artifactId>org.apache.aries.spifly.dynamic.bundle</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Don't use the native container for now. Observed limitations:
|
||||
- single test with a single configuration
|
||||
|
@ -149,13 +156,17 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
-->
|
||||
<!-- Orbit Servlet Deps -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Orbit JSP Deps -->
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-jta_1.1_spec</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- OSGi Deps -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
|
@ -182,6 +193,11 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Jetty Deps -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-annotations</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
|
@ -271,8 +287,18 @@
|
|||
<artifactId>javax.websocket-api</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>javax-websocket-server-impl</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>javax-websocket-client-impl</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.spdy</groupId>
|
||||
<artifactId>spdy-core</artifactId>
|
||||
|
|
|
@ -75,11 +75,20 @@ public class TestJettyOSGiBootCore
|
|||
public static List<Option> coreJettyDependencies()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-osgi-boot" ).versionAsInProject().start());
|
||||
|
||||
res.add(mavenBundle().groupId( "org.ow2.asm" ).artifactId( "asm" ).versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId( "org.ow2.asm" ).artifactId( "asm-commons" ).versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId( "org.ow2.asm" ).artifactId( "asm-tree" ).versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId( "org.apache.aries" ).artifactId( "org.apache.aries.util" ).version("1.0.0").start());
|
||||
res.add(mavenBundle().groupId( "org.apache.aries.spifly" ).artifactId( "org.apache.aries.spifly.dynamic.bundle" ).version("1.0.0").start());
|
||||
|
||||
res.add(mavenBundle().groupId( "javax.servlet" ).artifactId( "javax.servlet-api" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "javax.annotation" ).artifactId( "javax.annotation-api" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.apache.geronimo.specs" ).artifactId( "geronimo-jta_1.1_spec" ).version("1.1.1").noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.mail.glassfish" ).version( "1.4.1.v201005082020" ).noStart());
|
||||
|
||||
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.toolchain" ).artifactId( "jetty-schemas" ).versionAsInProject().noStart());
|
||||
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-deploy" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-server" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-servlet" ).versionAsInProject().noStart());
|
||||
|
@ -91,12 +100,19 @@ public class TestJettyOSGiBootCore
|
|||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-continuation" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-security" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-servlets" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-client" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-client" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-jndi" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-plus" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-annotations" ).versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-api" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-common" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-servlet" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-server" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-client" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "javax.websocket" ).artifactId( "javax.websocket-api" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "javax-websocket-client-impl").versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "javax-websocket-server-impl").versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-osgi-boot" ).versionAsInProject().start());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -111,11 +127,6 @@ public class TestJettyOSGiBootCore
|
|||
@Test
|
||||
public void assertAllBundlesActiveOrResolved() throws Exception
|
||||
{
|
||||
//TestOSGiUtil.debugBundles(bundleContext);
|
||||
//Bundle bootBundle = TestOSGiUtil.getBundle(bundleContext, "org.eclipse.jetty.osgi.boot");
|
||||
//TestOSGiUtil.diagnoseNonActiveOrNonResolvedBundle(bootBundle);
|
||||
Bundle httpservicebundle = TestOSGiUtil.getBundle(bundleContext, "org.eclipse.jetty.osgi.httpservice");
|
||||
TestOSGiUtil.diagnoseNonActiveOrNonResolvedBundle(httpservicebundle);
|
||||
TestOSGiUtil.assertAllBundlesActiveOrResolved(bundleContext);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.ops4j.pax.exam.junit.Configuration;
|
|||
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
||||
/**
|
||||
* Pax-Exam to make sure the jetty-osgi-boot can be started along with the
|
||||
|
@ -70,7 +71,7 @@ public class TestJettyOSGiBootWithJsp
|
|||
|
||||
options.add(CoreOptions.junitBundles());
|
||||
options.addAll(configureJettyHomeAndPort("jetty-selector.xml"));
|
||||
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.xml.*"));
|
||||
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.xml.*", "javax.activation.*"));
|
||||
options.add(CoreOptions.systemPackages("com.sun.org.apache.xalan.internal.res","com.sun.org.apache.xml.internal.utils",
|
||||
"com.sun.org.apache.xml.internal.utils", "com.sun.org.apache.xpath.internal",
|
||||
"com.sun.org.apache.xpath.internal.jaxp", "com.sun.org.apache.xpath.internal.objects"));
|
||||
|
@ -90,7 +91,7 @@ public class TestJettyOSGiBootWithJsp
|
|||
// this is how you set the default log level when using pax logging
|
||||
// (logProfile)
|
||||
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value(logLevel),
|
||||
systemProperty("org.eclipse.jetty.LEVEL").value(logLevel))));
|
||||
systemProperty("org.eclipse.jetty.annotations.LEVEL").value(logLevel))));
|
||||
|
||||
options.addAll(jspDependencies());
|
||||
|
||||
|
@ -156,11 +157,11 @@ public class TestJettyOSGiBootWithJsp
|
|||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void assertAllBundlesActiveOrResolved()
|
||||
{
|
||||
TestOSGiUtil.assertAllBundlesActiveOrResolved(bundleContext);
|
||||
TestOSGiUtil.assertAllBundlesActiveOrResolved(bundleContext);
|
||||
}
|
||||
|
||||
// at the moment can't run httpservice with jsp at the same time.
|
||||
|
@ -172,7 +173,7 @@ public class TestJettyOSGiBootWithJsp
|
|||
TestOSGiUtil.testHttpServiceGreetings(bundleContext, "http", TestJettyOSGiBootCore.DEFAULT_JETTY_HTTP_PORT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testJspDump() throws Exception
|
||||
{
|
||||
|
@ -185,6 +186,7 @@ public class TestJettyOSGiBootWithJsp
|
|||
|
||||
String content = new String(response.getContent());
|
||||
assertTrue(content.contains("<tr><th>ServletPath:</th><td>/jsp/dump.jsp</td></tr>"));
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -59,7 +59,7 @@ public class TestOSGiUtil
|
|||
//options.add(CoreOptions.equinox().version("3.6.1"));
|
||||
//options.add(CoreOptions.equinox().version("3.7.0"));
|
||||
// options.add(CoreOptions.felix().version("3.2.2"));
|
||||
options.add(CoreOptions.felix().version("4.0.2"));
|
||||
options.add(CoreOptions.felix().version("4.0.2"));
|
||||
}
|
||||
|
||||
protected static Bundle getBundle(BundleContext bundleContext, String symbolicName)
|
||||
|
@ -149,6 +149,11 @@ public class TestOSGiUtil
|
|||
System.err.println(" " + b.getSymbolicName() + " " + b.getState());
|
||||
}
|
||||
}
|
||||
|
||||
protected static ServiceReference[] getServices (String service, BundleContext bundleContext) throws Exception
|
||||
{
|
||||
return bundleContext.getAllServiceReferences(service, null);
|
||||
}
|
||||
|
||||
protected static SslContextFactory newSslContextFactory()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue