|
19 | 19 | package org.eclipse.jetty.tests.distribution;
|
20 | 20 |
|
21 | 21 | import java.io.File;
|
| 22 | +import java.net.URI; |
22 | 23 | import java.nio.file.Files;
|
23 | 24 | import java.nio.file.Path;
|
24 | 25 | import java.nio.file.Paths;
|
|
39 | 40 | import org.junit.jupiter.api.condition.DisabledOnOs;
|
40 | 41 | import org.junit.jupiter.api.condition.JRE;
|
41 | 42 | import org.junit.jupiter.api.condition.OS;
|
| 43 | +import org.junit.jupiter.params.ParameterizedTest; |
| 44 | +import org.junit.jupiter.params.provider.ValueSource; |
42 | 45 |
|
43 | 46 | import static org.hamcrest.MatcherAssert.assertThat;
|
44 | 47 | import static org.hamcrest.Matchers.containsString;
|
@@ -304,4 +307,103 @@ public void testLog4j2ModuleWithSimpleWebAppWithJSP() throws Exception
|
304 | 307 | IO.delete(jettyBase.toFile());
|
305 | 308 | }
|
306 | 309 | }
|
| 310 | + |
| 311 | + @ParameterizedTest |
| 312 | + @ValueSource(strings = {"http", "https"}) |
| 313 | + public void testWebsocketClientInWebappProvidedByServer(String scheme) throws Exception |
| 314 | + { |
| 315 | + Path jettyBase = Files.createTempDirectory("jetty_base"); |
| 316 | + String jettyVersion = System.getProperty("jettyVersion"); |
| 317 | + DistributionTester distribution = DistributionTester.Builder.newInstance() |
| 318 | + .jettyVersion(jettyVersion) |
| 319 | + .jettyBase(jettyBase) |
| 320 | + .mavenLocalRepository(System.getProperty("mavenRepoPath")) |
| 321 | + .build(); |
| 322 | + |
| 323 | + String[] args1 = { |
| 324 | + "--create-startd", |
| 325 | + "--approve-all-licenses", |
| 326 | + "--add-to-start=resources,server,webapp,deploy,jsp,jmx,servlet,servlets,websocket," + scheme |
| 327 | + }; |
| 328 | + try (DistributionTester.Run run1 = distribution.start(args1)) |
| 329 | + { |
| 330 | + assertTrue(run1.awaitFor(5, TimeUnit.SECONDS)); |
| 331 | + assertEquals(0, run1.getExitValue()); |
| 332 | + |
| 333 | + File webApp = distribution.resolveArtifact("org.eclipse.jetty.tests:test-websocket-client-provided-webapp:war:" + jettyVersion); |
| 334 | + distribution.installWarFile(webApp, "test"); |
| 335 | + |
| 336 | + int port = distribution.freePort(); |
| 337 | + String[] args2 = { |
| 338 | + "jetty.http.port=" + port, |
| 339 | + "jetty.ssl.port=" + port, |
| 340 | + // "jetty.server.dumpAfterStart=true", |
| 341 | + }; |
| 342 | + |
| 343 | + try (DistributionTester.Run run2 = distribution.start(args2)) |
| 344 | + { |
| 345 | + assertTrue(run2.awaitConsoleLogsFor("Started @", 10, TimeUnit.SECONDS)); |
| 346 | + |
| 347 | + // We should get the correct configuration from the jetty-websocket-httpclient.xml file. |
| 348 | + startHttpClient(scheme.equals("https")); |
| 349 | + URI serverUri = URI.create(scheme + "://localhost:" + port + "/test"); |
| 350 | + ContentResponse response = client.GET(serverUri); |
| 351 | + assertEquals(HttpStatus.OK_200, response.getStatus()); |
| 352 | + String content = response.getContentAsString(); |
| 353 | + assertThat(content, containsString("WebSocketEcho: success")); |
| 354 | + assertThat(content, containsString("ConnectTimeout: 4999")); |
| 355 | + } |
| 356 | + } |
| 357 | + } |
| 358 | + |
| 359 | + @ParameterizedTest |
| 360 | + @ValueSource(strings = {"http", "https"}) |
| 361 | + public void testWebsocketClientInWebapp(String scheme) throws Exception |
| 362 | + { |
| 363 | + Path jettyBase = Files.createTempDirectory("jetty_base"); |
| 364 | + String jettyVersion = System.getProperty("jettyVersion"); |
| 365 | + DistributionTester distribution = DistributionTester.Builder.newInstance() |
| 366 | + .jettyVersion(jettyVersion) |
| 367 | + .jettyBase(jettyBase) |
| 368 | + .mavenLocalRepository(System.getProperty("mavenRepoPath")) |
| 369 | + .build(); |
| 370 | + |
| 371 | + String[] args1 = { |
| 372 | + "--create-startd", |
| 373 | + "--approve-all-licenses", |
| 374 | + "--add-to-start=resources,server,webapp,deploy,jsp,jmx,servlet,servlets,websocket," + scheme |
| 375 | + }; |
| 376 | + try (DistributionTester.Run run1 = distribution.start(args1)) |
| 377 | + { |
| 378 | + assertTrue(run1.awaitFor(5, TimeUnit.SECONDS)); |
| 379 | + assertEquals(0, run1.getExitValue()); |
| 380 | + |
| 381 | + File webApp = distribution.resolveArtifact("org.eclipse.jetty.tests:test-websocket-client-webapp:war:" + jettyVersion); |
| 382 | + distribution.installWarFile(webApp, "test"); |
| 383 | + |
| 384 | + int port = distribution.freePort(); |
| 385 | + String[] args2 = { |
| 386 | + "jetty.http.port=" + port, |
| 387 | + "jetty.ssl.port=" + port, |
| 388 | + // We must hide the websocket classes from the webapp if we are to include websocket client jars in WEB-INF/lib. |
| 389 | + "jetty.webapp.addServerClasses+=,+org.eclipse.jetty.websocket.", |
| 390 | + "jetty.webapp.addSystemClasses+=,-org.eclipse.jetty.websocket.", |
| 391 | + // "jetty.server.dumpAfterStart=true", |
| 392 | + }; |
| 393 | + |
| 394 | + try (DistributionTester.Run run2 = distribution.start(args2)) |
| 395 | + { |
| 396 | + assertTrue(run2.awaitConsoleLogsFor("Started @", 10, TimeUnit.SECONDS)); |
| 397 | + |
| 398 | + // We should get the correct configuration from the jetty-websocket-httpclient.xml file. |
| 399 | + startHttpClient(scheme.equals("https")); |
| 400 | + URI serverUri = URI.create(scheme + "://localhost:" + port + "/test"); |
| 401 | + ContentResponse response = client.GET(serverUri); |
| 402 | + assertEquals(HttpStatus.OK_200, response.getStatus()); |
| 403 | + String content = response.getContentAsString(); |
| 404 | + assertThat(content, containsString("WebSocketEcho: success")); |
| 405 | + assertThat(content, containsString("ConnectTimeout: 4999")); |
| 406 | + } |
| 407 | + } |
| 408 | + } |
307 | 409 | }
|
0 commit comments