This commit is contained in:
Jan Bartel 2017-10-05 17:12:21 +11:00
parent 09e9cd1bef
commit 0282232ca4
14 changed files with 478 additions and 230 deletions

View File

@ -0,0 +1,104 @@
//
// ========================================================================
// Copyright (c) 1995-2017 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.utils;
import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener;
import org.eclipse.jetty.util.component.LifeCycle;
/**
* ServerConnectorListener
*
* This is for test support, where we need jetty to run on a random port, and we need
* a client to be able to find out which port was picked.
*/
public class ServerConnectorListener extends AbstractLifeCycleListener
{
private Path _filePath;
private String _sysPropertyName;
/**
* @see org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener#lifeCycleStarted(org.eclipse.jetty.util.component.LifeCycle)
*/
@Override
public void lifeCycleStarted(LifeCycle event)
{
if (getFilePath() != null)
{
try (FileWriter writer = new FileWriter(getFilePath().toFile()))
{
Files.deleteIfExists(_filePath);
writer.write(((ServerConnector)event).getLocalPort());
writer.close();
}
catch (Exception e)
{
throw new RuntimeException (e);
}
}
if (getSysPropertyName() != null)
{
System.setProperty(_sysPropertyName,String.valueOf(((ServerConnector)event).getLocalPort()));
}
super.lifeCycleStarted(event);
}
/**
* @return the filePath
*/
public Path getFilePath()
{
return _filePath;
}
/**
* @param filePath the filePath to set
*/
public void setFilePath(Path filePath)
{
_filePath = filePath;
}
/**
* @return the sysPropertyName
*/
public String getSysPropertyName()
{
return _sysPropertyName;
}
/**
* @param sysPropertyName the sysPropertyName to set
*/
public void setSysPropertyName(String sysPropertyName)
{
_sysPropertyName = sysPropertyName;
}
}

View File

@ -21,7 +21,10 @@ package com.acme.osgi;
import java.util.Dictionary;
import java.util.Hashtable;
import org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@ -43,14 +46,31 @@ public class Activator implements BundleActivator
*/
public void start(BundleContext context) throws Exception
{
Server server = new Server(9999);
//For test purposes, use a random port
Server server = new Server(0);
server.getConnectors()[0].addLifeCycleListener(new AbstractLifeCycleListener()
{
/**
* @see org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener#lifeCycleStarted(org.eclipse.jetty.util.component.LifeCycle)
*/
@Override
public void lifeCycleStarted(LifeCycle event)
{
System.setProperty("bundle.server.port", String.valueOf(((ServerConnector)event).getLocalPort()));
super.lifeCycleStarted(event);
}
});
ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
Dictionary serverProps = new Hashtable();
//define the unique name of the server instance
serverProps.put("managedServerName", "fooServer");
//serverProps.put("jetty.http.port", "9999");
//Could also instead call serverProps.put("jetty.http.port", "9999");
//register as an OSGi Service for Jetty to find
_sr = context.registerService(Server.class.getName(), server, serverProps);
}

View File

@ -0,0 +1,48 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<!-- ============================================================= -->
<!-- Configure the Jetty Server instance with an ID "Server" -->
<!-- by adding a HTTP connector. -->
<!-- This configuration must be used in conjunction with jetty.xml -->
<!-- ============================================================= -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Add a HTTP Connector. -->
<!-- Configure an o.e.j.server.ServerConnector with a single -->
<!-- HttpConnectionFactory instance using the common httpConfig -->
<!-- instance defined in jetty.xml -->
<!-- -->
<!-- Consult the javadoc of o.e.j.server.ServerConnector and -->
<!-- o.e.j.server.HttpConnectionFactory for all configuration -->
<!-- that may be set here. -->
<!-- =========================================================== -->
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="httpConfig" /></Arg>
</New>
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Arg>
<New class="org.eclipse.jetty.osgi.boot.utils.ServerConnectorListener">
<Set name="sysPropertyName">boot.context.service.port</Set>
</New>
</Arg>
</Call>
<Set name="host"><Property name="jetty.http.host" /></Set>
<Set name="port"><Property name="jetty.http.port" default="80" /></Set>
<Set name="idleTimeout"><Property name="jetty.http.idleTimeout" default="30000"/></Set>
</New>
</Arg>
</Call>
</Configure>

View File

@ -0,0 +1,48 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<!-- ============================================================= -->
<!-- Configure the Jetty Server instance with an ID "Server" -->
<!-- by adding a HTTP connector. -->
<!-- This configuration must be used in conjunction with jetty.xml -->
<!-- ============================================================= -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Add a HTTP Connector. -->
<!-- Configure an o.e.j.server.ServerConnector with a single -->
<!-- HttpConnectionFactory instance using the common httpConfig -->
<!-- instance defined in jetty.xml -->
<!-- -->
<!-- Consult the javadoc of o.e.j.server.ServerConnector and -->
<!-- o.e.j.server.HttpConnectionFactory for all configuration -->
<!-- that may be set here. -->
<!-- =========================================================== -->
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="httpConfig" /></Arg>
</New>
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Arg>
<New class="org.eclipse.jetty.osgi.boot.utils.ServerConnectorListener">
<Set name="sysPropertyName">boot.webapp.service.port</Set>
</New>
</Arg>
</Call>
<Set name="host"><Property name="jetty.http.host" /></Set>
<Set name="port"><Property name="jetty.http.port" default="80" /></Set>
<Set name="idleTimeout"><Property name="jetty.http.idleTimeout" default="30000"/></Set>
</New>
</Arg>
</Call>
</Configure>

View File

@ -0,0 +1,48 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<!-- ============================================================= -->
<!-- Configure the Jetty Server instance with an ID "Server" -->
<!-- by adding a HTTP connector. -->
<!-- This configuration must be used in conjunction with jetty.xml -->
<!-- ============================================================= -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Add a HTTP Connector. -->
<!-- Configure an o.e.j.server.ServerConnector with a single -->
<!-- HttpConnectionFactory instance using the common httpConfig -->
<!-- instance defined in jetty.xml -->
<!-- -->
<!-- Consult the javadoc of o.e.j.server.ServerConnector and -->
<!-- o.e.j.server.HttpConnectionFactory for all configuration -->
<!-- that may be set here. -->
<!-- =========================================================== -->
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="httpConfig" /></Arg>
</New>
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Arg>
<New class="org.eclipse.jetty.osgi.boot.utils.ServerConnectorListener">
<Set name="sysPropertyName">boot.annotations.port</Set>
</New>
</Arg>
</Call>
<Set name="host"><Property name="jetty.http.host" /></Set>
<Set name="port"><Property name="jetty.http.port" default="80" /></Set>
<Set name="idleTimeout"><Property name="jetty.http.idleTimeout" default="30000"/></Set>
</New>
</Arg>
</Call>
</Configure>

View File

@ -0,0 +1,48 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<!-- ============================================================= -->
<!-- Configure the Jetty Server instance with an ID "Server" -->
<!-- by adding a HTTP connector. -->
<!-- This configuration must be used in conjunction with jetty.xml -->
<!-- ============================================================= -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Add a HTTP Connector. -->
<!-- Configure an o.e.j.server.ServerConnector with a single -->
<!-- HttpConnectionFactory instance using the common httpConfig -->
<!-- instance defined in jetty.xml -->
<!-- -->
<!-- Consult the javadoc of o.e.j.server.ServerConnector and -->
<!-- o.e.j.server.HttpConnectionFactory for all configuration -->
<!-- that may be set here. -->
<!-- =========================================================== -->
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config"><Ref refid="httpConfig" /></Arg>
</New>
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Arg>
<New class="org.eclipse.jetty.osgi.boot.utils.ServerConnectorListener">
<Set name="sysPropertyName">boot.jsp.port</Set>
</New>
</Arg>
</Call>
<Set name="host"><Property name="jetty.http.host" /></Set>
<Set name="port"><Property name="jetty.http.port" default="80" /></Set>
<Set name="idleTimeout"><Property name="jetty.http.idleTimeout" default="30000"/></Set>
</New>
</Arg>
</Call>
</Configure>

View File

@ -31,6 +31,13 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Arg>
<New class="org.eclipse.jetty.osgi.boot.utils.ServerConnectorListener">
<Set name="sysPropertyName">foo.foo</Set>
</New>
</Arg>
</Call>
<Set name="host"><Property name="jetty.http.host" /></Set>
<Set name="port"><Property name="jetty.http.port" default="80" /></Set>
<Set name="idleTimeout"><Property name="jetty.http.idleTimeout" default="30000"/></Set>

View File

@ -69,9 +69,9 @@ public class TestJettyOSGiBootContextAsService
{
ArrayList<Option> options = new ArrayList<Option>();
options.add(CoreOptions.junitBundles());
options.addAll(configureJettyHomeAndPort("jetty-http.xml"));
options.addAll(configureJettyHomeAndPort("jetty-http-boot-context-as-service.xml"));
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.xml.*"));
options.addAll(TestJettyOSGiBootCore.coreJettyDependencies());
options.addAll(TestOSGiUtil.coreJettyDependencies());
// a bundle that registers a webapp as a service for the jetty osgi core
// to pick up and deploy
@ -96,8 +96,8 @@ public class TestJettyOSGiBootContextAsService
List<Option> options = new ArrayList<Option>();
options.add(systemProperty(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS).value(xmlConfigs.toString()));
options.add(systemProperty("jetty.http.port").value(String.valueOf(TestJettyOSGiBootCore.DEFAULT_HTTP_PORT)));
options.add(systemProperty("jetty.ssl.port").value(String.valueOf(TestJettyOSGiBootCore.DEFAULT_SSL_PORT)));
options.add(systemProperty("jetty.http.port").value("0"));
options.add(systemProperty("jetty.ssl.port").value(String.valueOf(TestOSGiUtil.DEFAULT_SSL_PORT)));
options.add(systemProperty("jetty.home").value(etc.getParentFile().getAbsolutePath()));
return options;
}
@ -120,7 +120,10 @@ public class TestJettyOSGiBootContextAsService
try
{
client.start();
ContentResponse response = client.GET("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_HTTP_PORT + "/acme/index.html");
String tmp = System.getProperty("boot.context.service.port");
assertNotNull(tmp);
int port = Integer.valueOf(tmp).intValue();
ContentResponse response = client.GET("http://127.0.0.1:" + port + "/acme/index.html");
assertEquals(HttpStatus.OK_200, response.getStatus());
String content = new String(response.getContent());

View File

@ -1,184 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2017 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.util.ArrayList;
import java.util.Arrays;
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.Configuration;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.MavenUtils;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.options.MavenUrlReference.VersionResolver;
import org.osgi.framework.BundleContext;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
/**
* Default OSGi setup integration test
*/
@RunWith( PaxExam.class )
public class TestJettyOSGiBootCore
{
private static final String LOG_LEVEL = "WARN";
public static final int DEFAULT_HTTP_PORT=TestOSGiUtil.findFreePort("jetty.http.port");
public static final int DEFAULT_SSL_PORT=TestOSGiUtil.findFreePort("jetty.ssl.port");
static
{
System.err.println("DEFAULT_HTTP_PORT="+DEFAULT_HTTP_PORT);
System.err.println("DEFAULT_SSL_PORT="+DEFAULT_SSL_PORT);
}
@Inject
private BundleContext bundleContext;
@Configuration
public Option[] config()
{
VersionResolver resolver = MavenUtils.asInProject();
ArrayList<Option> options = new ArrayList<Option>();
options.addAll(provisionCoreJetty());
options.add(CoreOptions.junitBundles());
options.addAll(httpServiceJetty());
options.addAll(Arrays.asList(options(systemProperty("pax.exam.logging").value("none"))));
options.addAll(Arrays.asList(options(systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value(LOG_LEVEL))));
options.addAll(Arrays.asList(options(systemProperty("org.eclipse.jetty.LEVEL").value(LOG_LEVEL))));
options.addAll(Arrays.asList(options(systemProperty("org.eclipse.jetty.annotations.LEVEL").value("DEBUG"))));
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.http.port").value(String.valueOf(DEFAULT_HTTP_PORT)));
res.add(CoreOptions.systemProperty("jetty.ssl.port").value(String.valueOf(DEFAULT_SSL_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.ow2.asm" ).artifactId( "asm" ).versionAsInProject().start());
res.add(mavenBundle().groupId( "org.ow2.asm" ).artifactId( "asm-commons" ).versionAsInProject().start());
res.add(mavenBundle().groupId( "org.ow2.asm" ).artifactId( "asm-tree" ).versionAsInProject().start());
res.add(mavenBundle().groupId( "org.apache.aries" ).artifactId( "org.apache.aries.util" ).versionAsInProject().start());
res.add(mavenBundle().groupId( "org.apache.aries.spifly" ).artifactId( "org.apache.aries.spifly.dynamic.bundle" ).versionAsInProject().start());
res.add(mavenBundle().groupId( "org.eclipse.jetty.toolchain" ).artifactId( "jetty-osgi-servlet-api" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "javax.annotation" ).artifactId( "javax.annotation-api" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.apache.geronimo.specs" ).artifactId( "geronimo-jta_1.1_spec" ).version("1.1.1").noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-util" ).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-http" ).versionAsInProject());
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" ).artifactId( "jetty-jndi" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-plus" ).versionAsInProject());
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-annotations" ).versionAsInProject().start());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-api" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-common" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-servlet" ).versionAsInProject());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-server" ).versionAsInProject());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-client" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "javax.websocket" ).artifactId( "javax.websocket-api" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "javax-websocket-client-impl").versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "javax-websocket-server-impl").versionAsInProject().start());
res.add(mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-osgi-boot" ).versionAsInProject().start());
return res;
}
public static List<Option> consoleDependencies()
{
List<Option> res = new ArrayList<Option>();
res.add(systemProperty("osgi.console").value("6666"));
res.add(systemProperty("osgi.console.enable.builtin").value("true"));
return res;
}
public static List<Option> jspDependencies()
{
List<Option> res = new ArrayList<Option>();
//jetty jsp bundles
res.add(mavenBundle().groupId("org.eclipse.jetty.toolchain").artifactId("jetty-schemas").versionAsInProject());
res.add(mavenBundle().groupId("org.eclipse.jetty.orbit").artifactId("javax.servlet.jsp.jstl").versionAsInProject());
res.add(mavenBundle().groupId("org.mortbay.jasper").artifactId("apache-el").versionAsInProject());
res.add(mavenBundle().groupId("org.mortbay.jasper").artifactId("apache-jsp").versionAsInProject());
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("apache-jsp").versionAsInProject());
res.add(mavenBundle().groupId("org.glassfish.web").artifactId("javax.servlet.jsp.jstl").versionAsInProject());
res.add(mavenBundle().groupId("org.eclipse.jdt.core.compiler").artifactId("ecj").versionAsInProject());
res.add(mavenBundle().groupId("org.eclipse.jetty.osgi").artifactId("jetty-osgi-boot-jsp").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;
}
@Ignore
@Test
public void assertAllBundlesActiveOrResolved() throws Exception
{
TestOSGiUtil.debugBundles(bundleContext);
TestOSGiUtil.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
{
TestOSGiUtil.testHttpServiceGreetings(bundleContext, "http", DEFAULT_HTTP_PORT);
}
}

View File

@ -58,10 +58,10 @@ public class TestJettyOSGiBootHTTP2
{
ArrayList<Option> options = new ArrayList<Option>();
options.addAll(TestJettyOSGiBootWithJsp.configureJettyHomeAndPort(true,"jetty-http2.xml"));
options.addAll(TestJettyOSGiBootCore.coreJettyDependencies());
options.addAll(TestOSGiUtil.coreJettyDependencies());
options.addAll(http2JettyDependencies());
options.add(CoreOptions.junitBundles());
options.addAll(TestJettyOSGiBootCore.httpServiceJetty());
options.addAll(TestOSGiUtil.httpServiceJetty());
options.add(systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value(LOG_LEVEL));
options.add(systemProperty("org.eclipse.jetty.LEVEL").value(LOG_LEVEL));
return options.toArray(new Option[options.size()]);
@ -70,8 +70,8 @@ public class TestJettyOSGiBootHTTP2
public static List<Option> http2JettyDependencies()
{
List<Option> res = new ArrayList<Option>();
res.add(CoreOptions.systemProperty("jetty.http.port").value(String.valueOf(TestJettyOSGiBootCore.DEFAULT_HTTP_PORT)));
res.add(CoreOptions.systemProperty("jetty.ssl.port").value(String.valueOf(TestJettyOSGiBootCore.DEFAULT_SSL_PORT)));
res.add(CoreOptions.systemProperty("jetty.http.port").value("0"));
res.add(CoreOptions.systemProperty("jetty.ssl.port").value(String.valueOf(TestOSGiUtil.DEFAULT_SSL_PORT)));
String alpnBoot = System.getProperty("mortbay-alpn-boot");
if (alpnBoot == null) { throw new IllegalStateException("Define path to alpn boot jar as system property -Dmortbay-alpn-boot"); }
@ -109,7 +109,7 @@ public class TestJettyOSGiBootHTTP2
@Test
public void testHTTP2OnHttpService() throws Exception
{
TestOSGiUtil.testHttpServiceGreetings(bundleContext, "https", TestJettyOSGiBootCore.DEFAULT_SSL_PORT);
TestOSGiUtil.testHttpServiceGreetings(bundleContext, "https", TestOSGiUtil.DEFAULT_SSL_PORT);
}
}

View File

@ -70,17 +70,17 @@ public class TestJettyOSGiBootWebAppAsService
{
ArrayList<Option> options = new ArrayList<Option>();
options.add(CoreOptions.junitBundles());
options.addAll(configureJettyHomeAndPort("jetty-http.xml"));
options.addAll(configureJettyHomeAndPort("jetty-http-boot-webapp-as-service.xml"));
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.xml.*"));
options.add(CoreOptions.systemPackages("com.sun.org.apache.xalan.internal.res","com.sun.org.apache.xml.internal.utils",
"com.sun.org.apache.xml.internal.utils", "com.sun.org.apache.xpath.internal",
"com.sun.org.apache.xpath.internal.jaxp", "com.sun.org.apache.xpath.internal.objects"));
options.addAll(TestJettyOSGiBootCore.coreJettyDependencies());
options.addAll(TestOSGiUtil.coreJettyDependencies());
options.add(systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value(LOG_LEVEL));
options.add(systemProperty("org.eclipse.jetty.LEVEL").value(LOG_LEVEL));
options.addAll(TestJettyOSGiBootCore.jspDependencies());
options.addAll(TestOSGiUtil.jspDependencies());
options.addAll(testDependencies());
return options.toArray(new Option[options.size()]);
}
@ -99,8 +99,8 @@ public class TestJettyOSGiBootWebAppAsService
List<Option> options = new ArrayList<Option>();
options.add(systemProperty(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS).value(xmlConfigs.toString()));
options.add(systemProperty("jetty.http.port").value(String.valueOf(TestJettyOSGiBootCore.DEFAULT_HTTP_PORT)));
options.add(systemProperty("jetty.ssl.port").value(String.valueOf(TestJettyOSGiBootCore.DEFAULT_SSL_PORT)));
options.add(systemProperty("jetty.http.port").value("0"));
options.add(systemProperty("jetty.ssl.port").value(String.valueOf(TestOSGiUtil.DEFAULT_SSL_PORT)));
options.add(systemProperty("jetty.home").value(etc.getParentFile().getAbsolutePath()));
return options;
}
@ -141,18 +141,23 @@ public class TestJettyOSGiBootWebAppAsService
try
{
client.start();
ContentResponse response = client.GET("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_HTTP_PORT + "/acme/index.html");
String tmp = System.getProperty("boot.webapp.service.port");
assertNotNull(tmp);
int port = Integer.valueOf(tmp.trim()).intValue();
ContentResponse response = client.GET("http://127.0.0.1:" + port + "/acme/index.html");
assertEquals(HttpStatus.OK_200, response.getStatus());
String content = new String(response.getContent());
assertTrue(content.indexOf("<h1>Test OSGi WebAppA</h1>") != -1);
response = client.GET("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_HTTP_PORT + "/acme/mime");
response = client.GET("http://127.0.0.1:" + port + "/acme/mime");
assertEquals(HttpStatus.OK_200, response.getStatus());
content = new String(response.getContent());
assertTrue(content.indexOf("MIMETYPE=application/gzip") != -1);
response = client.GET("http://127.0.0.1:" + "9999" + "/acme/index.html");
tmp = System.getProperty("bundle.server.port");
assertNotNull(tmp);
port = Integer.valueOf(tmp).intValue();
response = client.GET("http://127.0.0.1:" + port + "/acme/index.html");
assertEquals(HttpStatus.OK_200, response.getStatus());
content = new String(response.getContent());
assertTrue(content.indexOf("<h1>Test OSGi WebAppB</h1>") != -1);

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.osgi.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
@ -62,13 +63,13 @@ public class TestJettyOSGiBootWithAnnotations
{
ArrayList<Option> options = new ArrayList<Option>();
options.add(CoreOptions.junitBundles());
options.addAll(configureJettyHomeAndPort("jetty-http.xml"));
options.addAll(configureJettyHomeAndPort("jetty-http-boot-with-annotations.xml"));
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.sql.*","javax.xml.*", "javax.activation.*"));
options.add(CoreOptions.systemPackages("com.sun.org.apache.xalan.internal.res","com.sun.org.apache.xml.internal.utils",
"com.sun.org.apache.xml.internal.utils", "com.sun.org.apache.xpath.internal",
"com.sun.org.apache.xpath.internal.jaxp", "com.sun.org.apache.xpath.internal.objects"));
options.addAll(TestJettyOSGiBootCore.coreJettyDependencies());
options.addAll(TestOSGiUtil.coreJettyDependencies());
options.add(systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value(LOG_LEVEL));
options.add(systemProperty("org.eclipse.jetty.LEVEL").value(LOG_LEVEL));
// options.addAll(TestJettyOSGiBootCore.consoleDependencies());
@ -96,16 +97,19 @@ public class TestJettyOSGiBootWithAnnotations
xmlConfigs.append(";");
xmlConfigs.append(new File(etc, "jetty-testrealm.xml").toURI());
System.err.println(xmlConfigs);
options.add(systemProperty(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS).value(xmlConfigs.toString()));
options.add(systemProperty("jetty.http.port").value(String.valueOf(TestJettyOSGiBootCore.DEFAULT_HTTP_PORT)));
options.add(systemProperty("jetty.ssl.port").value(String.valueOf(TestJettyOSGiBootCore.DEFAULT_SSL_PORT)));
//options.add(systemProperty("jetty.http.port").value(String.valueOf(TestJettyOSGiBootCore.DEFAULT_HTTP_PORT)));
options.add(systemProperty("jetty.http.port").value("0"));
options.add(systemProperty("jetty.ssl.port").value(String.valueOf(TestOSGiUtil.DEFAULT_SSL_PORT)));
options.add(systemProperty("jetty.home").value(etc.getParentFile().getAbsolutePath()));
return options;
}
public static List<Option> jspDependencies()
{
return TestJettyOSGiBootCore.jspDependencies();
return TestOSGiUtil.jspDependencies();
}
public static List<Option> annotationDependencies()
@ -133,23 +137,26 @@ public class TestJettyOSGiBootWithAnnotations
@Test
public void testIndex() throws Exception
{
// TestOSGiUtil.debugBundles(bundleContext);
HttpClient client = new HttpClient();
try
{
client.start();
ContentResponse response = client.GET("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_HTTP_PORT + "/index.html");
String tmp = System.getProperty("boot.annotations.port");
assertNotNull(tmp);
int port = Integer.valueOf(tmp.trim()).intValue();
ContentResponse response = client.GET("http://127.0.0.1:" + port + "/index.html");
assertEquals(HttpStatus.OK_200, response.getStatus());
String content = new String(response.getContent());
assertTrue(content.contains("<h1>Servlet 3.1 Test WebApp</h1>"));
Request req = client.POST("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_HTTP_PORT + "/test");
Request req = client.POST("http://127.0.0.1:" + port + "/test");
response = req.send();
content = new String(response.getContent());
assertTrue(content.contains("<p><b>Result: <span class=\"pass\">PASS</span></p>"));
response = client.GET("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_HTTP_PORT + "/frag.html");
response = client.GET("http://127.0.0.1:" + port + "/frag.html");
content = new String(response.getContent());
assertTrue(content.contains("<h1>FRAGMENT</h1>"));
}

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.osgi.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
@ -61,13 +62,13 @@ public class TestJettyOSGiBootWithJsp
{
ArrayList<Option> options = new ArrayList<Option>();
options.add(CoreOptions.junitBundles());
options.addAll(configureJettyHomeAndPort(false,"jetty-http.xml"));
options.addAll(configureJettyHomeAndPort(false,"jetty-http-boot-with-jsp.xml"));
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.xml.*", "javax.activation.*"));
options.add(CoreOptions.systemPackages("com.sun.org.apache.xalan.internal.res","com.sun.org.apache.xml.internal.utils",
"com.sun.org.apache.xml.internal.utils", "com.sun.org.apache.xpath.internal",
"com.sun.org.apache.xpath.internal.jaxp", "com.sun.org.apache.xpath.internal.objects"));
options.addAll(TestJettyOSGiBootCore.coreJettyDependencies());
options.addAll(TestOSGiUtil.coreJettyDependencies());
options.add(systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value(LOG_LEVEL));
options.add(systemProperty("org.eclipse.jetty.LEVEL").value(LOG_LEVEL));
options.addAll(jspDependencies());
@ -98,8 +99,8 @@ public class TestJettyOSGiBootWithJsp
xmlConfigs.append(new File(etc, "jetty-testrealm.xml").toURI());
options.add(systemProperty(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS).value(xmlConfigs.toString()));
options.add(systemProperty("jetty.http.port").value(String.valueOf(TestJettyOSGiBootCore.DEFAULT_HTTP_PORT)));
options.add(systemProperty("jetty.ssl.port").value(String.valueOf(TestJettyOSGiBootCore.DEFAULT_SSL_PORT)));
options.add(systemProperty("jetty.http.port").value("0"));
options.add(systemProperty("jetty.ssl.port").value(String.valueOf(TestOSGiUtil.DEFAULT_SSL_PORT)));
options.add(systemProperty("jetty.home").value(etc.getParentFile().getAbsolutePath()));
options.add(systemProperty("jetty.base").value(etc.getParentFile().getAbsolutePath()));
return options;
@ -108,7 +109,7 @@ public class TestJettyOSGiBootWithJsp
public static List<Option> jspDependencies()
{
List<Option> res = new ArrayList<Option>();
res.addAll(TestJettyOSGiBootCore.jspDependencies());
res.addAll(TestOSGiUtil.jspDependencies());
//test webapp bundle
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("test-jetty-webapp").classifier("webbundle").versionAsInProject());
@ -124,16 +125,7 @@ public class TestJettyOSGiBootWithJsp
TestOSGiUtil.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
{
TestOSGiUtil.testHttpServiceGreetings(bundleContext, "http", TestJettyOSGiBootCore.DEFAULT_HTTP_PORT);
}
@Test
public void testJspDump() throws Exception
{
@ -142,7 +134,11 @@ public class TestJettyOSGiBootWithJsp
try
{
client.start();
ContentResponse response = client.GET("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_HTTP_PORT + "/jsp/jstl.jsp");
String tmp = System.getProperty("boot.jsp.port");
assertNotNull(tmp);
int port = Integer.valueOf(tmp.trim()).intValue();
ContentResponse response = client.GET("http://127.0.0.1:" + port + "/jsp/jstl.jsp");
assertEquals(HttpStatus.OK_200, response.getStatus());
String content = new String(response.getContent());

View File

@ -18,9 +18,14 @@
package org.eclipse.jetty.osgi.test;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
@ -33,6 +38,8 @@ import org.eclipse.jetty.client.api.ContentResponse;
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;
@ -43,6 +50,97 @@ import org.osgi.service.http.HttpService;
*/
public class TestOSGiUtil
{
public static final int DEFAULT_SSL_PORT=TestOSGiUtil.findFreePort("jetty.ssl.port");
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.http.port").value("0"));
res.add(CoreOptions.systemProperty("jetty.ssl.port").value(String.valueOf(DEFAULT_SSL_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.ow2.asm" ).artifactId( "asm" ).versionAsInProject().start());
res.add(mavenBundle().groupId( "org.ow2.asm" ).artifactId( "asm-commons" ).versionAsInProject().start());
res.add(mavenBundle().groupId( "org.ow2.asm" ).artifactId( "asm-tree" ).versionAsInProject().start());
res.add(mavenBundle().groupId( "org.apache.aries" ).artifactId( "org.apache.aries.util" ).versionAsInProject().start());
res.add(mavenBundle().groupId( "org.apache.aries.spifly" ).artifactId( "org.apache.aries.spifly.dynamic.bundle" ).versionAsInProject().start());
res.add(mavenBundle().groupId( "org.eclipse.jetty.toolchain" ).artifactId( "jetty-osgi-servlet-api" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "javax.annotation" ).artifactId( "javax.annotation-api" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.apache.geronimo.specs" ).artifactId( "geronimo-jta_1.1_spec" ).version("1.1.1").noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-util" ).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-http" ).versionAsInProject());
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" ).artifactId( "jetty-jndi" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-plus" ).versionAsInProject());
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).artifactId( "jetty-annotations" ).versionAsInProject().start());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-api" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-common" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-servlet" ).versionAsInProject());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-server" ).versionAsInProject());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "websocket-client" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "javax.websocket" ).artifactId( "javax.websocket-api" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "javax-websocket-client-impl").versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty.websocket" ).artifactId( "javax-websocket-server-impl").versionAsInProject().start());
res.add(mavenBundle().groupId( "org.eclipse.jetty.osgi" ).artifactId( "jetty-osgi-boot" ).versionAsInProject().start());
return res;
}
public static List<Option> consoleDependencies()
{
List<Option> res = new ArrayList<Option>();
res.add(systemProperty("osgi.console").value("6666"));
res.add(systemProperty("osgi.console.enable.builtin").value("true"));
return res;
}
public static List<Option> jspDependencies()
{
List<Option> res = new ArrayList<Option>();
//jetty jsp bundles
res.add(mavenBundle().groupId("org.eclipse.jetty.toolchain").artifactId("jetty-schemas").versionAsInProject());
res.add(mavenBundle().groupId("org.eclipse.jetty.orbit").artifactId("javax.servlet.jsp.jstl").versionAsInProject());
res.add(mavenBundle().groupId("org.mortbay.jasper").artifactId("apache-el").versionAsInProject());
res.add(mavenBundle().groupId("org.mortbay.jasper").artifactId("apache-jsp").versionAsInProject());
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("apache-jsp").versionAsInProject());
res.add(mavenBundle().groupId("org.glassfish.web").artifactId("javax.servlet.jsp.jstl").versionAsInProject());
res.add(mavenBundle().groupId("org.eclipse.jdt.core.compiler").artifactId("ecj").versionAsInProject());
res.add(mavenBundle().groupId("org.eclipse.jetty.osgi").artifactId("jetty-osgi-boot-jsp").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;
}
protected static Bundle getBundle(BundleContext bundleContext, String symbolicName)
{