commit test-jetty-osgi
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2185 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
9d7dc984b0
commit
de2e13a9e3
|
@ -0,0 +1,277 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
<artifactId>jetty-osgi-project</artifactId>
|
||||
<version>7.1.5-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
<artifactId>test-jetty-osgi</artifactId>
|
||||
<name>Jetty :: OSGi :: Test</name>
|
||||
<description>Jetty OSGi Integration test</description>
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.boot.test</bundle-symbolic-name>
|
||||
<eclipse-mirror>http://mirror.cc.vt.edu/pub/eclipse/eclipse/downloads/drops</eclipse-mirror>
|
||||
<!-- <orbit-url>http://download.eclipse.org/tools/orbit/downloads/drops/R20100519200754/bundles</orbit-url> -->
|
||||
<orbit-url>http://download.eclipse.org/tools/orbit/committers/drops/I20100628101947/bundles</orbit-url>
|
||||
<assembly-directory>target/distribution</assembly-directory>
|
||||
<eclipse-drop>S-3.6RC4-201006031500</eclipse-drop>
|
||||
<eclipse-ecj-version>3.6RC4</eclipse-ecj-version>
|
||||
<orbit-javax-activation-version>${javax-activation-version}.0.v201005080500</orbit-javax-activation-version>
|
||||
<orbit-javax-el-version>2.1.0.v201004190952</orbit-javax-el-version>
|
||||
<orbit-javax-mail-glassfish-version>${javax-mail-version}.v201005082020</orbit-javax-mail-glassfish-version>
|
||||
<orbit-javax-servlet-version>2.5.0.v200910301333</orbit-javax-servlet-version>
|
||||
<orbit-javax-servlet-jsp-version>2.1.0.v201004190952</orbit-javax-servlet-jsp-version>
|
||||
<orbit-javax-servlet-jsp-jstl-version>1.2.0.v201004190952</orbit-javax-servlet-jsp-jstl-version>
|
||||
<orbit-com-sun-el-version>1.0.0.v201004190952</orbit-com-sun-el-version>
|
||||
<orbit-org-apache-jasper-version>2.1.0.v201006280255</orbit-org-apache-jasper-version>
|
||||
<orbit-org-apache-taglibs-standard-version>1.2.0.v201004190952</orbit-org-apache-taglibs-standard-version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
<artifactId>jetty-osgi-boot</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
<artifactId>jetty-osgi-boot-jsp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.osgi</groupId>
|
||||
<artifactId>jetty-httpservice</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-deploy</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</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>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-websocket</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- can't use javax.servlet:servlet-api:2.5 it is not a bundle.
|
||||
the mortbay one is a bundle -->
|
||||
<dependency>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5-20081211</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse</groupId>
|
||||
<artifactId>osgi</artifactId>
|
||||
<version>${osgi-version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>services</artifactId>
|
||||
<version>${osgi-services-version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.equinox.http</groupId>
|
||||
<artifactId>servlet</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlets</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>test-jetty-webapp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<classifier>webbundle</classifier>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam-junit</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>pax-exam-container-default</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit4-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.ops4j.pax.exam</groupId>
|
||||
<artifactId>maven-paxexam-plugin</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-config</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>
|
||||
|
||||
<!-- prepare the orbit jars in the target/distribution folder copied from jetty-distribution/pom.xml -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<!-- This is the Orbit Downloads Process -->
|
||||
|
||||
<!-- Step 1: download orbit artifact into orbit-cache (if not present) -->
|
||||
<property name="orbit-cache" value="${user.home}/.m2/eclipse-orbit" />
|
||||
|
||||
<mkdir dir="${orbit-cache}" />
|
||||
<get dest="${orbit-cache}" verbose="true" skipexisting="true">
|
||||
<url url="${orbit-url}/javax.servlet_${orbit-javax-servlet-version}.jar" />
|
||||
<url url="${orbit-url}/javax.activation_${orbit-javax-activation-version}.jar" />
|
||||
<url url="${orbit-url}/javax.mail.glassfish_${orbit-javax-mail-glassfish-version}.jar" />
|
||||
<url url="${orbit-url}/javax.el_${orbit-javax-el-version}.jar" />
|
||||
<url url="${orbit-url}/javax.servlet.jsp_${orbit-javax-servlet-jsp-version}.jar" />
|
||||
<url url="${orbit-url}/javax.servlet.jsp.jstl_${orbit-javax-servlet-jsp-jstl-version}.jar" />
|
||||
<url url="${orbit-url}/com.sun.el_${orbit-com-sun-el-version}.jar" />
|
||||
<url url="${orbit-url}/org.apache.jasper.glassfish_${orbit-org-apache-jasper-version}.jar" />
|
||||
<url url="${orbit-url}/org.apache.taglibs.standard.glassfish_${orbit-org-apache-taglibs-standard-version}.jar" />
|
||||
</get>
|
||||
|
||||
<mkdir dir="${orbit-cache}/${eclipse-drop}" />
|
||||
<get dest="${orbit-cache}/${eclipse-drop}" verbose="true" skipexisting="true">
|
||||
<url url="${eclipse-mirror}/${eclipse-drop}/ecj-${eclipse-ecj-version}.jar" />
|
||||
</get>
|
||||
|
||||
<!-- Step 2: copy the orbit artifact from orbit-cache to the appropriate lib directory -->
|
||||
|
||||
<!-- ${jetty.home}/lib/ -->
|
||||
<mkdir dir="${assembly-directory}/lib" />
|
||||
<copy file="${orbit-cache}/javax.servlet_${orbit-javax-servlet-version}.jar" tofile="${assembly-directory}/lib/servlet-api-2.5.jar" />
|
||||
|
||||
<!-- ${jetty.home}/lib/jndi/ -->
|
||||
<mkdir dir="${assembly-directory}/lib/jndi" />
|
||||
<copy todir="${assembly-directory}/lib/jndi">
|
||||
<fileset dir="${orbit-cache}">
|
||||
<include name="javax.activation_${orbit-javax-activation-version}.jar" />
|
||||
<include name="javax.mail.glassfish_${orbit-javax-mail-glassfish-version}.jar" />
|
||||
</fileset>
|
||||
</copy>
|
||||
|
||||
<!-- ${jetty.home}/lib/jsp/ -->
|
||||
<mkdir dir="${assembly-directory}/lib/jsp" />
|
||||
<copy todir="${assembly-directory}/lib/jsp">
|
||||
<fileset dir="${orbit-cache}">
|
||||
<include name="javax.el_${orbit-javax-el-version}.jar" />
|
||||
<include name="javax.servlet.jsp_${orbit-javax-servlet-jsp-version}.jar" />
|
||||
<include name="javax.servlet.jsp.jstl_${orbit-javax-servlet-jsp-jstl-version}.jar" />
|
||||
<include name="com.sun.el_${orbit-com-sun-el-version}.jar" />
|
||||
<include name="org.apache.jasper.glassfish_${orbit-org-apache-jasper-version}.jar" />
|
||||
<include name="org.apache.taglibs.standard.glassfish_${orbit-org-apache-taglibs-standard-version}.jar" />
|
||||
</fileset>
|
||||
<fileset dir="${orbit-cache}/${eclipse-drop}">
|
||||
<include name="ecj-${eclipse-ecj-version}.jar" />
|
||||
</fileset>
|
||||
</copy>
|
||||
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<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,23 @@
|
|||
<?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 Authentication Login Service -->
|
||||
<!-- Realms may be configured for the entire server here, or -->
|
||||
<!-- they can be configured for a specific web app in a context -->
|
||||
<!-- configuration (see $(jetty.home)/contexts/test.xml for an -->
|
||||
<!-- example). -->
|
||||
<!-- =========================================================== -->
|
||||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.security.HashLoginService">
|
||||
<Set name="name">Test Realm</Set>
|
||||
<Set name="config"><Property name="jetty.home" default="src/test/config"/>realm.properties</Set>
|
||||
<Set name="refreshInterval">0</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
</Configure>
|
|
@ -0,0 +1,21 @@
|
|||
#
|
||||
# This file defines users passwords and roles for a HashUserRealm
|
||||
#
|
||||
# The format is
|
||||
# <username>: <password>[,<rolename> ...]
|
||||
#
|
||||
# Passwords may be clear text, obfuscated or checksummed. The class
|
||||
# org.eclipse.util.Password should be used to generate obfuscated
|
||||
# passwords or password checksums
|
||||
#
|
||||
# If DIGEST Authentication is used, the password must be in a recoverable
|
||||
# format, either plain text or OBF:.
|
||||
#
|
||||
jetty: MD5:164c88b302622e17050af52c89945d44,user
|
||||
admin: CRYPT:adpexzg3FUZAk,server-administrator,content-administrator,admin
|
||||
other: OBF:1xmk1w261u9r1w1c1xmq,user
|
||||
plain: plain,user
|
||||
user: password,user
|
||||
|
||||
# This entry is for digest auth. The credential is a MD5 hash of username:realmname:password
|
||||
digest: MD5:6e120743ad67abfbc385bc2bb754e297,user
|
|
@ -0,0 +1,192 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2010 Intalio, Inc.
|
||||
// ------------------------------------------------------------------------
|
||||
// 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.
|
||||
// Contributors:
|
||||
// Hugues Malphettes - initial API and implementation
|
||||
// ========================================================================
|
||||
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 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.ContentExchange;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.http.HttpMethods;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.osgi.boot.internal.serverfactory.DefaultJettyAtJettyHomeHelper;
|
||||
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
|
||||
*/
|
||||
public static List<Option> provisionCoreJetty()
|
||||
{
|
||||
return Arrays.asList(options(
|
||||
//get the jetty home config from the osgi boot bundle.
|
||||
PaxRunnerOptions.vmOptions("-D" + DefaultJettyAtJettyHomeHelper.SYS_PROP_JETTY_HOME_BUNDLE + "=org.eclipse.jetty.osgi.boot"),
|
||||
|
||||
// CoreOptions.equinox(),
|
||||
|
||||
mavenBundle().groupId( "org.mortbay.jetty" ).artifactId( "servlet-api" ).versionAsInProject().noStart(),
|
||||
mavenBundle().groupId( "org.eclipse" ).artifactId( "osgi" ).versionAsInProject().noStart(),
|
||||
mavenBundle().groupId( "org.eclipse.osgi" ).artifactId( "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-client" ).versionAsInProject().noStart()
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
@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)
|
||||
//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;
|
||||
protected void doGet(HttpServletRequest req,
|
||||
HttpServletResponse resp) throws ServletException,
|
||||
IOException {
|
||||
resp.getWriter().append("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://localhost:8080/greetings");
|
||||
getExchange.setMethod(HttpMethods.GET);
|
||||
|
||||
client.send(getExchange);
|
||||
int state = getExchange.waitForDone();
|
||||
|
||||
String content = null;
|
||||
int responseStatus = getExchange.getResponseStatus();
|
||||
Assert.assertEquals(HttpStatus.OK_200, responseStatus);
|
||||
if (responseStatus == HttpStatus.OK_200) {
|
||||
content = getExchange.getResponseContent();
|
||||
}
|
||||
Assert.assertEquals("Hello", content);
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2010 Intalio, Inc.
|
||||
// ------------------------------------------------------------------------
|
||||
// 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.
|
||||
// Contributors:
|
||||
// Hugues Malphettes - initial API and implementation
|
||||
// ========================================================================
|
||||
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.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.jetty.client.ContentExchange;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.http.HttpMethods;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
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
|
||||
{
|
||||
@Inject
|
||||
BundleContext bundleContext = null;
|
||||
|
||||
|
||||
@Configuration
|
||||
public static Option[] configure()
|
||||
{
|
||||
File testrealm = new File("src/test/config/etc/jetty-testrealm.xml");
|
||||
|
||||
ArrayList<Option> options = new ArrayList<Option>();
|
||||
options.addAll(TestJettyOSGiBootCore.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)
|
||||
//systemProperty( "org.ops4j.pax.logging.DefaultServiceLog.level" ).value( "INFO" ),
|
||||
|
||||
// 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" ),
|
||||
|
||||
PaxRunnerOptions.vmOption("-D" + OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS +
|
||||
"=etc/jetty.xml;" + testrealm.getAbsolutePath()),
|
||||
|
||||
mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-osgi-boot" ).versionAsInProject(),
|
||||
mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-osgi-boot-jsp" ).versionAsInProject(),
|
||||
|
||||
mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-websocket" ).versionAsInProject(),
|
||||
mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-servlets" ).versionAsInProject(),
|
||||
mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "test-jetty-webapp" ).classifier("webbundle").versionAsInProject(),
|
||||
//the jsp bundles downloaded from eclipse orbit website and the ecj jar.
|
||||
// CoreOptions.provision( PaxRunnerOptions.scanDir( "jasper" ) ),
|
||||
CoreOptions.provision( PaxRunnerOptions.scanDir( "target/distribution/lib/jsp" ) )
|
||||
|
||||
)));
|
||||
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 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 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 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);
|
||||
|
||||
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);
|
||||
|
||||
//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://localhost:8080/jsp/dump.jsp");
|
||||
getExchange.setMethod(HttpMethods.GET);
|
||||
|
||||
client.send(getExchange);
|
||||
int state = getExchange.waitForDone();
|
||||
|
||||
String content = null;
|
||||
int responseStatus = getExchange.getResponseStatus();
|
||||
Assert.assertEquals(HttpStatus.OK_200, responseStatus);
|
||||
if (responseStatus == HttpStatus.OK_200) {
|
||||
content = getExchange.getResponseContent();
|
||||
}
|
||||
//System.err.println("content: " + content);
|
||||
Assert.assertTrue(content.indexOf("<tr><th>ServletPath:</th><td>/jsp/dump.jsp</td></tr>") != -1);
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue