Merge remote-tracking branch 'origin/jetty-9.4.x'

This commit is contained in:
Jan Bartel 2017-10-05 17:37:11 +11:00
commit e9d813552b
36 changed files with 640 additions and 359 deletions

View File

@ -0,0 +1,45 @@
//
// ========================================================================
// 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.its.jetty_run_distro_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
*/
@WebServlet("/hello")
public class HelloServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "hello " + (who == null ? "unknown" : who) );
}
}

View File

@ -17,7 +17,7 @@
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
package org.eclipse.jetty.its.jetty_run_distro_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;

View File

@ -1,51 +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.its.jetty_run_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
*/
@WebServlet("/hello")
public class HelloServlet
extends HttpServlet
{
public HelloServlet()
{
System.err.println("HELLOSERVLET CONTSTRUCTED AT "+System.currentTimeMillis());
}
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
System.err.println("HELLOSERVLET HIT AT "+System.currentTimeMillis());
String who = req.getParameter( "name" );
resp.getWriter().write( "hello " + (who == null ? "unknown" : who) );
}
}

View File

@ -1,46 +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.its.jetty_run_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class PingServlet
extends HttpServlet
{
public PingServlet()
{
System.err.println("PINGSERVLET LOADED at"+System.currentTimeMillis());
}
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
System.err.println("PINGSERVLET HIT at"+System.currentTimeMillis());
String who = req.getParameter( "name" );
resp.getWriter().write( "pong " + (who == null ? "unknown" : who) );
}
}

View File

@ -14,7 +14,7 @@
<servlet>
<servlet-name>Ping</servlet-name>
<servlet-class>org.eclipse.jetty.its.jetty_run_mojo_it.PingServlet</servlet-class>
<servlet-class>org.eclipse.jetty.its.jetty_run_distro_mojo_it.PingServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>extra1</param-name><param-value>123</param-value>

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
package org.eclipse.jetty.its.jetty_run_distro_mojo_it;
import org.eclipse.jetty.client.HttpClient;
import org.junit.Assert;
@ -28,16 +28,10 @@ import org.junit.Test;
public class TestHelloServlet
{
public TestHelloServlet()
{
System.err.println("CONSTRUCTED TESTHELLOSERVLET");
}
@Test
public void hello_servlet()
throws Exception
{
System.err.println("IN HELLOSERVLET, PORT="+Integer.getInteger( "jetty.runPort" ));
int port = Integer.getInteger( "jetty.runPort" );
System.out.println( "port used:" + port );
HttpClient httpClient = new HttpClient();

View File

@ -17,7 +17,7 @@
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
package org.eclipse.jetty.its.jetty_run_forked_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;

View File

@ -17,7 +17,7 @@
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
package org.eclipse.jetty.its.jetty_run_forked_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;

View File

@ -14,7 +14,7 @@
<servlet>
<servlet-name>Ping</servlet-name>
<servlet-class>org.eclipse.jetty.its.jetty_run_mojo_it.PingServlet</servlet-class>
<servlet-class>org.eclipse.jetty.its.jetty_run_forked_mojo_it.PingServlet</servlet-class>
<init-param>
<param-name>extra1</param-name><param-value>123</param-value>
</init-param>

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
package org.eclipse.jetty.its.jetty_run_forked_mojo_it;
import org.eclipse.jetty.client.HttpClient;
import org.junit.Assert;

View File

@ -17,7 +17,7 @@
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
package org.eclipse.jetty.its.jetty_run_war_exploded_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;

View File

@ -0,0 +1,41 @@
//
// ========================================================================
// 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.its.jetty_run_war_exploded_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class PingServlet
extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
{
String who = req.getParameter( "name" );
resp.getWriter().write( "pong " + (who == null ? "unknown" : who) );
}
}

View File

@ -14,7 +14,7 @@
<servlet>
<servlet-name>Ping</servlet-name>
<servlet-class>org.eclipse.jetty.its.jetty_run_mojo_it.PingServlet</servlet-class>
<servlet-class>org.eclipse.jetty.its.jetty_run_war_exploded_mojo_it.PingServlet</servlet-class>
<init-param>
<param-name>extra1</param-name><param-value>123</param-value>
</init-param>

View File

@ -17,7 +17,7 @@
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
package org.eclipse.jetty.its.jetty_run_war_exploded_mojo_it;
import org.eclipse.jetty.client.HttpClient;
import org.junit.Assert;

View File

@ -17,7 +17,7 @@
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
package org.eclipse.jetty.its.jetty_run_war_mojo_it;
import org.eclipse.jetty.client.HttpClient;
import org.junit.Assert;

View File

@ -17,7 +17,7 @@
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
package org.eclipse.jetty.its.jetty_start_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;

View File

@ -17,7 +17,7 @@
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
package org.eclipse.jetty.its.jetty_start_mojo_it;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;

View File

@ -14,7 +14,7 @@
<servlet>
<servlet-name>Ping</servlet-name>
<servlet-class>org.eclipse.jetty.its.jetty_run_mojo_it.PingServlet</servlet-class>
<servlet-class>org.eclipse.jetty.its.jetty_start_mojo_it.PingServlet</servlet-class>
<init-param>
<param-name>extra1</param-name><param-value>123</param-value>
</init-param>

View File

@ -17,7 +17,7 @@
//
package org.eclipse.jetty.its.jetty_run_mojo_it;
package org.eclipse.jetty.its.jetty_start_mojo_it;
import org.eclipse.jetty.client.HttpClient;
import org.junit.Assert;

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

@ -405,6 +405,7 @@
<!-- No point defining -Xbootclasspath as the actual OSGi VM is run as a forked process by pax-exam -->
<!-- But we do pass the sys property of the alpn-boot jar so that it can be configured inside tests -->
<argLine>-Dmortbay-alpn-boot=${settings.localRepository}/org/mortbay/jetty/alpn/alpn-boot/${alpn.version}/alpn-boot-${alpn.version}.jar</argLine>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>

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.bundle.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

@ -68,9 +68,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
@ -95,8 +95,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;
}
@ -119,7 +119,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,186 +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 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.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;
/**
* 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.servlet" ).artifactId( "javax.servlet-api" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "javax.annotation" ).artifactId( "javax.annotation-api" ).versionAsInProject().noStart());
res.add(mavenBundle().groupId( "org.apache.geronimo.specs" ).artifactId( "geronimo-jta_1.1_spec" ).version("1.1.1").noStart());
res.add(mavenBundle().groupId( "org.eclipse.jetty" ).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-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

@ -57,10 +57,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()]);
@ -69,8 +69,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"); }
@ -108,7 +108,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

@ -69,17 +69,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()]);
}
@ -98,8 +98,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;
}
@ -140,18 +140,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()
@ -135,23 +139,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("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

@ -73,9 +73,9 @@ public class TestJettyOSGiBootWithBundle
{
ArrayList<Option> options = new ArrayList<Option>();
options.add(CoreOptions.junitBundles());
options.addAll(configureJettyHomeAndPort("jetty-http.xml"));
options.addAll(configureJettyHomeAndPort());
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.xml.*"));
options.addAll(TestJettyOSGiBootCore.coreJettyDependencies());
options.addAll(TestOSGiUtil.coreJettyDependencies());
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))));
@ -84,23 +84,22 @@ public class TestJettyOSGiBootWithBundle
bundle.add(SomeCustomBean.class);
bundle.set( Constants.BUNDLE_SYMBOLICNAME, TEST_JETTY_HOME_BUNDLE );
File etcFolder = new File("src/test/config/etc");
bundle.add("jettyhome/etc/jetty-http.xml", new FileInputStream(new File(etcFolder, "jetty-http.xml")));
bundle.add("jettyhome/etc/jetty-http-boot-with-bundle.xml", new FileInputStream(new File(etcFolder, "jetty-http-boot-with-bundle.xml")));
bundle.add("jettyhome/etc/jetty-with-custom-class.xml", new FileInputStream(new File(etcFolder, "jetty-with-custom-class.xml")));
options.add(CoreOptions.streamBundle(bundle.build()).startLevel(1));
return options.toArray(new Option[options.size()]);
}
public static List<Option> configureJettyHomeAndPort(String jettySelectorFileName)
public static List<Option> configureJettyHomeAndPort()
{
List<Option> options = new ArrayList<Option>();
options.add(systemProperty(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS).value("etc/jetty-with-custom-class.xml,etc/jetty-http.xml"));
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(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS).value("etc/jetty-with-custom-class.xml,etc/jetty-http-boot-with-bundle.xml"));
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.bundle").value(TEST_JETTY_HOME_BUNDLE));
return options;
}
@Ignore
@Test
public void assertAllBundlesActiveOrResolved()
{
@ -110,6 +109,7 @@ public class TestJettyOSGiBootWithBundle
/**
*/
@Ignore
@Test
public void testContextHandlerAsOSGiService() throws Exception
{
@ -118,7 +118,10 @@ public class TestJettyOSGiBootWithBundle
try
{
client.start();
ContentResponse response = client.GET("http://127.0.0.1:" + TestJettyOSGiBootCore.DEFAULT_HTTP_PORT);
String tmp = System.getProperty("boot.bundle.port");
assertNotNull(tmp);
int port = Integer.valueOf(tmp.trim()).intValue();
ContentResponse response = client.GET("http://127.0.0.1:" + port);
assertEquals(HttpStatus.NOT_FOUND_404, response.getStatus());
String content = new String(response.getContent());
assertNotNull(content);

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)
{