Clean-up OSGi test; add spdy OSGi test; fix felix
Upgrade to the latest pax-exam Support for felix-3.x and 4.x as tested Fix the spdy MANIFEST.MF generations Add an integration test for SPDY Refactor the test code Squashed commit of the following: commit bd020ee1214992d8d21a11dc800e04dc5e9b2001 Author: Hugues Malphettes <hmalphettes@gmail.com> Date: Sat Oct 6 16:58:43 2012 +0800 Add spdy integration test for OSGi and clean-up Refacor the pax-exam OSGi integration tests Add an integration test for spdy. Execute the test under 2 versions of felix and 2 versions of equinox. commit f3151a272ab92560432f3b76f564bf06b19bc22b Author: Hugues Malphettes <hmalphettes@gmail.com> Date: Sat Oct 6 16:28:51 2012 +0800 Fix the generated MANIFEST.MF OSGi integration test in the next commit. commit 3152aa2b5e39cf2d3b81f8400488c0672e922b8d Author: Hugues Malphettes <hmalphettes@gmail.com> Date: Fri Oct 5 16:58:29 2012 +0800 Fix the startup of the servlet. setInitOrder(0) was working in jetty-7 and jetty-8 but not in jetty-9 anymore. setInitOrder(1) is fine. commit 8038d314f4f423e8608fd09dd42b840e101a0c13 Author: Hugues Malphettes <hmalphettes@gmail.com> Date: Thu Oct 4 17:53:28 2012 +0800 Upgrade to pax-exam-2.6 commit 7136fa88e2410ac345b6ae0657d882c7e9714c0b Author: Hugues Malphettes <hmalphettes@gmail.com> Date: Thu Oct 4 17:53:07 2012 +0800 Support for felix-3.x and felix-4.x commit 0bcc6b0d8ed5144150f90f578a90c558419349d1 Author: Hugues Malphettes <hmalphettes@gmail.com> Date: Thu Oct 4 17:53:28 2012 +0800 Upgrade to pax-exam-2.6 commit 2e17466624650df433b6c5f11abafb56539ee740 Author: Hugues Malphettes <hmalphettes@gmail.com> Date: Thu Oct 4 17:53:07 2012 +0800 Support for felix-3.x and felix-4.x
This commit is contained in:
parent
41ea028706
commit
3efefe37bc
|
@ -34,6 +34,10 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper
|
|||
|
||||
private static boolean identifiedOsgiImpl = false;
|
||||
|
||||
private static Class BundleWiringClass = null;
|
||||
private static Method BundleWiringClass_getClassLoader_method = null;
|
||||
private static Method BundleClass_adapt_method = null;
|
||||
|
||||
private static boolean isEquinox = false;
|
||||
|
||||
private static boolean isFelix = false;
|
||||
|
@ -41,6 +45,26 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper
|
|||
private static void init(Bundle bundle)
|
||||
{
|
||||
identifiedOsgiImpl = true;
|
||||
|
||||
try
|
||||
{
|
||||
BundleWiringClass = bundle.getClass().getClassLoader().loadClass("org.osgi.framework.wiring.BundleWiring");
|
||||
if (BundleWiringClass != null)
|
||||
{
|
||||
BundleWiringClass_getClassLoader_method = BundleWiringClass.getDeclaredMethod("getClassLoader", new Class[] {});
|
||||
BundleClass_adapt_method = bundle.getClass().getDeclaredMethod("adapt", new Class[] { Class.class });
|
||||
BundleClass_adapt_method.setAccessible(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
//nevermind: an older version of OSGi where BundleWiring is not availble
|
||||
//t.printStackTrace();
|
||||
}
|
||||
|
||||
if (!bundle.getClass().getName().startsWith("org.apache.felix"))
|
||||
{
|
||||
try
|
||||
{
|
||||
isEquinox = bundle.getClass().getClassLoader().loadClass("org.eclipse.osgi.framework.internal.core.BundleHost") != null;
|
||||
|
@ -49,6 +73,7 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper
|
|||
{
|
||||
isEquinox = false;
|
||||
}
|
||||
}
|
||||
if (!isEquinox)
|
||||
{
|
||||
try
|
||||
|
@ -70,6 +95,7 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper
|
|||
*/
|
||||
public ClassLoader getBundleClassLoader(Bundle bundle)
|
||||
{
|
||||
//Older OSGi implementations:
|
||||
String bundleActivator = (String) bundle.getHeaders().get("Bundle-Activator");
|
||||
if (bundleActivator == null)
|
||||
{
|
||||
|
@ -93,6 +119,22 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper
|
|||
{
|
||||
init(bundle);
|
||||
}
|
||||
//This works for OSGi 4.2 and more recent. Aka version 1.6
|
||||
//It is using ava reflection to execute:
|
||||
//(BundleClassLoader) bundle.adapt(BundleWiring.class).getClassLoader()
|
||||
if (BundleClass_adapt_method != null && BundleWiringClass_getClassLoader_method != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object bundleWiring = BundleClass_adapt_method.invoke(bundle, BundleWiringClass);
|
||||
return (ClassLoader)BundleWiringClass_getClassLoader_method.invoke(bundleWiring, new Object[] {});
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (isEquinox)
|
||||
{
|
||||
return internalGetEquinoxBundleClassLoader(bundle);
|
||||
|
@ -136,6 +178,9 @@ public class DefaultBundleClassLoaderHelper implements BundleClassLoaderHelper
|
|||
|
||||
private static Field Felix_ModuleImpl_m_classLoader_field;
|
||||
|
||||
private static Field Felix_BundleImpl_m_revisions_field;
|
||||
|
||||
|
||||
private static ClassLoader internalGetFelixBundleClassLoader(Bundle bundle)
|
||||
{
|
||||
// assume felix:
|
||||
|
|
|
@ -36,8 +36,8 @@ import org.eclipse.jetty.util.resource.FileResource;
|
|||
import org.osgi.framework.Bundle;
|
||||
|
||||
/**
|
||||
* From a bundle to its location on the filesystem. Assumes the bundle is not a
|
||||
* jar.
|
||||
* From a bundle to its location on the filesystem.
|
||||
* Often assumes the bundle is not a jar.
|
||||
*
|
||||
* @author hmalphettes
|
||||
*/
|
||||
|
@ -150,7 +150,6 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
|
|||
{
|
||||
// observed this on felix-2.0.0
|
||||
String location = bundle.getLocation();
|
||||
// System.err.println("location " + location);
|
||||
if (location.startsWith("file:/"))
|
||||
{
|
||||
URI uri = new URI(URIUtil.encodePath(location));
|
||||
|
@ -183,10 +182,16 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
|
|||
File file = new File(location.substring("file:".length()));
|
||||
return file;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Resort to introspection on felix:
|
||||
return getBundleInstallLocationInFelix(bundle);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Locate a file inside a bundle.
|
||||
*
|
||||
|
@ -357,4 +362,85 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
|
|||
return url;
|
||||
}
|
||||
|
||||
// Felix introspection
|
||||
private static Method Felix_BundleImpl_getArchive_method;
|
||||
private static Method Felix_BundleArchive_getCurrentRevision_method;
|
||||
private static Method Felix_BundleRevision_getRevisionRootDir_method;
|
||||
|
||||
private static boolean felixIntroSpectionDone = false;
|
||||
|
||||
/**
|
||||
* Introspection of the implementation classes of Felix-3.x and Felix-4.x.
|
||||
* <p>
|
||||
* See org.apache.felix.framework.cache
|
||||
* In pseudo code:
|
||||
* <code>
|
||||
* File revRootDir = BundleImpl.getArchive().getCurrentRevision().getRevisionRootDir();
|
||||
* return new File(revRootDir, bundle.jar) if it exists?
|
||||
* else return revRootDir
|
||||
* </p>
|
||||
* @param bundle
|
||||
* @return The File or null if we failed to find it.
|
||||
*/
|
||||
private static File getBundleInstallLocationInFelix(Bundle bundle)
|
||||
{
|
||||
if (Felix_BundleImpl_getArchive_method == null) {
|
||||
if (felixIntroSpectionDone)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
felixIntroSpectionDone = true;
|
||||
try
|
||||
{
|
||||
Felix_BundleImpl_getArchive_method = bundle.getClass().getDeclaredMethod("getArchive", new Class[] {});
|
||||
Felix_BundleImpl_getArchive_method.setAccessible(true);
|
||||
Object archive = Felix_BundleImpl_getArchive_method.invoke(bundle);
|
||||
Class bundleArchiveClass = archive.getClass();
|
||||
Felix_BundleArchive_getCurrentRevision_method = bundleArchiveClass.getDeclaredMethod("getCurrentRevision", new Class[] {});
|
||||
Felix_BundleArchive_getCurrentRevision_method.setAccessible(true);
|
||||
Object revision = Felix_BundleArchive_getCurrentRevision_method.invoke(archive);
|
||||
Class bundleRevisionClass = revision.getClass();
|
||||
Felix_BundleRevision_getRevisionRootDir_method = bundleRevisionClass.getMethod("getRevisionRootDir", new Class[] {});
|
||||
Felix_BundleRevision_getRevisionRootDir_method.setAccessible(true);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
//nevermind?
|
||||
//t.printStackTrace();
|
||||
Felix_BundleImpl_getArchive_method = null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (Felix_BundleImpl_getArchive_method != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object archive = Felix_BundleImpl_getArchive_method.invoke(bundle);
|
||||
Object revision = Felix_BundleArchive_getCurrentRevision_method.invoke(archive);
|
||||
File revRootDir = (File)Felix_BundleRevision_getRevisionRootDir_method.invoke(revision);
|
||||
//System.err.println("Got the archive revision root dir " + revRootDir.getAbsolutePath());
|
||||
File bundleJar = new File(revRootDir, "bundle.jar");
|
||||
if (bundleJar.exists())
|
||||
{
|
||||
//bundle.jar is hardcoded in org.apache.felix.framework.cache.JarRevision
|
||||
//when it is not a bundle.jar, then the bundle location starts with 'file:' and we have already
|
||||
//taken care if that scheme earlier.
|
||||
return bundleJar;
|
||||
}
|
||||
else //sanity check?: if (new File(revRootDir, "META-INF/MANIFEST.MF").exists())
|
||||
{
|
||||
//this is a DirectoryRevision
|
||||
return revRootDir;
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
//best effort: nevermind
|
||||
//t.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// -- end Felix introspection
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<Call name="addServlet">
|
||||
<Arg>org.eclipse.equinox.http.servlet.HttpServiceServlet</Arg>
|
||||
<Arg>/*</Arg>
|
||||
<Set name="InitOrder">0</Set>
|
||||
<Set name="InitOrder">1</Set>
|
||||
</Call>
|
||||
<!-- custom pluggable error handler -->
|
||||
<Set name="ErrorHandler">
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
<osgi-services-version>3.2.100.v20100503</osgi-services-version>
|
||||
<equinox-http-servlet-version>1.0.0-v20070606</equinox-http-servlet-version>
|
||||
<!--equinox-servletbridge-version>1.0.0-v20070523</equinox-servletbridge-version-->
|
||||
<logback-version>0.9.18</logback-version>
|
||||
<slf4j-version>1.5.11</slf4j-version>
|
||||
<logback-version>0.9.29</logback-version>
|
||||
<slf4j-version>1.6.1</slf4j-version>
|
||||
</properties>
|
||||
<modules>
|
||||
<module>jetty-osgi-boot</module>
|
||||
|
|
|
@ -8,28 +8,157 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-jetty-osgi</artifactId>
|
||||
<name>Jetty :: OSGi :: Test</name>
|
||||
<description>Jetty OSGi Integration test</description>
|
||||
<description>Jetty OSGi Integration tests</description>
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.boot.test</bundle-symbolic-name>
|
||||
<bundle-symbolic-name>${project.groupId}.boot.test.spdy</bundle-symbolic-name>
|
||||
<jetty-orbit-url>http://download.eclipse.org/jetty/orbit/</jetty-orbit-url>
|
||||
<assembly-directory>target/distribution</assembly-directory>
|
||||
<paxexam-version-old>1.2.0</paxexam-version-old>
|
||||
<paxexam-version>1.2.4</paxexam-version>
|
||||
<exam.version>2.6.0</exam.version>
|
||||
<url.version>1.4.0</url.version>
|
||||
<paxswissbox.version>1.5.1</paxswissbox.version>
|
||||
<felixversion>4.0.3</felixversion>
|
||||
<injection.bundle.version>1.0</injection.bundle.version>
|
||||
<runner.version>1.7.6</runner.version>
|
||||
<npn-version>1.1.0.v20120525</npn-version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit-dep</artifactId>
|
||||
<version>4.10</version>
|
||||
</dependency>
|
||||
<!-- Pax Exam Dependencies -->
|
||||
<!-- OPS4J Swissbox Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.swissbox</groupId>
|
||||
<artifactId>pax-swissbox-core</artifactId>
|
||||
<version>${paxswissbox.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.swissbox</groupId>
|
||||
<artifactId>pax-swissbox-extender</artifactId>
|
||||
<version>${paxswissbox.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.swissbox</groupId>
|
||||
<artifactId>pax-swissbox-lifecycle</artifactId>
|
||||
<version>${paxswissbox.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.swissbox</groupId>
|
||||
<artifactId>pax-swissbox-framework</artifactId>
|
||||
<version>${paxswissbox.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam</artifactId>
|
||||
<version>${exam.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-atinject_1.0_spec</artifactId>
|
||||
<version>${injection.bundle.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam-inject</artifactId>
|
||||
<version>${exam.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Don't use the native container for now. Observed limitations:
|
||||
- single test with a single configuration
|
||||
- does not read the versions of the dependencies from the pom.xml
|
||||
and hence hardcode the bundles versions in the source code instead
|
||||
- no support for most configuration options for the OSGi container. -->
|
||||
<!--dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam-container-native</artifactId>
|
||||
<version>${exam.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency-->
|
||||
|
||||
<!-- container is not bad but not enough config parameters yet
|
||||
can't pass the VMOption for npn-boot
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam-container-forked</artifactId>
|
||||
<version>${exam.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam-container-paxrunner</artifactId>
|
||||
<version>${exam.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.runner</groupId>
|
||||
<artifactId>pax-runner-no-jcl</artifactId>
|
||||
<version>${runner.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam-junit4</artifactId>
|
||||
<version>${exam.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam-link-mvn</artifactId>
|
||||
<version>${exam.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.url</groupId>
|
||||
<artifactId>pax-url-aether</artifactId>
|
||||
<version>${url.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- OSGi R4 frameworks -->
|
||||
<dependency>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>org.apache.felix.framework</artifactId>
|
||||
<version>${felixversion}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam-testforge</artifactId>
|
||||
<version>${exam.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- For sane logging -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.6.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Orbit Servlet Deps -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.servlet</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Orbit JSP Deps -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-jsp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- OSGi Deps -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
|
@ -49,7 +178,6 @@
|
|||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Jetty Deps -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
|
@ -123,13 +251,44 @@
|
|||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.spdy</groupId>
|
||||
<artifactId>spdy-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.spdy</groupId>
|
||||
<artifactId>spdy-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.spdy</groupId>
|
||||
<artifactId>spdy-http-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.spdy</groupId>
|
||||
<artifactId>spdy-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mortbay.jetty.npn</groupId>
|
||||
<artifactId>npn-boot</artifactId>
|
||||
<version>${npn-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-plus</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Eclipse OSGi Deps -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
|
@ -153,7 +312,6 @@
|
|||
<artifactId>servlet</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>test-jetty-webapp</artifactId>
|
||||
|
@ -161,139 +319,40 @@
|
|||
<classifier>webbundle</classifier>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam</artifactId>
|
||||
<version>${paxexam-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam-junit</artifactId>
|
||||
<version>${paxexam-version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<!-- we use junit-dep -->
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam-container-default</artifactId>
|
||||
<version>${paxexam-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>maven-paxexam-plugin</artifactId>
|
||||
<version>${paxexam-version}</version>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- No point defining -Xbootclasspath as the actual OSGi VM is run as a forked process by pax-exam -->
|
||||
<!--argLine>-Xbootclasspath/p:${settings.localRepository}/org/mortbay/jetty/npn/npn-boot/${npn-version}/npn-boot-${npn-version}.jar</argLine-->
|
||||
<!-- But we do pass the sys property of the npn-boot jar -->
|
||||
<argLine>-Dmortbay-npn-boot=${settings.localRepository}/org/mortbay/jetty/npn/npn-boot/${npn-version}/npn-boot-${npn-version}.jar</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.servicemix.tooling</groupId>
|
||||
<artifactId>depends-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-config</id>
|
||||
<id>generate-depends-file</id>
|
||||
<goals>
|
||||
<goal>generate-depends-file</goal>
|
||||
<goal>generate-config</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<options>
|
||||
<workingDirectory>${project.build.directory}/paxexam</workingDirectory>
|
||||
</options>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-orbit-servlet-api-deps</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.servlet</artifactId>
|
||||
<version>${orbit-servlet-api-version}</version>
|
||||
<overWrite>true</overWrite>
|
||||
<outputDirectory>${assembly-directory}/lib</outputDirectory>
|
||||
<destFileName>servlet-api-3.0.jar</destFileName>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>copy-orbit-lib-jndi-deps</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includeGroupIds>org.eclipse.jetty.orbit</includeGroupIds>
|
||||
<includeArtifactIds>javax.mail.glassfish,javax.activation</includeArtifactIds>
|
||||
<includeTypes>jar</includeTypes>
|
||||
<outputDirectory>${assembly-directory}/lib/jndi</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>copy-orbit-lib-jsp-deps</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includeGroupIds>org.eclipse.jetty.orbit</includeGroupIds>
|
||||
<includeArtifactIds>com.sun.el,javax.el,javax.servlet.jsp,javax.servlet.jsp.jstl,org.apache.jasper.glassfish,org.apache.taglibs.standard.glassfish,org.eclipse.jdt.core</includeArtifactIds>
|
||||
<includeTypes>jar</includeTypes>
|
||||
<outputDirectory>${assembly-directory}/lib/jsp</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.8</version>
|
||||
<configuration>
|
||||
<manifest>prevent/overwriting/by/pointing/to/nonexisting/MANIFEST.MF</manifest>
|
||||
<pde>false</pde>
|
||||
<downloadSources>true</downloadSources>
|
||||
<sourceExcludes>
|
||||
<sourceExclude>**/.svn/**</sourceExclude>
|
||||
</sourceExcludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,2 @@
|
|||
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
|
||||
org.eclipse.jetty.spdy.LEVEL=WARN
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,133 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
|
||||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- HttpChannel Configuration -->
|
||||
<!-- =========================================================== -->
|
||||
<New id="httpConfig" class="org.eclipse.jetty.server.HttpChannelConfig">
|
||||
<Set name="secureScheme">https</Set>
|
||||
<Set name="securePort"><SystemProperty name="jetty.spdy.port" default="8443"/></Set>
|
||||
<Set name="outputBufferSize">32768</Set>
|
||||
<Set name="requestHeaderSize">8192</Set>
|
||||
<Set name="responseHeaderSize">8192</Set>
|
||||
<Call name="addCustomizer">
|
||||
<Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
|
||||
</Call>
|
||||
</New>
|
||||
|
||||
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Setup a SSL Context factory -->
|
||||
<!-- =========================================================== -->
|
||||
<New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
|
||||
<Set name="KeyStorePath"><Property name="jetty.home" default="."/>/etc/keystore
|
||||
</Set>
|
||||
<Set name="KeyStorePassword">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
|
||||
<Set name="KeyManagerPassword">OBF:1u2u1wml1z7s1z7a1wnl1u2g</Set>
|
||||
<Set name="TrustStorePath"><Property name="jetty.home" default="."/>/etc/keystore
|
||||
</Set>
|
||||
<Set name="TrustStorePassword">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
|
||||
</New>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Add HTTP Customizer for Secure request -->
|
||||
<!-- =========================================================== -->
|
||||
<Ref id="httpConfig">
|
||||
<Call name="addCustomizer">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.SecureRequestCustomizer"/>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Ref>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Create a push strategy -->
|
||||
<!-- =========================================================== -->
|
||||
<New id="pushStrategy" class="org.eclipse.jetty.spdy.server.http.ReferrerPushStrategy">
|
||||
<Arg type="List">
|
||||
<Array type="String">
|
||||
<Item>.*\.css</Item>
|
||||
<Item>.*\.js</Item>
|
||||
<Item>.*\.png</Item>
|
||||
<Item>.*\.jpg</Item>
|
||||
<Item>.*\.gif</Item>
|
||||
</Array>
|
||||
</Arg>
|
||||
</New>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Set connectors -->
|
||||
<!-- =========================================================== -->
|
||||
<Call id="sslConnector" name="addConnector">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.ServerConnector">
|
||||
<Arg name="server">
|
||||
<Ref id="Server"/>
|
||||
</Arg>
|
||||
<Arg name="factories">
|
||||
<Array type="org.eclipse.jetty.server.ConnectionFactory">
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.server.SslConnectionFactory">
|
||||
<Arg name="next">npn</Arg>
|
||||
<Arg name="sslContextFactory">
|
||||
<Ref id="sslContextFactory"/>
|
||||
</Arg>
|
||||
</New>
|
||||
</Item>
|
||||
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.spdy.server.NPNServerConnectionFactory">
|
||||
<Arg name="protocols">
|
||||
<Array type="String">
|
||||
<Item>spdy/3</Item>
|
||||
<Item>spdy/2</Item>
|
||||
<Item>http/1.1</Item>
|
||||
</Array>
|
||||
</Arg>
|
||||
<Set name="defaultProtocol">http/1.1</Set>
|
||||
</New>
|
||||
</Item>
|
||||
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.spdy.server.http.HTTPSPDYServerConnectionFactory">
|
||||
<Arg name="version" type="int">3</Arg>
|
||||
<Arg name="config">
|
||||
<Ref id="httpConfig"/>
|
||||
</Arg>
|
||||
<!-- <Arg name="pushStrategy"><Ref id="pushStrategy"/></Arg> -->
|
||||
</New>
|
||||
</Item>
|
||||
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.spdy.server.http.HTTPSPDYServerConnectionFactory">
|
||||
<Arg name="version" type="int">2</Arg>
|
||||
<Arg name="config">
|
||||
<Ref id="httpConfig"/>
|
||||
</Arg>
|
||||
</New>
|
||||
</Item>
|
||||
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
|
||||
<Arg name="config">
|
||||
<Ref id="httpConfig"/>
|
||||
</Arg>
|
||||
</New>
|
||||
</Item>
|
||||
</Array>
|
||||
</Arg>
|
||||
<Set name="host">
|
||||
<Property name="jetty.host"/>
|
||||
</Set>
|
||||
<Set name="port">
|
||||
<SystemProperty name="jetty.spdy.port" default="8443"/>
|
||||
</Set>
|
||||
<Set name="idleTimeout">30000</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
</Configure>
|
Binary file not shown.
|
@ -1,197 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.osgi.boot;
|
||||
|
||||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.options;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.HttpContentResponse;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.osgi.boot.internal.serverfactory.DefaultJettyAtJettyHomeHelper;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.ops4j.pax.exam.CoreOptions;
|
||||
import org.ops4j.pax.exam.Inject;
|
||||
import org.ops4j.pax.exam.Option;
|
||||
import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
|
||||
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;
|
||||
import org.osgi.service.http.HttpService;
|
||||
|
||||
/**
|
||||
* Pax-Exam to make sure the jetty-osgi-boot can be started along with the httpservice web-bundle.
|
||||
* Then make sure we can deploy an OSGi service on the top of this.
|
||||
*/
|
||||
@RunWith( JUnit4TestRunner.class )
|
||||
public class TestJettyOSGiBootCore
|
||||
{
|
||||
/**
|
||||
* Jetty-osgi including webapp support and also jetty-client.
|
||||
* Sets the system property jetty.home.bunde=org.eclipse.jetty.osgi.boot
|
||||
* to use the jetty server configuration embedded in
|
||||
*
|
||||
* @return list of options
|
||||
*/
|
||||
public static List<Option> provisionCoreJetty()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
// get the jetty home config from the osgi boot bundle.
|
||||
res.add(PaxRunnerOptions.vmOptions("-Djetty.port=9876 -D" + DefaultJettyAtJettyHomeHelper.SYS_PROP_JETTY_HOME_BUNDLE + "=org.eclipse.jetty.osgi.boot"));
|
||||
res.addAll(coreJettyDependencies());
|
||||
return res;
|
||||
}
|
||||
|
||||
public static List<Option> coreJettyDependencies() {
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.servlet" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.osgi" ).artifactId( "org.eclipse.osgi.services" ).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());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-util" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-http" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-xml" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-webapp" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-io" ).versionAsInProject().noStart());
|
||||
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.websocket" ).artifactId( "websocket-core" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-server" ).versionAsInProject().noStart());
|
||||
//optional:
|
||||
//res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-client" ).versionAsInProject().noStart());
|
||||
return res;
|
||||
}
|
||||
|
||||
public static List<Option> websocketDependencies() {
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
return res;
|
||||
}
|
||||
|
||||
@Inject
|
||||
BundleContext bundleContext = null;
|
||||
|
||||
|
||||
@Configuration
|
||||
public static Option[] configure()
|
||||
{
|
||||
ArrayList<Option> options = new ArrayList<Option>();
|
||||
options.addAll(provisionCoreJetty());
|
||||
options.addAll(Arrays.asList(options(
|
||||
// install log service using pax runners profile abstraction (there are more profiles, like DS)
|
||||
//logProfile(),
|
||||
// this is how you set the default log level when using pax logging (logProfile)
|
||||
CoreOptions.systemProperty( "org.ops4j.pax.logging.DefaultServiceLog.level" ).value( "INFO" ),
|
||||
|
||||
// CoreOptions.equinox(), CoreOptions.felix(),//.version("3.0.0"),
|
||||
|
||||
mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-osgi-boot" ).versionAsInProject().start(),
|
||||
mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-httpservice" ).versionAsInProject().start(),
|
||||
|
||||
mavenBundle().groupId( "org.eclipse.equinox.http" ).artifactId( "servlet" ).versionAsInProject().start()
|
||||
)));
|
||||
return options.toArray(new Option[options.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* You will get a list of bundles installed by default
|
||||
* plus your testcase, wrapped into a bundle called pax-exam-probe
|
||||
*/
|
||||
@Test
|
||||
public void testHttpService() throws Exception
|
||||
{
|
||||
// ServletContextHandler sch = null;
|
||||
// sch.addServlet("className", "pathSpec").setInitOrder("0");
|
||||
|
||||
|
||||
Map<String,Bundle> bundlesIndexedBySymbolicName = new HashMap<String, Bundle>();
|
||||
for( Bundle b : bundleContext.getBundles() )
|
||||
{
|
||||
bundlesIndexedBySymbolicName.put(b.getSymbolicName(), b);
|
||||
//System.err.println("got " + b.getSymbolicName());
|
||||
}
|
||||
Bundle osgiBoot = bundlesIndexedBySymbolicName.get("org.eclipse.jetty.osgi.boot");
|
||||
Assert.assertNotNull("Could not find the org.eclipse.jetty.osgi.boot bundle", osgiBoot);
|
||||
Assert.assertTrue(osgiBoot.getState() == Bundle.ACTIVE);
|
||||
|
||||
Bundle httpServiceOSGiBundle = bundlesIndexedBySymbolicName.get("org.eclipse.jetty.osgi.httpservice");
|
||||
Assert.assertNotNull(httpServiceOSGiBundle);
|
||||
Assert.assertTrue(httpServiceOSGiBundle.getState() == Bundle.ACTIVE);
|
||||
|
||||
Bundle equinoxServlet = bundlesIndexedBySymbolicName.get("org.eclipse.equinox.http.servlet");
|
||||
Assert.assertNotNull(equinoxServlet);
|
||||
//interestingly with equinox the bundle is not started. probably a difference in pax-exam and
|
||||
//the way the bundles are activated. the rest of the test goes fine.
|
||||
Assert.assertTrue(equinoxServlet.getState() == Bundle.ACTIVE);
|
||||
|
||||
//in the OSGi world this would be bad code and we should use a bundle tracker.
|
||||
//here we purposely want to make sure that the httpService is actually ready.
|
||||
ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
|
||||
Assert.assertNotNull("The httpServiceOSGiBundle is started and should have deployed a service reference for HttpService" ,sr);
|
||||
HttpService http = (HttpService)bundleContext.getService(sr);
|
||||
http.registerServlet("/greetings", new HttpServlet() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req,
|
||||
HttpServletResponse resp) throws ServletException,
|
||||
IOException {
|
||||
resp.getWriter().write("Hello");
|
||||
}
|
||||
}, null, null);
|
||||
|
||||
//now test the servlet
|
||||
HttpClient client = new HttpClient();
|
||||
try
|
||||
{
|
||||
client.start();
|
||||
Response response = client.GET("http://127.0.0.1:9876/greetings").get(5, TimeUnit.SECONDS);;
|
||||
Assert.assertEquals(HttpStatus.OK_200, response.status());
|
||||
|
||||
String content = new String(((HttpContentResponse)response).content());
|
||||
Assert.assertEquals("Hello", content);
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,172 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.osgi.boot;
|
||||
|
||||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.options;
|
||||
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.HttpContentResponse;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.ops4j.pax.exam.CoreOptions;
|
||||
import org.ops4j.pax.exam.Inject;
|
||||
import org.ops4j.pax.exam.Option;
|
||||
import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
|
||||
import org.ops4j.pax.exam.junit.Configuration;
|
||||
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
* Pax-Exam to make sure the jetty-osgi-boot can be started along with the httpservice web-bundle.
|
||||
* Then make sure we can deploy an OSGi service on the top of this.
|
||||
*/
|
||||
@RunWith( JUnit4TestRunner.class )
|
||||
public class TestJettyOSGiBootWithJsp
|
||||
{
|
||||
private static final boolean LOGGING_ENABLED = true;
|
||||
private static final boolean REMOTE_DEBUGGING = false;
|
||||
|
||||
@Inject
|
||||
BundleContext bundleContext = null;
|
||||
|
||||
@Configuration
|
||||
public static Option[] configure()
|
||||
{
|
||||
File etcFolder = new File("src/test/config/etc");
|
||||
String etc = "file://" + etcFolder.getAbsolutePath();
|
||||
|
||||
ArrayList<Option> options = new ArrayList<Option>();
|
||||
options.add(PaxRunnerOptions.vmOption("-Djetty.port=9876 -Djetty.home="+ etcFolder.getParentFile().getAbsolutePath() +
|
||||
" -D" + OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS +
|
||||
"="+etc+"/jetty.xml;"+etc+"/jetty-selector.xml;"+etc+"/jetty-deployer.xml;" + etc + "/jetty-testrealm.xml"));
|
||||
options.add(CoreOptions.equinox());
|
||||
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*",
|
||||
"org.w3c.*", "javax.xml.*"));
|
||||
options.addAll(TestJettyOSGiBootCore.coreJettyDependencies());
|
||||
|
||||
// Enable Logging
|
||||
if(LOGGING_ENABLED) {
|
||||
options.addAll(Arrays.asList(options(
|
||||
// install log service using pax runners profile abstraction (there are more profiles, like DS)
|
||||
// logProfile(),
|
||||
// this is how you set the default log level when using pax logging (logProfile)
|
||||
systemProperty( "org.ops4j.pax.logging.DefaultServiceLog.level" ).value( "INFO" )
|
||||
)));
|
||||
}
|
||||
|
||||
options.addAll(jspDependencies());
|
||||
|
||||
// Remote JDWP Debugging
|
||||
if(REMOTE_DEBUGGING) {
|
||||
options.addAll(Arrays.asList(options(
|
||||
// this just adds all what you write here to java vm argumenents of the (new) osgi process.
|
||||
PaxRunnerOptions.vmOption( "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006" )
|
||||
)));
|
||||
}
|
||||
|
||||
return options.toArray(new Option[options.size()]);
|
||||
}
|
||||
|
||||
public static List<Option> jspDependencies() {
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
/* orbit deps */
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.servlet.jsp" ).versionAsInProject());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.servlet.jsp.jstl" ).versionAsInProject());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.el" ).versionAsInProject());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "com.sun.el" ).versionAsInProject());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "org.apache.jasper.glassfish" ).versionAsInProject());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "org.apache.taglibs.standard.glassfish" ).versionAsInProject());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "org.eclipse.jdt.core" ).versionAsInProject());
|
||||
|
||||
/* jetty-osgi deps */
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-osgi-boot-jsp" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-osgi-boot" ).versionAsInProject().start());
|
||||
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "test-jetty-webapp" ).classifier("webbundle").versionAsInProject());
|
||||
|
||||
res.add(mavenBundle().groupId( "org.eclipse.equinox.http" ).artifactId( "servlet" ).versionAsInProject().start());
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* You will get a list of bundles installed by default
|
||||
* plus your testcase, wrapped into a bundle called pax-exam-probe
|
||||
*/
|
||||
@Test
|
||||
public void listBundles() throws Exception
|
||||
{
|
||||
Map<String,Bundle> bundlesIndexedBySymbolicName = new HashMap<String, Bundle>();
|
||||
for( Bundle b : bundleContext.getBundles() )
|
||||
{
|
||||
bundlesIndexedBySymbolicName.put(b.getSymbolicName(), b);
|
||||
}
|
||||
Bundle websocketServer = bundlesIndexedBySymbolicName.get("org.eclipse.jetty.websocket.server");
|
||||
Assert.assertNotNull("Could not find the org.eclipse.jetty.websocket.server bundle", websocketServer);
|
||||
Assert.assertEquals(Bundle.RESOLVED, websocketServer.getState());
|
||||
|
||||
Bundle osgiBoot = bundlesIndexedBySymbolicName.get("org.eclipse.jetty.osgi.boot");
|
||||
Assert.assertNotNull("Could not find the org.eclipse.jetty.osgi.boot bundle", osgiBoot);
|
||||
Assert.assertEquals(Bundle.ACTIVE, osgiBoot.getState());
|
||||
|
||||
Bundle osgiBootJsp = bundlesIndexedBySymbolicName.get("org.eclipse.jetty.osgi.boot.jsp");
|
||||
Assert.assertNotNull("Could not find the org.eclipse.jetty.osgi.boot.jsp bundle", osgiBootJsp);
|
||||
Assert.assertEquals("The fragment jsp is not correctly resolved.",
|
||||
Bundle.RESOLVED, osgiBootJsp.getState());
|
||||
|
||||
Bundle testWebBundle = bundlesIndexedBySymbolicName.get("org.eclipse.jetty.test-jetty-webapp");
|
||||
Assert.assertNotNull("Could not find the org.eclipse.jetty.test-jetty-webappp bundle", osgiBootJsp);
|
||||
Assert.assertEquals("The test-jetty-webapp is not correctly resolved", Bundle.ACTIVE, testWebBundle.getState());
|
||||
|
||||
//now test the jsp/dump.jsp
|
||||
HttpClient client = new HttpClient();
|
||||
try
|
||||
{
|
||||
client.start();
|
||||
Response response = client.GET("http://127.0.0.1:9876/jsp/dump.jsp").get(5, TimeUnit.SECONDS);
|
||||
Assert.assertEquals(HttpStatus.OK_200, response.status());
|
||||
|
||||
String content = new String(((HttpContentResponse)response).content());
|
||||
//System.err.println("content: " + content);
|
||||
Assert.assertTrue(content.indexOf("<tr><th>ServletPath:</th><td>/jsp/dump.jsp</td></tr>") != -1);
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,188 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
package org.eclipse.jetty.osgi.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.HttpContentResponse;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.junit.Assert;
|
||||
import org.ops4j.pax.exam.CoreOptions;
|
||||
import org.ops4j.pax.exam.Option;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.service.http.HttpService;
|
||||
|
||||
public class AbstractTestOSGi
|
||||
{
|
||||
|
||||
private Map<String,Bundle> _bundles;
|
||||
|
||||
/**
|
||||
* Note: this will run many more tests.
|
||||
* TODO: find a better way to control this and use non-deprecated methods.
|
||||
* @param options
|
||||
*/
|
||||
protected static void addMoreOSGiContainers(List<Option> options)
|
||||
{
|
||||
options.add(CoreOptions.equinox().version("3.6.1"));
|
||||
options.add(CoreOptions.equinox().version("3.7.1"));
|
||||
options.add(CoreOptions.felix().version("3.2.2"));
|
||||
options.add(CoreOptions.felix().version("4.0.2"));
|
||||
}
|
||||
|
||||
protected Bundle getBundle(BundleContext bundleContext, String symbolicName)
|
||||
{
|
||||
if (_bundles == null)
|
||||
{
|
||||
_bundles = new HashMap<String,Bundle>();
|
||||
for (Bundle b : bundleContext.getBundles())
|
||||
{
|
||||
Bundle prevBundle = _bundles.put(b.getSymbolicName(), b);
|
||||
String err = prevBundle != null ? "2 versions of the bundle " + b.getSymbolicName() +
|
||||
" " + b.getHeaders().get("Bundle-Version") +
|
||||
" and " + prevBundle.getHeaders().get("Bundle-Version")
|
||||
: "";
|
||||
Assert.assertNull(err, prevBundle);
|
||||
}
|
||||
}
|
||||
return _bundles.get(symbolicName);
|
||||
}
|
||||
|
||||
protected void assertActiveBundle(BundleContext bundleContext, String symbolicName) throws Exception
|
||||
{
|
||||
Bundle b = getBundle(bundleContext, symbolicName);
|
||||
Assert.assertNotNull(b);
|
||||
Assert.assertEquals(b.getSymbolicName()+" must be active.", Bundle.ACTIVE, b.getState());
|
||||
}
|
||||
|
||||
protected void assertActiveOrResolvedBundle(BundleContext bundleContext, String symbolicName) throws Exception
|
||||
{
|
||||
Bundle b = getBundle(bundleContext, symbolicName);
|
||||
Assert.assertNotNull(b);
|
||||
if (b.getHeaders().get("Fragment-Host") == null) diagnoseNonActiveOrNonResolvedBundle(b);
|
||||
Assert.assertTrue(b.getSymbolicName()+" must be active or resolved. It was "+b.getState(),
|
||||
b.getState() == Bundle.ACTIVE || b.getState() == Bundle.RESOLVED);
|
||||
}
|
||||
|
||||
protected void assertAllBundlesActiveOrResolved(BundleContext bundleContext)
|
||||
{
|
||||
for (Bundle b : bundleContext.getBundles())
|
||||
{
|
||||
if (b.getState() == Bundle.INSTALLED)
|
||||
{
|
||||
diagnoseNonActiveOrNonResolvedBundle(b);
|
||||
}
|
||||
Assert.assertTrue(b.getState() == Bundle.ACTIVE || b.getState() == Bundle.RESOLVED);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean diagnoseNonActiveOrNonResolvedBundle(Bundle b)
|
||||
{
|
||||
if (b.getState() != Bundle.ACTIVE && b.getHeaders().get("Fragment-Host") == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.err.println("Trying to start the bundle "+b.getSymbolicName()+
|
||||
" that was supposed to be active or resolved.");
|
||||
b.start();
|
||||
System.err.println(b.getSymbolicName() + " did start");
|
||||
return true;
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
System.err.println(b.getSymbolicName() + " failed to start");
|
||||
t.printStackTrace(System.err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
System.err.println(b.getSymbolicName() + " was already started");
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void debugBundles(BundleContext bundleContext)
|
||||
{
|
||||
Map<String,Bundle> bundlesIndexedBySymbolicName = new HashMap<String, Bundle>();
|
||||
System.err.println("Active " + Bundle.ACTIVE);
|
||||
System.err.println("RESOLVED " + Bundle.RESOLVED);
|
||||
System.err.println("INSTALLED " + Bundle.INSTALLED);
|
||||
for( Bundle b : bundleContext.getBundles() )
|
||||
{
|
||||
bundlesIndexedBySymbolicName.put(b.getSymbolicName(), b);
|
||||
System.err.println(" " + b.getSymbolicName() + " " + b.getState());
|
||||
}
|
||||
}
|
||||
|
||||
protected SslContextFactory getSslContextFactory()
|
||||
{
|
||||
return new SslContextFactory(true);
|
||||
}
|
||||
|
||||
protected void testHttpServiceGreetings(BundleContext bundleContext, String protocol, int port) throws Exception
|
||||
{
|
||||
assertActiveBundle(bundleContext, "org.eclipse.jetty.osgi.boot");
|
||||
|
||||
assertActiveBundle(bundleContext, "org.eclipse.jetty.osgi.httpservice");
|
||||
assertActiveBundle(bundleContext, "org.eclipse.equinox.http.servlet");
|
||||
|
||||
//in the OSGi world this would be bad code and we should use a bundle tracker.
|
||||
//here we purposely want to make sure that the httpService is actually ready.
|
||||
ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
|
||||
Assert.assertNotNull("The httpServiceOSGiBundle is started and should " +
|
||||
"have deployed a service reference for HttpService" ,sr);
|
||||
HttpService http = (HttpService)bundleContext.getService(sr);
|
||||
http.registerServlet("/greetings", new HttpServlet() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req,
|
||||
HttpServletResponse resp) throws ServletException,
|
||||
IOException {
|
||||
resp.getWriter().write("Hello");
|
||||
}
|
||||
}, null, null);
|
||||
|
||||
//now test the servlet
|
||||
HttpClient client = protocol.equals("https") ? new HttpClient(getSslContextFactory()) : new HttpClient();
|
||||
try
|
||||
{
|
||||
client.start();
|
||||
Response response = client.GET(protocol+"://127.0.0.1:"+port+"/greetings").get(5, TimeUnit.SECONDS);;
|
||||
Assert.assertEquals(HttpStatus.OK_200, response.status());
|
||||
|
||||
String content = new String(((HttpContentResponse)response).content());
|
||||
Assert.assertEquals("Hello", content);
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
package org.eclipse.jetty.osgi.test;
|
||||
|
||||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.ops4j.pax.exam.CoreOptions;
|
||||
import org.ops4j.pax.exam.Option;
|
||||
import org.ops4j.pax.exam.junit.Configuration;
|
||||
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
|
||||
import org.osgi.framework.BundleContext;
|
||||
//import org.eclipse.jetty.osgi.boot.internal.serverfactory.DefaultJettyAtJettyHomeHelper;
|
||||
@RunWith( JUnit4TestRunner.class )
|
||||
//@ExamReactorStrategy( AllConfinedStagedReactorFactory.class )
|
||||
public class TestJettyOSGiBootCore extends AbstractTestOSGi {
|
||||
|
||||
public static int DEFAULT_JETTY_HTTP_PORT = 9876;
|
||||
|
||||
@Inject
|
||||
private BundleContext bundleContext;
|
||||
|
||||
@Configuration
|
||||
public Option[] config()
|
||||
{
|
||||
ArrayList<Option> options = new ArrayList<Option>();
|
||||
addMoreOSGiContainers(options);
|
||||
options.addAll(provisionCoreJetty());
|
||||
options.add(CoreOptions.junitBundles());
|
||||
options.addAll(httpServiceJetty());
|
||||
return options.toArray(new Option[options.size()]);
|
||||
}
|
||||
|
||||
public static List<Option> provisionCoreJetty()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
// get the jetty home config from the osgi boot bundle.
|
||||
res.add(CoreOptions.systemProperty("jetty.port").value(String.valueOf(DEFAULT_JETTY_HTTP_PORT)));
|
||||
res.add(CoreOptions.systemProperty("jetty.home.bundle").value("org.eclipse.jetty.osgi.boot"));
|
||||
res.addAll(coreJettyDependencies());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
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.eclipse.jetty.orbit" ).artifactId( "javax.servlet" ).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());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-util" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-http" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-xml" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-webapp" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-io" ).versionAsInProject().noStart());
|
||||
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.websocket" ).artifactId( "websocket-core" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-server" ).versionAsInProject().noStart());
|
||||
//optional:
|
||||
//res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-client" ).versionAsInProject().noStart());
|
||||
return res;
|
||||
}
|
||||
|
||||
public static List<Option> httpServiceJetty()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-httpservice" ).versionAsInProject().start());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.equinox.http" ).artifactId( "servlet" ).versionAsInProject().start());
|
||||
return res;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertAllBundlesActiveOrResolved()
|
||||
{
|
||||
assertAllBundlesActiveOrResolved(bundleContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* You will get a list of bundles installed by default
|
||||
* plus your testcase, wrapped into a bundle called pax-exam-probe
|
||||
*/
|
||||
@Test
|
||||
public void testHttpService() throws Exception
|
||||
{
|
||||
testHttpServiceGreetings(bundleContext, "http", DEFAULT_JETTY_HTTP_PORT);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
package org.eclipse.jetty.osgi.test;
|
||||
|
||||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.ops4j.pax.exam.CoreOptions;
|
||||
import org.ops4j.pax.exam.Option;
|
||||
import org.ops4j.pax.exam.junit.Configuration;
|
||||
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
@RunWith( JUnit4TestRunner.class )
|
||||
//@ExamReactorStrategy( AllConfinedStagedReactorFactory.class )
|
||||
public class TestJettyOSGiBootSpdy extends AbstractTestOSGi {
|
||||
|
||||
private static final String JETTY_SPDY_PORT = "jetty.spdy.port";
|
||||
private static final int DEFAULT_JETTY_SPDY_PORT = 9877;
|
||||
|
||||
@Inject
|
||||
private BundleContext bundleContext;
|
||||
|
||||
@Configuration
|
||||
public Option[] config()
|
||||
{
|
||||
ArrayList<Option> options = new ArrayList<Option>();
|
||||
|
||||
addMoreOSGiContainers(options);
|
||||
|
||||
options.addAll(TestJettyOSGiBootCore.provisionCoreJetty());
|
||||
options.addAll(TestJettyOSGiBootWithJsp.configureJettyHomeAndPort("jetty-spdy.xml"));
|
||||
options.add(CoreOptions.junitBundles());
|
||||
options.addAll(TestJettyOSGiBootCore.httpServiceJetty());
|
||||
options.addAll(spdyJettyDependencies());
|
||||
return options.toArray(new Option[options.size()]);
|
||||
}
|
||||
|
||||
public static List<Option> spdyJettyDependencies()
|
||||
{
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
res.add(CoreOptions.systemProperty(JETTY_SPDY_PORT).value(String.valueOf(DEFAULT_JETTY_SPDY_PORT)));
|
||||
//java -Xbootclasspath/p:${settings.localRepository}/org/mortbay/jetty/npn/npn-boot/${npn-version}/npn-boot-${npn-version}.jar
|
||||
// res.add(CoreOptions.vmOptions("-Xbootclasspath/p:"+System.getenv("HOME")+"/.m2/repository/org/mortbay/jetty/npn/npn-boot/"+npnBootVersion+"/npn-boot-"+npnBootVersion+".jar"));
|
||||
String npnBoot = System.getProperty("mortbay-npn-boot");
|
||||
if (npnBoot == null)
|
||||
{
|
||||
throw new IllegalStateException("Please define the path to the npn boot jar as the sys property -Dmortbay-npn-boot");
|
||||
//are we trying to be too nice? this kinds of work outside of maven maybe
|
||||
// String npnBootUrl = mavenBundle().groupId( "org.mortbay.jetty.npn" ).artifactId( "npn-boot" ).versionAsInProject().getURL();
|
||||
// String npnBootVersion = npnBootUrl.split("\\/")[2];
|
||||
// if (!Character.isDigit(npnBootVersion.charAt(0)))
|
||||
// {
|
||||
// throw new IllegalArgumentException(npnBootUrl + " - " + npnBootVersion);
|
||||
// }
|
||||
// npnBoot = System.getenv("HOME")+"/.m2/repository/org/mortbay/jetty/npn/npn-boot/"+npnBootVersion+"/npn-boot-"+npnBootVersion+".jar";
|
||||
}
|
||||
File checkNpnBoot = new File(npnBoot);
|
||||
if (!checkNpnBoot.exists())
|
||||
{
|
||||
throw new IllegalStateException("Unable to find the npn boot jar here: " + npnBoot);
|
||||
}
|
||||
|
||||
res.add(CoreOptions.vmOptions("-Xbootclasspath/p:"+npnBoot));
|
||||
// res.add(CoreOptions.vmOptions("-Xbootclasspath/p:"+"target/npn/npn-boot-"+npnBootVersion+".jar"));
|
||||
res.add(CoreOptions.bootDelegationPackages("org.eclipse.jetty.npn"));
|
||||
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.spdy" ).artifactId( "spdy-core" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.spdy" ).artifactId( "spdy-server" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.spdy" ).artifactId( "spdy-http-server" ).versionAsInProject().noStart());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.spdy" ).artifactId( "spdy-client" ).versionAsInProject().noStart());
|
||||
return res;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkNpnBootOnBootstrapClasspath() throws Exception
|
||||
{
|
||||
Class<?> npn = Thread.currentThread().getContextClassLoader()
|
||||
.loadClass("org.eclipse.jetty.npn.NextProtoNego");
|
||||
Assert.assertNotNull(npn);
|
||||
Assert.assertNull(npn.getClassLoader());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertAllBundlesActiveOrResolved()
|
||||
{
|
||||
assertAllBundlesActiveOrResolved(bundleContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* This does not work yet.
|
||||
*/
|
||||
//@Ignore
|
||||
@Test
|
||||
public void testSpdyOnHttpService() throws Exception
|
||||
{
|
||||
testHttpServiceGreetings(bundleContext, "https", DEFAULT_JETTY_SPDY_PORT);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.osgi.test;
|
||||
|
||||
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
|
||||
import static org.ops4j.pax.exam.CoreOptions.options;
|
||||
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.HttpContentResponse;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.ops4j.pax.exam.CoreOptions;
|
||||
import org.ops4j.pax.exam.Option;
|
||||
import org.ops4j.pax.exam.junit.Configuration;
|
||||
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
* Pax-Exam to make sure the jetty-osgi-boot can be started along with the httpservice web-bundle.
|
||||
* Then make sure we can deploy an OSGi service on the top of this.
|
||||
*/
|
||||
@RunWith( JUnit4TestRunner.class )
|
||||
//@ExamReactorStrategy( AllConfinedStagedReactorFactory.class )
|
||||
public class TestJettyOSGiBootWithJsp extends AbstractTestOSGi
|
||||
{
|
||||
private static final boolean LOGGING_ENABLED = true;
|
||||
private static final boolean REMOTE_DEBUGGING = false;
|
||||
|
||||
@Inject
|
||||
BundleContext bundleContext = null;
|
||||
|
||||
@Configuration
|
||||
public static Option[] configure()
|
||||
{
|
||||
|
||||
ArrayList<Option> options = new ArrayList<Option>();
|
||||
|
||||
addMoreOSGiContainers(options);
|
||||
|
||||
options.add(CoreOptions.junitBundles());
|
||||
options.addAll(configureJettyHomeAndPort("jetty-selector.xml"));
|
||||
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*",
|
||||
"org.w3c.*", "javax.xml.*"));
|
||||
options.addAll(TestJettyOSGiBootCore.coreJettyDependencies());
|
||||
|
||||
// Enable Logging
|
||||
if(LOGGING_ENABLED) {
|
||||
options.addAll(Arrays.asList(options(
|
||||
// install log service using pax runners profile abstraction (there are more profiles, like DS)
|
||||
// logProfile(),
|
||||
// this is how you set the default log level when using pax logging (logProfile)
|
||||
systemProperty( "org.ops4j.pax.logging.DefaultServiceLog.level" ).value( "INFO" )
|
||||
)));
|
||||
}
|
||||
|
||||
options.addAll(jspDependencies());
|
||||
|
||||
// Remote JDWP Debugging, this won't work with the forked container.
|
||||
// if(REMOTE_DEBUGGING) {
|
||||
// options.addAll(Arrays.asList(options(
|
||||
// // this just adds all what you write here to java vm argumenents of the (new) osgi process.
|
||||
// PaxRunnerOptions.vmOption( "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006" )
|
||||
// )));
|
||||
// }
|
||||
|
||||
//bug at the moment: this would make the httpservice catch all
|
||||
//requests and prevent the webapp at the root context to catch any of them.
|
||||
//options.addAll(TestJettyOSGiBootCore.httpServiceJetty());
|
||||
|
||||
return options.toArray(new Option[options.size()]);
|
||||
}
|
||||
|
||||
public static List<Option> configureJettyHomeAndPort(String jettySelectorFileName)
|
||||
{
|
||||
File etcFolder = new File("src/test/config/etc");
|
||||
String etc = "file://" + etcFolder.getAbsolutePath();
|
||||
List<Option> options = new ArrayList<Option>();
|
||||
options.add(systemProperty(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS)
|
||||
.value(etc + "/jetty.xml;" +
|
||||
etc + "/" + jettySelectorFileName + ";" +
|
||||
etc + "/jetty-deployer.xml;" +
|
||||
etc + "/jetty-testrealm.xml"));
|
||||
options.add(systemProperty("jetty.port").value(String.valueOf(TestJettyOSGiBootCore.DEFAULT_JETTY_HTTP_PORT)));
|
||||
options.add(systemProperty("jetty.home").value(etcFolder.getParentFile().getAbsolutePath()));
|
||||
return options;
|
||||
}
|
||||
|
||||
public static List<Option> jspDependencies() {
|
||||
List<Option> res = new ArrayList<Option>();
|
||||
/* orbit deps */
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.servlet.jsp" ).versionAsInProject());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.servlet.jsp.jstl" ).versionAsInProject());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.el" ).versionAsInProject());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "com.sun.el" ).versionAsInProject());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "org.apache.jasper.glassfish" ).versionAsInProject());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "org.apache.taglibs.standard.glassfish" ).versionAsInProject());
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "org.eclipse.jdt.core" ).versionAsInProject());
|
||||
|
||||
/* jetty-osgi deps */
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-osgi-boot-jsp" ).versionAsInProject().noStart());
|
||||
|
||||
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "test-jetty-webapp" ).classifier("webbundle").versionAsInProject());
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertAllBundlesActiveOrResolved()
|
||||
{
|
||||
assertAllBundlesActiveOrResolved(bundleContext);
|
||||
}
|
||||
|
||||
//at the moment can't run httpservice with jsp at the same time.
|
||||
//that is a regression in jetty-9
|
||||
@Ignore
|
||||
@Test
|
||||
public void testHttpService() throws Exception
|
||||
{
|
||||
super.testHttpServiceGreetings(bundleContext, "http", TestJettyOSGiBootCore.DEFAULT_JETTY_HTTP_PORT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJspDump() throws Exception
|
||||
{
|
||||
|
||||
//System.err.println("http://127.0.0.1:9876/jsp/dump.jsp sleeping....");
|
||||
//Thread.currentThread().sleep(5000000);
|
||||
//now test the jsp/dump.jsp
|
||||
HttpClient client = new HttpClient();
|
||||
try
|
||||
{
|
||||
client.start();
|
||||
Response response = client.GET("http://127.0.0.1:"+
|
||||
TestJettyOSGiBootCore.DEFAULT_JETTY_HTTP_PORT+"/jsp/dump.jsp").get(5, TimeUnit.SECONDS);
|
||||
Assert.assertEquals(HttpStatus.OK_200, response.status());
|
||||
|
||||
String content = new String(((HttpContentResponse)response).content());
|
||||
//System.err.println("content: " + content);
|
||||
Assert.assertTrue(content.indexOf("<tr><th>ServletPath:</th><td>/jsp/dump.jsp</td></tr>") != -1);
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -28,7 +28,9 @@
|
|||
<configuration>
|
||||
<instructions>
|
||||
<_versionpolicy> </_versionpolicy>
|
||||
<Import-Package>javax.sql.*,javax.security.*,javax.naming.*,javax.servlet.*;version="2.6.0",javax.transaction.*;version="[1.1,1.2)",*</Import-Package>
|
||||
<Import-Package>javax.sql.*,javax.security.*,javax.naming.*,
|
||||
javax.servlet.*;version="2.6.0",javax.transaction.*;version="[1.1,1.2)",
|
||||
*</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
<instructions>
|
||||
<Export-Package>org.eclipse.jetty.spdy.*;version="9.0"</Export-Package>
|
||||
<Import-Package>org.eclipse.jetty.*;version="[9.0,10.0)",*</Import-Package>
|
||||
<_nouses>true</_nouses>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<argLine>-Xbootclasspath/p:${project.build.directory}/npn/npn-boot-${npn.version}.jar</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- <plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
|
@ -57,21 +57,13 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Export-Package>*</Export-Package>
|
||||
<Export-Package>org.eclipse.jetty.spdy.client;version="9.0"</Export-Package>
|
||||
<Import-Package>!org.eclipse.jetty.npn,org.eclipse.jetty.*;version="[9.0,10.0)",*</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>-->
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
|
|
@ -14,38 +14,6 @@
|
|||
<bundle-symbolic-name>${project.groupId}.core</bundle-symbolic-name>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- <plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>manifest</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Import-Package>javax.net.*,*</Import-Package>
|
||||
<Export-Package>*</Export-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>-->
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
|
|
|
@ -48,12 +48,18 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>manifest</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Import-Package>org.eclipse.jetty.npn;version="0";resolution:=optional,*</Import-Package>
|
||||
<Export-Package>*</Export-Package>
|
||||
<Export-Package>org.eclipse.jetty.spdy.server.http;version="9.0",
|
||||
org.eclipse.jetty.spdy.server.proxy;version="9.0"</Export-Package>
|
||||
<Import-Package>!org.eclipse.jetty.npn,org.eclipse.jetty.*;version="[9.0,10.0)",*</Import-Package>
|
||||
<_nouses>true</_nouses>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<argLine>-Xbootclasspath/p:${project.build.directory}/npn/npn-boot-${npn.version}.jar</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- <plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
|
@ -57,22 +57,14 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Import-Package>javax.net.ssl.*,*</Import-Package>
|
||||
<Export-Package>*</Export-Package>
|
||||
<Export-Package>org.eclipse.jetty.spdy.server;version="9.0"</Export-Package>
|
||||
<Import-Package>!org.eclipse.jetty.npn,org.eclipse.jetty.*;version="[9.0,10.0)",*</Import-Package>
|
||||
<_nouses>true</_nouses>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin> -->
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
|
Loading…
Reference in New Issue