diff --git a/jetty-osgi/test-jetty-osgi-context/pom.xml b/jetty-osgi/test-jetty-osgi-context/pom.xml
index 2d9c2799980..afbd60f8d5c 100644
--- a/jetty-osgi/test-jetty-osgi-context/pom.xml
+++ b/jetty-osgi/test-jetty-osgi-context/pom.xml
@@ -6,7 +6,7 @@
4.0.0
test-jetty-osgi-context
- Jetty :: OSGi :: Context
+ Jetty :: OSGi :: Test Context
Test Jetty OSGi bundle with a ContextHandler
http://www.eclipse.org/jetty
diff --git a/jetty-osgi/test-jetty-osgi-webapp/pom.xml b/jetty-osgi/test-jetty-osgi-webapp/pom.xml
index 6303ad0014c..c34ca274d5b 100644
--- a/jetty-osgi/test-jetty-osgi-webapp/pom.xml
+++ b/jetty-osgi/test-jetty-osgi-webapp/pom.xml
@@ -7,7 +7,7 @@
4.0.0
test-jetty-osgi-webapp
- Jetty :: OSGi :: WebApp
+ Jetty :: OSGi :: Test WebApp
Test Jetty OSGi Webapp bundle
http://www.eclipse.org/jetty
diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootCore.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootCore.java
index 2608f57c84d..696c886592f 100644
--- a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootCore.java
+++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestJettyOSGiBootCore.java
@@ -47,10 +47,16 @@ public class TestJettyOSGiBootCore
{
private static final String LOG_LEVEL = "WARN";
- // TODO these should be dynamic
- public static final int DEFAULT_HTTP_PORT = 9876;
- public static final int DEFAULT_SSL_PORT = 9877;
+ 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;
@@ -175,4 +181,5 @@ public class TestJettyOSGiBootCore
{
TestOSGiUtil.testHttpServiceGreetings(bundleContext, "http", DEFAULT_HTTP_PORT);
}
+
}
diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java
index 8b3a27d71a3..e8bf386ba9c 100644
--- a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java
+++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.osgi.test;
import java.io.IOException;
+import java.net.ServerSocket;
import java.util.HashMap;
import java.util.Map;
@@ -184,4 +185,41 @@ public class TestOSGiUtil
client.stop();
}
}
+
+ public static int findFreePort(String systemProperty)
+ {
+ String freeport = System.getProperty(systemProperty);
+ if (freeport!=null)
+ return Integer.valueOf(freeport);
+
+ try (ServerSocket socket = new ServerSocket(0))
+ {
+ socket.setReuseAddress(true);
+ int port = socket.getLocalPort();
+ System.setProperty(systemProperty,Integer.toString(port));
+ return port;
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ public static void main(String... args)
+ {
+ int freeport = TestOSGiUtil.findFreePort("test");
+ System.err.println("Found Free port="+freeport);
+
+
+ try (ServerSocket socket = new ServerSocket(TestOSGiUtil.findFreePort("test")))
+ {
+ System.err.println("reused port="+socket.getLocalPort());
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+
+ }
}