|
17 | 17 |
|
18 | 18 | package org.openqa.selenium.environment.webserver; |
19 | 19 |
|
| 20 | +import static com.google.common.net.HttpHeaders.CONTENT_TYPE; |
| 21 | +import static java.util.Collections.singletonMap; |
| 22 | +import static org.openqa.selenium.json.Json.JSON_UTF_8; |
| 23 | +import static org.openqa.selenium.remote.http.Contents.string; |
| 24 | + |
20 | 25 | import com.google.common.collect.ImmutableMap; |
| 26 | + |
21 | 27 | import org.openqa.selenium.grid.config.CompoundConfig; |
22 | 28 | import org.openqa.selenium.grid.config.Config; |
23 | 29 | import org.openqa.selenium.grid.config.MapConfig; |
|
26 | 32 | import org.openqa.selenium.grid.server.Server; |
27 | 33 | import org.openqa.selenium.internal.Require; |
28 | 34 | import org.openqa.selenium.io.TemporaryFilesystem; |
29 | | -import org.openqa.selenium.net.PortProber; |
30 | 35 | import org.openqa.selenium.netty.server.NettyServer; |
31 | 36 | import org.openqa.selenium.remote.http.Contents; |
32 | 37 | import org.openqa.selenium.remote.http.HttpClient; |
|
41 | 46 | import java.net.MalformedURLException; |
42 | 47 | import java.net.URL; |
43 | 48 |
|
44 | | -import static com.google.common.net.HttpHeaders.CONTENT_TYPE; |
45 | | -import static java.util.Collections.singletonMap; |
46 | | -import static org.openqa.selenium.json.Json.JSON_UTF_8; |
47 | | -import static org.openqa.selenium.remote.http.Contents.string; |
48 | | - |
49 | 49 | public class NettyAppServer implements AppServer { |
50 | 50 |
|
51 | 51 | private final static Config sslConfig = new MapConfig( |
@@ -94,7 +94,24 @@ private NettyAppServer(Config config, HttpHandler handler) { |
94 | 94 |
|
95 | 95 | private static Config createDefaultConfig() { |
96 | 96 | return new MemoizedConfig(new MapConfig( |
97 | | - singletonMap("server", singletonMap("port", PortProber.findFreePort())))); |
| 97 | + singletonMap("server", singletonMap("port", 0)))); |
| 98 | + } |
| 99 | + |
| 100 | + public static void main(String[] args) { |
| 101 | + MemoizedConfig config = new MemoizedConfig(new MapConfig(singletonMap("server", singletonMap("port", 2310)))); |
| 102 | + BaseServerOptions options = new BaseServerOptions(config); |
| 103 | + |
| 104 | + HttpHandler handler = new HandlersForTests( |
| 105 | + options.getHostname().orElse("localhost"), |
| 106 | + options.getPort(), |
| 107 | + TemporaryFilesystem.getDefaultTmpFS().createTempDir("netty", "server").toPath()); |
| 108 | + |
| 109 | + NettyAppServer server = new NettyAppServer( |
| 110 | + config, |
| 111 | + handler); |
| 112 | + server.start(); |
| 113 | + |
| 114 | + System.out.printf("Server started. Root URL: %s%n", server.whereIs("/")); |
98 | 115 | } |
99 | 116 |
|
100 | 117 | @Override |
@@ -181,21 +198,4 @@ public String getHostName() { |
181 | 198 | public String getAlternateHostName() { |
182 | 199 | return AppServer.detectAlternateHostname(); |
183 | 200 | } |
184 | | - |
185 | | - public static void main(String[] args) { |
186 | | - MemoizedConfig config = new MemoizedConfig(new MapConfig(singletonMap("server", singletonMap("port", 2310)))); |
187 | | - BaseServerOptions options = new BaseServerOptions(config); |
188 | | - |
189 | | - HttpHandler handler = new HandlersForTests( |
190 | | - options.getHostname().orElse("localhost"), |
191 | | - options.getPort(), |
192 | | - TemporaryFilesystem.getDefaultTmpFS().createTempDir("netty", "server").toPath()); |
193 | | - |
194 | | - NettyAppServer server = new NettyAppServer( |
195 | | - config, |
196 | | - handler); |
197 | | - server.start(); |
198 | | - |
199 | | - System.out.printf("Server started. Root URL: %s%n", server.whereIs("/")); |
200 | | - } |
201 | 201 | } |
0 commit comments