-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #5320 - reproduce failure to load httpClient for WebSocketClien…
…t in webapp Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
- Loading branch information
1 parent
e3ed05f
commit 00f05cb
Showing
10 changed files
with
316 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>org.eclipse.jetty.tests</groupId> | ||
<artifactId>test-webapps-parent</artifactId> | ||
<version>9.4.32-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>test-websocket-client-webapp</artifactId> | ||
<packaging>war</packaging> | ||
|
||
<name>Test :: Jetty Websocket Simple Webapp with WebSocketClient</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.websocket</groupId> | ||
<artifactId>javax.websocket-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.websocket</groupId> | ||
<artifactId>websocket-client</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
32 changes: 32 additions & 0 deletions
32
...et-client-webapp/src/main/java/org/eclipse/jetty/tests/webapp/websocket/EchoEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.tests.webapp.websocket; | ||
|
||
import javax.websocket.OnMessage; | ||
import javax.websocket.server.ServerEndpoint; | ||
|
||
@ServerEndpoint(value = "/echo") | ||
public class EchoEndpoint | ||
{ | ||
@OnMessage | ||
public String echo(String message) | ||
{ | ||
return message; | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
...webapp/src/main/java/org/eclipse/jetty/tests/webapp/websocket/WebSocketClientServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.tests.webapp.websocket; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.concurrent.ArrayBlockingQueue; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.eclipse.jetty.util.component.LifeCycle; | ||
import org.eclipse.jetty.websocket.api.Session; | ||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; | ||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; | ||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; | ||
import org.eclipse.jetty.websocket.api.annotations.WebSocket; | ||
import org.eclipse.jetty.websocket.api.util.WSURI; | ||
import org.eclipse.jetty.websocket.client.WebSocketClient; | ||
|
||
@WebServlet("/") | ||
public class WebSocketClientServlet extends HttpServlet | ||
{ | ||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException | ||
{ | ||
|
||
WebSocketClient client = null; | ||
try | ||
{ | ||
client = new WebSocketClient(); | ||
LifeCycle.start(client); | ||
resp.setContentType("text/html"); | ||
resp.getWriter().println("ConnectTimeout: " + client.getHttpClient().getConnectTimeout()); | ||
|
||
ClientSocket clientSocket = new ClientSocket(); | ||
URI wsUri = WSURI.toWebsocket(req.getRequestURL()).resolve("echo"); | ||
client.connect(clientSocket, wsUri); | ||
clientSocket.openLatch.await(5, TimeUnit.SECONDS); | ||
clientSocket.session.getRemote().sendString("test message"); | ||
String response = clientSocket.textMessages.poll(5, TimeUnit.SECONDS); | ||
if (!"test message".equals(response)) | ||
throw new RuntimeException("incorrect response"); | ||
clientSocket.session.close(); | ||
clientSocket.closeLatch.await(5, TimeUnit.SECONDS); | ||
resp.getWriter().println("WebSocketEcho: success"); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
finally | ||
{ | ||
LifeCycle.stop(client); | ||
} | ||
} | ||
|
||
@WebSocket | ||
public static class ClientSocket | ||
{ | ||
public Session session; | ||
public CountDownLatch openLatch = new CountDownLatch(1); | ||
public CountDownLatch closeLatch = new CountDownLatch(1); | ||
public ArrayBlockingQueue<String> textMessages = new ArrayBlockingQueue<>(10); | ||
|
||
@OnWebSocketConnect | ||
public void onOpen(Session session) | ||
{ | ||
this.session = session; | ||
openLatch.countDown(); | ||
} | ||
|
||
@OnWebSocketMessage | ||
public void onMessage(String message) | ||
{ | ||
textMessages.add(message); | ||
} | ||
|
||
@OnWebSocketClose | ||
public void onClose(int statusCode, String reason) | ||
{ | ||
closeLatch.countDown(); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...st-webapps/test-websocket-client-webapp/src/main/resources/jetty-websocket-httpclient.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> | ||
|
||
<Configure class="org.eclipse.jetty.client.HttpClient"> | ||
<Arg> | ||
<New class="org.eclipse.jetty.util.ssl.SslContextFactory$Client"> | ||
<Set name="trustAll" type="java.lang.Boolean">false</Set> | ||
<Call name="addExcludeProtocols"> | ||
<Arg> | ||
<Array type="java.lang.String"> | ||
<Item>TLS/1.3</Item> | ||
</Array> | ||
</Arg> | ||
</Call> | ||
<Call name="setExcludeCipherSuites"><!-- websocket.org uses WEAK cipher suites --> | ||
<Arg> | ||
<Array type="java.lang.String" /> | ||
</Arg> | ||
</Call> | ||
</New> | ||
</Arg> | ||
<Set name="connectTimeout">4999</Set> | ||
</Configure> |
8 changes: 8 additions & 0 deletions
8
tests/test-webapps/test-websocket-client-webapp/src/main/webapp/WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app | ||
xmlns="http://xmlns.jcp.org/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" | ||
metadata-complete="false" | ||
version="3.1"> | ||
</web-app> |