|
22 | 22 |
|
23 | 23 | import com.google.common.collect.ImmutableList; |
24 | 24 |
|
| 25 | +import org.openqa.selenium.io.TemporaryFilesystem; |
25 | 26 | import org.openqa.selenium.net.NetworkUtils; |
26 | 27 | import org.openqa.selenium.testing.InProject; |
27 | 28 | import org.seleniumhq.jetty9.http.HttpVersion; |
|
42 | 43 | import org.seleniumhq.jetty9.servlet.ServletHolder; |
43 | 44 | import org.seleniumhq.jetty9.util.ssl.SslContextFactory; |
44 | 45 |
|
| 46 | +import java.io.File; |
45 | 47 | import java.nio.file.Files; |
46 | 48 | import java.nio.file.Path; |
47 | 49 | import java.util.EnumSet; |
@@ -74,16 +76,19 @@ public class JettyAppServer implements AppServer { |
74 | 76 | private final String hostName; |
75 | 77 |
|
76 | 78 | public JettyAppServer() { |
77 | | - this(detectHostname()); |
| 79 | + this(detectHostname(), getHttpPort(), getHttpsPort()); |
78 | 80 | } |
79 | 81 |
|
80 | 82 | public static String detectHostname() { |
81 | 83 | String hostnameFromProperty = System.getenv(HOSTNAME_FOR_TEST_ENV_NAME); |
82 | 84 | return hostnameFromProperty == null ? "localhost" : hostnameFromProperty; |
83 | 85 | } |
84 | 86 |
|
85 | | - public JettyAppServer(String hostName) { |
| 87 | + public JettyAppServer(String hostName, int httpPort, int httpsPort) { |
86 | 88 | this.hostName = hostName; |
| 89 | + this.port = httpPort; |
| 90 | + this.securePort = httpsPort; |
| 91 | + |
87 | 92 | // Be quiet. Unless we want things to be chatty |
88 | 93 | if (!Boolean.getBoolean("webdriver.debug")) { |
89 | 94 | new NullLogger().disableLogging(); |
@@ -116,17 +121,14 @@ public JettyAppServer(String hostName) { |
116 | 121 | addServlet(defaultContext, "/quitquitquit", KillSwitchServlet.class); |
117 | 122 | addServlet(defaultContext, "/basicAuth", BasicAuth.class); |
118 | 123 | addServlet(defaultContext, "/generated/*", GeneratedJsTestServlet.class); |
119 | | - |
120 | | - listenOn(getHttpPort()); |
121 | | - listenSecurelyOn(getHttpsPort()); |
122 | 124 | } |
123 | 125 |
|
124 | | - private int getHttpPort() { |
| 126 | + private static int getHttpPort() { |
125 | 127 | String port = System.getenv(FIXED_HTTP_PORT_ENV_NAME); |
126 | 128 | return port == null ? findFreePort() : Integer.parseInt(port); |
127 | 129 | } |
128 | 130 |
|
129 | | - private int getHttpsPort() { |
| 131 | + private static int getHttpsPort() { |
130 | 132 | String port = System.getenv(FIXED_HTTPS_PORT_ENV_NAME); |
131 | 133 | return port == null ? findFreePort() : Integer.parseInt(port); |
132 | 134 | } |
@@ -218,16 +220,6 @@ protected Path getKeyStore() { |
218 | 220 | return InProject.locate("java/client/test/org/openqa/selenium/environment/webserver/keystore"); |
219 | 221 | } |
220 | 222 |
|
221 | | - @Override |
222 | | - public void listenOn(int port) { |
223 | | - this.port = port; |
224 | | - } |
225 | | - |
226 | | - @Override |
227 | | - public void listenSecurelyOn(int port) { |
228 | | - this.securePort = port; |
229 | | - } |
230 | | - |
231 | 223 | @Override |
232 | 224 | public void stop() { |
233 | 225 | try { |
@@ -291,15 +283,11 @@ protected static int getHttpsPortFromEnv() { |
291 | 283 | } |
292 | 284 |
|
293 | 285 | public static void main(String[] args) { |
294 | | - JettyAppServer server = new JettyAppServer(detectHostname()); |
295 | | - |
296 | | - server.listenOn(getHttpPortFromEnv()); |
297 | | - System.out.println(String.format("Starting server on port %d", getHttpPortFromEnv())); |
298 | | - |
299 | | - server.listenSecurelyOn(getHttpsPortFromEnv()); |
300 | | - System.out.println(String.format("HTTPS on %d", getHttpsPortFromEnv())); |
301 | | - |
302 | | - server.start(); |
| 286 | + int httpPort = getHttpPortFromEnv(); |
| 287 | + int httpsPort = getHttpsPortFromEnv(); |
| 288 | + System.out.println(String.format("Starting server on HTTPS port %d and HTTPS port %d", |
| 289 | + httpPort, httpsPort)); |
| 290 | + new JettyAppServer(detectHostname(), httpPort, httpsPort).start(); |
303 | 291 | } |
304 | 292 |
|
305 | 293 | } |
0 commit comments