Merge remote-tracking branch 'origin/jetty-9.3.x' into jetty-9.4.x
This commit is contained in:
commit
6c635e3263
|
@ -6,7 +6,7 @@
|
|||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-jetty-osgi-context</artifactId>
|
||||
<name>Jetty :: OSGi :: Context</name>
|
||||
<name>Jetty :: OSGi :: Test Context</name>
|
||||
<description>Test Jetty OSGi bundle with a ContextHandler</description>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<properties>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-jetty-osgi-webapp</artifactId>
|
||||
<name>Jetty :: OSGi :: WebApp</name>
|
||||
<name>Jetty :: OSGi :: Test WebApp</name>
|
||||
<description>Test Jetty OSGi Webapp bundle</description>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<properties>
|
||||
|
|
|
@ -47,9 +47,15 @@ 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue