Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugues Malphettes2012-09-24 05:04:57 +0000
committerHugues Malphettes2012-09-24 05:04:57 +0000
commit1cfa277c6c55252022227c9f1ee2bae8c49c9595 (patch)
treeea1ee6f148afc5e6274073413ba425ab4d764be2 /jetty-osgi/test-jetty-osgi
parent96dc4fe15080b3a456acf9c00d85b0ec8b6e8b0c (diff)
downloadorg.eclipse.jetty.project-1cfa277c6c55252022227c9f1ee2bae8c49c9595.tar.gz
org.eclipse.jetty.project-1cfa277c6c55252022227c9f1ee2bae8c49c9595.tar.xz
org.eclipse.jetty.project-1cfa277c6c55252022227c9f1ee2bae8c49c9595.zip
jetty-9 osgi support
Diffstat (limited to 'jetty-osgi/test-jetty-osgi')
-rw-r--r--jetty-osgi/test-jetty-osgi/pom.xml55
-rw-r--r--jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-deployer.xml40
-rw-r--r--jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-selector.xml22
-rw-r--r--jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty.xml71
-rw-r--r--jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/boot/TestJettyOSGiBootCore.java94
-rw-r--r--jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/boot/TestJettyOSGiBootWithJsp.java123
6 files changed, 288 insertions, 117 deletions
diff --git a/jetty-osgi/test-jetty-osgi/pom.xml b/jetty-osgi/test-jetty-osgi/pom.xml
index b36ae6c4ef..905b7e8a5b 100644
--- a/jetty-osgi/test-jetty-osgi/pom.xml
+++ b/jetty-osgi/test-jetty-osgi/pom.xml
@@ -13,7 +13,8 @@
<bundle-symbolic-name>${project.groupId}.boot.test</bundle-symbolic-name>
<jetty-orbit-url>http://download.eclipse.org/jetty/orbit/</jetty-orbit-url>
<assembly-directory>target/distribution</assembly-directory>
- <paxexam-version>1.2.0</paxexam-version>
+ <paxexam-version-old>1.2.0</paxexam-version-old>
+ <paxexam-version>1.2.4</paxexam-version>
</properties>
<dependencies>
<!-- Orbit Servlet Deps -->
@@ -78,6 +79,12 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-security</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
@@ -99,8 +106,21 @@
<scope>runtime</scope>
</dependency>
<dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-websocket</artifactId>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-client</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-core</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-server</artifactId>
+ <version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
@@ -120,13 +140,20 @@
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi.services</artifactId>
<scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <!-- we use the servlet jar from orbit -->
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.equinox.http</groupId>
<artifactId>servlet</artifactId>
<scope>runtime</scope>
</dependency>
-
+
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>test-jetty-webapp</artifactId>
@@ -134,7 +161,7 @@
<classifier>webbundle</classifier>
<scope>test</scope>
</dependency>
-
+
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
@@ -146,13 +173,13 @@
<artifactId>pax-exam-junit</artifactId>
<version>${paxexam-version}</version>
<scope>test</scope>
- <exclusion>
+ <exclusions>
<exclusion>
<!-- we use junit-dep -->
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
- </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
@@ -165,6 +192,18 @@
<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>
@@ -207,7 +246,7 @@
<version>${orbit-servlet-api-version}</version>
<overWrite>true</overWrite>
<outputDirectory>${assembly-directory}/lib</outputDirectory>
- <destFileName>servlet-api-2.5.jar</destFileName>
+ <destFileName>servlet-api-3.0.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
diff --git a/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-deployer.xml b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-deployer.xml
new file mode 100644
index 0000000000..99c4d74a10
--- /dev/null
+++ b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-deployer.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
+
+<Configure id="Server" class="org.eclipse.jetty.server.Server">
+
+ <!-- =========================================================== -->
+ <!-- Configure the deployment manager -->
+ <!-- =========================================================== -->
+ <Call name="addBean">
+ <Arg>
+ <New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
+ <Set name="contexts">
+ <Ref id="Contexts" />
+ </Set>
+ <Call name="setContextAttribute">
+ <Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
+ <Arg>.*/jsp-api-[^/]*\.jar$|.*/jsp-[^/]*\.jar$</Arg>
+ </Call>
+ <!-- Providers of OSGi Apps -->
+ <Call name="addAppProvider">
+ <Arg>
+ <New class="org.eclipse.jetty.osgi.boot.OSGiAppProvider">
+ <!--
+ <Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
+ -->
+ <Set name="scanInterval">0</Set>
+ <Set name="contextXmlDir"><Property name="jetty.home" default="." />/contexts</Set>
+ <!-- comma separated list of bundle symbolic names that contain custom tag libraries (*.tld files) -->
+ <!-- if those bundles don't exist or can't be loaded no errors or warning will be issued! -->
+ <!-- This default value plugs in the tld files of the reference implementation of JSF -->
+ <Set name="tldBundles"><Property name="org.eclipse.jetty.osgi.tldbundles" default="javax.faces.jsf-impl" /></Set>
+ </New>
+ </Arg>
+ </Call>
+
+ </New>
+ </Arg>
+ </Call>
+
+</Configure>
diff --git a/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-selector.xml b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-selector.xml
new file mode 100644
index 0000000000..4fd87d38b1
--- /dev/null
+++ b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty-selector.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
+
+<Configure id="Server" class="org.eclipse.jetty.server.Server">
+
+
+ <!-- =========================================================== -->
+ <!-- Add connector -->
+ <!-- =========================================================== -->
+
+ <Call name="addConnector">
+ <Arg>
+ <New class="org.eclipse.jetty.server.ServerConnector">
+ <Arg><Ref id="Server" /></Arg>
+ <Set name="host"><Property name="jetty.host" /></Set>
+ <Set name="port"><Property name="jetty.port" default="8080"/></Set>
+ <Set name="idleTimeout">300000</Set>
+ </New>
+ </Arg>
+ </Call>
+
+</Configure>
diff --git a/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty.xml b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty.xml
new file mode 100644
index 0000000000..6e7dd851a2
--- /dev/null
+++ b/jetty-osgi/test-jetty-osgi/src/test/config/etc/jetty.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
+
+
+<!-- =============================================================== -->
+<!-- Configure the Jetty Server -->
+<!-- -->
+<!-- Documentation of this file format can be found at: -->
+<!-- http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax -->
+<!-- =============================================================== -->
+
+<Configure id="Server" class="org.eclipse.jetty.server.Server">
+
+ <!-- =========================================================== -->
+ <!-- Server Thread Pool -->
+ <!-- =========================================================== -->
+ <Arg name="threadPool">
+ <!-- Default queued blocking threadpool -->
+ <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
+ <Set name="minThreads">10</Set>
+ <Set name="maxThreads">200</Set>
+ </New>
+ </Arg>
+
+
+ <!-- =========================================================== -->
+ <!-- Set handler Collection Structure -->
+ <!-- =========================================================== -->
+ <Set name="handler">
+ <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
+ <Set name="handlers">
+ <Array type="org.eclipse.jetty.server.Handler">
+ <Item>
+ <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
+ </Item>
+ <Item>
+ <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
+ </Item>
+ <Item>
+ <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
+ </Item>
+ </Array>
+ </Set>
+ </New>
+ </Set>
+
+
+ <!-- =========================================================== -->
+ <!-- extra options -->
+ <!-- =========================================================== -->
+ <Set name="stopAtShutdown">true</Set>
+ <Set name="sendServerVersion">true</Set>
+ <Set name="sendDateHeader">true</Set>
+ <Set name="stopTimeout">1000</Set>
+ <Set name="dumpAfterStart">false</Set>
+ <Set name="dumpBeforeStop">false</Set>
+
+
+ <!-- =========================================================== -->
+ <!-- jetty-jndi by default -->
+ <!-- =========================================================== -->
+ <Call class="java.lang.System" name="setProperty">
+ <Arg>java.naming.factory.initial</Arg>
+ <Arg><Property name="java.naming.factory.initial" default="org.eclipse.jetty.jndi.InitialContextFactory"/></Arg>
+ </Call>
+ <Call class="java.lang.System" name="setProperty">
+ <Arg>java.naming.factory.url.pkgs</Arg>
+ <Arg><Property name="java.naming.factory.url.pkgs" default="org.eclipse.jetty.jndi"/></Arg>
+ </Call>
+
+</Configure>
diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/boot/TestJettyOSGiBootCore.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/boot/TestJettyOSGiBootCore.java
index ae794700d0..130df479ec 100644
--- a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/boot/TestJettyOSGiBootCore.java
+++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/boot/TestJettyOSGiBootCore.java
@@ -18,7 +18,8 @@
package org.eclipse.jetty.osgi.boot;
-import static org.ops4j.pax.exam.CoreOptions.*;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
import java.io.IOException;
import java.util.ArrayList;
@@ -26,6 +27,7 @@ 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;
@@ -34,14 +36,15 @@ import javax.servlet.http.HttpServletResponse;
import junit.framework.Assert;
-import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.client.HttpExchange;
-import org.eclipse.jetty.http.HttpMethods;
+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;
@@ -52,7 +55,6 @@ 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.
@@ -69,31 +71,39 @@ public class TestJettyOSGiBootCore
*/
public static List<Option> provisionCoreJetty()
{
- return Arrays.asList(options(
- // get the jetty home config from the osgi boot bundle.
- PaxRunnerOptions.vmOptions("-Djetty.port=9876 -D" + DefaultJettyAtJettyHomeHelper.SYS_PROP_JETTY_HOME_BUNDLE + "=org.eclipse.jetty.osgi.boot"),
-
- // CoreOptions.equinox(),
-
- mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.servlet" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.osgi" ).artifactId( "org.eclipse.osgi" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.osgi" ).artifactId( "org.eclipse.osgi.services" ).versionAsInProject().noStart(),
-
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-deploy" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-server" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-servlet" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-util" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-http" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-xml" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-webapp" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-io" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-continuation" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-security" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-websocket" ).versionAsInProject().noStart(),
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-servlets" ).versionAsInProject().noStart(),
-
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-client" ).versionAsInProject().noStart()
- ));
+ 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
@@ -109,7 +119,7 @@ public class TestJettyOSGiBootCore
// 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" ),
+ CoreOptions.systemProperty( "org.ops4j.pax.logging.DefaultServiceLog.level" ).value( "INFO" ),
// CoreOptions.equinox(), CoreOptions.felix(),//.version("3.0.0"),
@@ -136,7 +146,7 @@ public class TestJettyOSGiBootCore
for( Bundle b : bundleContext.getBundles() )
{
bundlesIndexedBySymbolicName.put(b.getSymbolicName(), b);
- System.err.println("got " + b.getSymbolicName());
+ //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);
@@ -163,31 +173,19 @@ public class TestJettyOSGiBootCore
protected void doGet(HttpServletRequest req,
HttpServletResponse resp) throws ServletException,
IOException {
- resp.getWriter().append("Hello");
+ resp.getWriter().write("Hello");
}
}, null, null);
//now test the servlet
HttpClient client = new HttpClient();
- client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
try
{
client.start();
-
- ContentExchange getExchange = new ContentExchange();
- getExchange.setURL("http://127.0.0.1:9876/greetings");
- getExchange.setMethod(HttpMethods.GET);
+ Response response = client.GET("http://127.0.0.1:9876/greetings").get(5, TimeUnit.SECONDS);;
+ Assert.assertEquals(HttpStatus.OK_200, response.status());
- client.send(getExchange);
- int state = getExchange.waitForDone();
- Assert.assertEquals("state should be done", HttpExchange.STATUS_COMPLETED, state);
-
- String content = null;
- int responseStatus = getExchange.getResponseStatus();
- Assert.assertEquals(HttpStatus.OK_200, responseStatus);
- if (responseStatus == HttpStatus.OK_200) {
- content = getExchange.getResponseContent();
- }
+ String content = new String(((HttpContentResponse)response).content());
Assert.assertEquals("Hello", content);
}
finally
diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/boot/TestJettyOSGiBootWithJsp.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/boot/TestJettyOSGiBootWithJsp.java
index 5879da9f82..3f552e74fb 100644
--- a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/boot/TestJettyOSGiBootWithJsp.java
+++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/boot/TestJettyOSGiBootWithJsp.java
@@ -18,24 +18,28 @@
package org.eclipse.jetty.osgi.boot;
-import static org.ops4j.pax.exam.CoreOptions.*;
+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.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.client.HttpExchange;
-import org.eclipse.jetty.http.HttpMethods;
+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;
@@ -51,20 +55,27 @@ import org.osgi.framework.BundleContext;
@RunWith( JUnit4TestRunner.class )
public class TestJettyOSGiBootWithJsp
{
- private static final boolean LOGGING_ENABLED = false;
+ private static final boolean LOGGING_ENABLED = true;
private static final boolean REMOTE_DEBUGGING = false;
-
+
@Inject
BundleContext bundleContext = null;
@Configuration
public static Option[] configure()
{
- File testrealm = new File("src/test/config/etc/jetty-testrealm.xml");
-
+ File etcFolder = new File("src/test/config/etc");
+ String etc = "file://" + etcFolder.getAbsolutePath();
+
ArrayList<Option> options = new ArrayList<Option>();
- options.addAll(TestJettyOSGiBootCore.provisionCoreJetty());
-
+ 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(
@@ -75,6 +86,8 @@ public class TestJettyOSGiBootWithJsp
)));
}
+ options.addAll(jspDependencies());
+
// Remote JDWP Debugging
if(REMOTE_DEBUGGING) {
options.addAll(Arrays.asList(options(
@@ -83,80 +96,68 @@ public class TestJettyOSGiBootWithJsp
)));
}
- // Standard Options
- options.addAll(Arrays.asList(options(
- PaxRunnerOptions.vmOption("-Djetty.port=9876 -D" + OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS +
- "=etc/jetty.xml;" + testrealm.getAbsolutePath()),
-
- /* orbit deps */
- mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.servlet.jsp" ).versionAsInProject(),
- mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.servlet.jsp.jstl" ).versionAsInProject(),
- mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "javax.el" ).versionAsInProject(),
- mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "com.sun.el" ).versionAsInProject(),
- mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "org.apache.jasper.glassfish" ).versionAsInProject(),
- mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "org.apache.taglibs.standard.glassfish" ).versionAsInProject(),
- mavenBundle().groupId( "org.eclipse.jetty.orbit" ).artifactId( "org.eclipse.jdt.core" ).versionAsInProject(),
-
- /* jetty-osgi deps */
- mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-osgi-boot" ).versionAsInProject().start(),
- mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-osgi-boot-jsp" ).versionAsInProject().start(),
-
- mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "test-jetty-webapp" ).classifier("webbundle").versionAsInProject()
-
- // mavenBundle().groupId( "org.eclipse.equinox.http" ).artifactId( "servlet" ).versionAsInProject().start()
- )));
-
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
- @Ignore
public void listBundles() throws Exception
{
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 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.assertTrue(osgiBoot.getState() == Bundle.ACTIVE);
-
+ 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.assertTrue("The fragment jsp is not correctly resolved", osgiBootJsp.getState() == Bundle.RESOLVED);
-
+ 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.osgi.boot.jsp bundle", osgiBootJsp);
- Assert.assertTrue("The fragment jsp is not correctly resolved", testWebBundle.getState() == Bundle.ACTIVE);
-
+ 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();
- client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
try
{
client.start();
-
- ContentExchange getExchange = new ContentExchange();
- getExchange.setURL("http://127.0.0.1:9876/jsp/dump.jsp");
- getExchange.setMethod(HttpMethods.GET);
-
- client.send(getExchange);
- int state = getExchange.waitForDone();
- Assert.assertEquals("state should be done", HttpExchange.STATUS_COMPLETED, state);
-
- String content = null;
- int responseStatus = getExchange.getResponseStatus();
- Assert.assertEquals(HttpStatus.OK_200, responseStatus);
- if (responseStatus == HttpStatus.OK_200) {
- content = getExchange.getResponseContent();
- }
+ 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);
}
@@ -164,8 +165,8 @@ public class TestJettyOSGiBootWithJsp
{
client.stop();
}
-
+
}
-
+
}

Back to the top