|
54 | 54 | import org.openqa.selenium.remote.http.BinaryMessage; |
55 | 55 | import org.openqa.selenium.remote.http.ClientConfig; |
56 | 56 | import org.openqa.selenium.remote.http.CloseMessage; |
| 57 | +import org.openqa.selenium.remote.http.ConnectionFailedException; |
57 | 58 | import org.openqa.selenium.remote.http.HttpClient; |
58 | 59 | import org.openqa.selenium.remote.http.HttpClientName; |
59 | 60 | import org.openqa.selenium.remote.http.HttpMethod; |
@@ -145,7 +146,13 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { |
145 | 146 |
|
146 | 147 | @Override |
147 | 148 | public WebSocket openSocket(HttpRequest request, WebSocket.Listener listener) { |
148 | | - URI uri = getWebSocketUri(request); |
| 149 | + URI uri; |
| 150 | + |
| 151 | + try { |
| 152 | + uri = getWebSocketUri(request); |
| 153 | + } catch (URISyntaxException e) { |
| 154 | + throw new ConnectionFailedException("JdkWebSocket initial request execution error", e); |
| 155 | + } |
149 | 156 |
|
150 | 157 | CompletableFuture<java.net.http.WebSocket> webSocketCompletableFuture = |
151 | 158 | client |
@@ -220,25 +227,16 @@ public void onError(java.net.http.WebSocket webSocket, Throwable error) { |
220 | 227 | underlyingSocket = |
221 | 228 | webSocketCompletableFuture.get(readTimeout.toMillis(), TimeUnit.MILLISECONDS); |
222 | 229 | } catch (CancellationException e) { |
223 | | - throw new WebDriverException(e.getMessage(), e); |
| 230 | + throw new ConnectionFailedException("JdkWebSocket initial request canceled", e); |
224 | 231 | } catch (ExecutionException e) { |
225 | 232 | Throwable cause = e.getCause(); |
226 | | - |
227 | | - if (cause instanceof HttpTimeoutException) { |
228 | | - throw new TimeoutException(cause); |
229 | | - } else if (cause instanceof IOException) { |
230 | | - throw new UncheckedIOException((IOException) cause); |
231 | | - } else if (cause instanceof RuntimeException) { |
232 | | - throw (RuntimeException) cause; |
233 | | - } |
234 | | - |
235 | | - throw new WebDriverException((cause != null) ? cause : e); |
| 233 | + throw new ConnectionFailedException("JdkWebSocket initial request execution error", (cause != null) ? cause : e); |
236 | 234 | } catch (InterruptedException e) { |
237 | 235 | Thread.currentThread().interrupt(); |
238 | | - throw new RuntimeException(e); |
| 236 | + throw new ConnectionFailedException("JdkWebSocket initial request interrupted", e); |
239 | 237 | } catch (java.util.concurrent.TimeoutException e) { |
240 | 238 | webSocketCompletableFuture.cancel(true); |
241 | | - throw new TimeoutException(e); |
| 239 | + throw new ConnectionFailedException("JdkWebSocket initial request timeout", e); |
242 | 240 | } |
243 | 241 |
|
244 | 242 | WebSocket websocket = |
@@ -314,36 +312,28 @@ public void close() { |
314 | 312 | return websocket; |
315 | 313 | } |
316 | 314 |
|
317 | | - private URI getWebSocketUri(HttpRequest request) { |
| 315 | + private URI getWebSocketUri(HttpRequest request) throws URISyntaxException { |
318 | 316 | URI uri = messages.getRawUri(request); |
319 | 317 | if ("http".equalsIgnoreCase(uri.getScheme())) { |
320 | | - try { |
321 | | - uri = |
322 | | - new URI( |
323 | | - "ws", |
324 | | - uri.getUserInfo(), |
325 | | - uri.getHost(), |
326 | | - uri.getPort(), |
327 | | - uri.getPath(), |
328 | | - uri.getQuery(), |
329 | | - uri.getFragment()); |
330 | | - } catch (URISyntaxException e) { |
331 | | - throw new RuntimeException(e); |
332 | | - } |
| 318 | + uri = |
| 319 | + new URI( |
| 320 | + "ws", |
| 321 | + uri.getUserInfo(), |
| 322 | + uri.getHost(), |
| 323 | + uri.getPort(), |
| 324 | + uri.getPath(), |
| 325 | + uri.getQuery(), |
| 326 | + uri.getFragment()); |
333 | 327 | } else if ("https".equalsIgnoreCase(uri.getScheme())) { |
334 | | - try { |
335 | | - uri = |
336 | | - new URI( |
337 | | - "wss", |
338 | | - uri.getUserInfo(), |
339 | | - uri.getHost(), |
340 | | - uri.getPort(), |
341 | | - uri.getPath(), |
342 | | - uri.getQuery(), |
343 | | - uri.getFragment()); |
344 | | - } catch (URISyntaxException e) { |
345 | | - throw new RuntimeException(e); |
346 | | - } |
| 328 | + uri = |
| 329 | + new URI( |
| 330 | + "wss", |
| 331 | + uri.getUserInfo(), |
| 332 | + uri.getHost(), |
| 333 | + uri.getPort(), |
| 334 | + uri.getPath(), |
| 335 | + uri.getQuery(), |
| 336 | + uri.getFragment()); |
347 | 337 | } |
348 | 338 | return uri; |
349 | 339 | } |
|
0 commit comments