From b351631c0de7a77c107da958e713719dc4e9eda4 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 21 Mar 2019 14:31:14 -0500 Subject: [PATCH] Adding both WebSocket tests to /test-integration/ to verify behavior that is causing problems from within OSGi. + Renamed TestableJettyServer to XmlBasedJettyServer to avoid it being picked up as a Test class (due it starting with the name "Test") + Renamed .addConfiguration() to .addXmlConfiguration() to reflect true nature, and also to avoid naming confusion with new Configuration infrastructure in Jetty. Signed-off-by: Joakim Erdfelt --- tests/test-integration/pom.xml | 40 +++++++- .../jetty/test/DefaultHandlerTest.java | 10 +- .../jetty/test/rfcs/RFC2616BaseTest.java | 6 +- .../jetty/test/rfcs/RFC2616NIOHttpTest.java | 12 +-- .../jetty/test/rfcs/RFC2616NIOHttpsTest.java | 12 +-- ...tyServer.java => XmlBasedJettyServer.java} | 21 ++-- .../test/websocket/JavaxSimpleEchoSocket.java | 72 ++++++++++++++ .../test/websocket/JavaxWebSocketTest.java | 89 +++++++++++++++++ .../test/websocket/JettySimpleEchoSocket.java | 84 ++++++++++++++++ .../test/websocket/JettyWebSocketTest.java | 85 +++++++++++++++++ .../src/test/resources/DefaultHandler.xml | 95 +++++++++---------- .../test/resources/add-jetty-test-webapp.xml | 17 ++++ .../src/test/resources/basic-server.xml | 43 +++++++++ .../resources/configurations-addknown-all.xml | 26 +++++ .../src/test/resources/deploy.xml | 33 +++++++ .../src/test/resources/login-service.xml | 22 +++++ 16 files changed, 583 insertions(+), 84 deletions(-) rename tests/test-integration/src/test/java/org/eclipse/jetty/test/support/{TestableJettyServer.java => XmlBasedJettyServer.java} (90%) create mode 100644 tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JavaxSimpleEchoSocket.java create mode 100644 tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JavaxWebSocketTest.java create mode 100644 tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JettySimpleEchoSocket.java create mode 100644 tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JettyWebSocketTest.java create mode 100644 tests/test-integration/src/test/resources/add-jetty-test-webapp.xml create mode 100644 tests/test-integration/src/test/resources/basic-server.xml create mode 100644 tests/test-integration/src/test/resources/configurations-addknown-all.xml create mode 100644 tests/test-integration/src/test/resources/deploy.xml create mode 100644 tests/test-integration/src/test/resources/login-service.xml diff --git a/tests/test-integration/pom.xml b/tests/test-integration/pom.xml index 5fa756b46c7..8665ed2137f 100644 --- a/tests/test-integration/pom.xml +++ b/tests/test-integration/pom.xml @@ -30,11 +30,8 @@ copy-dependencies - org.eclipse.jetty.tests test war - true - true true ${project.build.directory}/webapps @@ -123,6 +120,36 @@ http2-server ${project.version} + + org.eclipse.jetty + jetty-annotations + ${project.version} + test + + + org.eclipse.jetty + jetty-servlets + ${project.version} + test + + + org.eclipse.jetty.websocket + jetty-websocket-server + ${project.version} + test + + + org.eclipse.jetty.websocket + jetty-websocket-client + ${project.version} + test + + + org.eclipse.jetty.websocket + javax-websocket-server + ${project.version} + test + org.eclipse.jetty.tests test-webapp-rfc2616 @@ -130,6 +157,13 @@ war test + + org.eclipse.jetty + test-jetty-webapp + ${project.version} + war + test + org.eclipse.jetty jetty-alpn-server diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/DefaultHandlerTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/DefaultHandlerTest.java index 630ad8a75c8..6388bca0a63 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/DefaultHandlerTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/DefaultHandlerTest.java @@ -29,7 +29,7 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.tools.HttpTester; -import org.eclipse.jetty.test.support.TestableJettyServer; +import org.eclipse.jetty.test.support.XmlBasedJettyServer; import org.eclipse.jetty.test.support.rawhttp.HttpSocketImpl; import org.eclipse.jetty.test.support.rawhttp.HttpTesting; import org.eclipse.jetty.util.IO; @@ -50,16 +50,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals; */ public class DefaultHandlerTest { - private static TestableJettyServer server; + private static XmlBasedJettyServer server; private int serverPort; @BeforeAll public static void setUpServer() throws Exception { - server = new TestableJettyServer(); + server = new XmlBasedJettyServer(); server.setScheme(HttpScheme.HTTP.asString()); - server.addConfiguration("DefaultHandler.xml"); - server.addConfiguration("NIOHttp.xml"); + server.addXmlConfiguration("DefaultHandler.xml"); + server.addXmlConfiguration("NIOHttp.xml"); server.load(); server.start(); diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java index d0d58b46ce0..5569a2c8a0e 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java @@ -33,7 +33,7 @@ import org.eclipse.jetty.http.HttpParser; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.tools.HttpTester; import org.eclipse.jetty.test.support.StringUtil; -import org.eclipse.jetty.test.support.TestableJettyServer; +import org.eclipse.jetty.test.support.XmlBasedJettyServer; import org.eclipse.jetty.test.support.rawhttp.HttpSocket; import org.eclipse.jetty.test.support.rawhttp.HttpTesting; import org.eclipse.jetty.toolchain.test.FS; @@ -62,7 +62,7 @@ public abstract class RFC2616BaseTest private static final String ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; /** STRICT RFC TESTS */ private static final boolean STRICT = false; - private static TestableJettyServer server; + private static XmlBasedJettyServer server; private HttpTesting http; class TestFile @@ -88,7 +88,7 @@ public abstract class RFC2616BaseTest } } - public static void setUpServer(TestableJettyServer testableserver, Class testclazz) throws Exception + public static void setUpServer(XmlBasedJettyServer testableserver, Class testclazz) throws Exception { File testWorkDir = MavenTestingUtils.getTargetTestingDir(testclazz.getName()); FS.ensureDirExists(testWorkDir); diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616NIOHttpTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616NIOHttpTest.java index 4f3929142ae..472a7d20948 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616NIOHttpTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616NIOHttpTest.java @@ -19,7 +19,7 @@ package org.eclipse.jetty.test.rfcs; import org.eclipse.jetty.http.HttpScheme; -import org.eclipse.jetty.test.support.TestableJettyServer; +import org.eclipse.jetty.test.support.XmlBasedJettyServer; import org.eclipse.jetty.test.support.rawhttp.HttpSocket; import org.eclipse.jetty.test.support.rawhttp.HttpSocketImpl; import org.junit.jupiter.api.BeforeAll; @@ -32,12 +32,12 @@ public class RFC2616NIOHttpTest extends RFC2616BaseTest @BeforeAll public static void setupServer() throws Exception { - TestableJettyServer server = new TestableJettyServer(); + XmlBasedJettyServer server = new XmlBasedJettyServer(); server.setScheme(HttpScheme.HTTP.asString()); - server.addConfiguration("RFC2616Base.xml"); - server.addConfiguration("RFC2616_Redirects.xml"); - server.addConfiguration("RFC2616_Filters.xml"); - server.addConfiguration("NIOHttp.xml"); + server.addXmlConfiguration("RFC2616Base.xml"); + server.addXmlConfiguration("RFC2616_Redirects.xml"); + server.addXmlConfiguration("RFC2616_Filters.xml"); + server.addXmlConfiguration("NIOHttp.xml"); setUpServer(server, RFC2616NIOHttpTest.class); } diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616NIOHttpsTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616NIOHttpsTest.java index 34a98de8901..2a6d1c951fc 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616NIOHttpsTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616NIOHttpsTest.java @@ -19,7 +19,7 @@ package org.eclipse.jetty.test.rfcs; import org.eclipse.jetty.http.HttpScheme; -import org.eclipse.jetty.test.support.TestableJettyServer; +import org.eclipse.jetty.test.support.XmlBasedJettyServer; import org.eclipse.jetty.test.support.rawhttp.HttpSocket; import org.eclipse.jetty.test.support.rawhttp.HttpsSocketImpl; import org.junit.jupiter.api.BeforeAll; @@ -35,12 +35,12 @@ public class RFC2616NIOHttpsTest extends RFC2616BaseTest @BeforeAll public static void setupServer() throws Exception { - TestableJettyServer server = new TestableJettyServer(); + XmlBasedJettyServer server = new XmlBasedJettyServer(); server.setScheme(HttpScheme.HTTPS.asString()); - server.addConfiguration("RFC2616Base.xml"); - server.addConfiguration("RFC2616_Redirects.xml"); - server.addConfiguration("RFC2616_Filters.xml"); - server.addConfiguration("NIOHttps.xml"); + server.addXmlConfiguration("RFC2616Base.xml"); + server.addXmlConfiguration("RFC2616_Redirects.xml"); + server.addXmlConfiguration("RFC2616_Filters.xml"); + server.addXmlConfiguration("NIOHttps.xml"); setUpServer(server, RFC2616NIOHttpsTest.class); } diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/XmlBasedJettyServer.java similarity index 90% rename from tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java rename to tests/test-integration/src/test/java/org/eclipse/jetty/test/support/XmlBasedJettyServer.java index a612e6592e7..a857b21e7c6 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/XmlBasedJettyServer.java @@ -39,15 +39,16 @@ import java.util.Properties; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.server.NetworkConnector; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.xml.XmlConfiguration; -import org.junit.jupiter.api.Disabled; /** * Allows for setting up a Jetty server for testing based on XML configuration files. */ -@Disabled -public class TestableJettyServer +public class XmlBasedJettyServer { + private static final Logger LOG = Log.getLogger(XmlBasedJettyServer.class); private List _xmlConfigurations; private final Map _properties = new HashMap<>(); private Server _server; @@ -58,7 +59,7 @@ public class TestableJettyServer private File baseDir; private File testResourcesDir; - public TestableJettyServer() throws IOException + public XmlBasedJettyServer() throws IOException { _xmlConfigurations = new ArrayList<>(); Properties properties = new Properties(); @@ -87,25 +88,25 @@ public class TestableJettyServer // Write out configuration for use by ConfigurationManager. File testConfig = new File(targetDir,"testable-jetty-server-config.properties"); FileOutputStream out = new FileOutputStream(testConfig); - properties.store(out,"Generated by " + TestableJettyServer.class.getName()); + properties.store(out,"Generated by " + XmlBasedJettyServer.class.getName()); for (Object key:properties.keySet()) _properties.put(String.valueOf(key),String.valueOf(properties.get(key))); } - public void addConfiguration(URL xmlConfig) + public void addXmlConfiguration(URL xmlConfig) { _xmlConfigurations.add(xmlConfig); } - public void addConfiguration(File xmlConfigFile) throws MalformedURLException + public void addXmlConfiguration(File xmlConfigFile) throws MalformedURLException { _xmlConfigurations.add(xmlConfigFile.toURI().toURL()); } - public void addConfiguration(String testConfigName) throws MalformedURLException + public void addXmlConfiguration(String testConfigName) throws MalformedURLException { - addConfiguration(new File(testResourcesDir,testConfigName)); + addXmlConfiguration(new File(testResourcesDir,testConfigName)); } public void setProperty(String key, String value) @@ -122,7 +123,7 @@ public class TestableJettyServer for (int i = 0; i < this._xmlConfigurations.size(); i++) { URL configURL = this._xmlConfigurations.get(i); - System.err.println("configuring: "+configURL); + LOG.debug("configuring: "+configURL); XmlConfiguration configuration = new XmlConfiguration(configURL); if (last != null) { diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JavaxSimpleEchoSocket.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JavaxSimpleEchoSocket.java new file mode 100644 index 00000000000..edbbfb3f38a --- /dev/null +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JavaxSimpleEchoSocket.java @@ -0,0 +1,72 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// 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.test.websocket; + +import static org.junit.jupiter.api.Assertions.fail; + +import java.util.concurrent.CountDownLatch; + +import javax.websocket.ClientEndpoint; +import javax.websocket.CloseReason; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; + +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; + +@ClientEndpoint( + subprotocols = {"chat"}) +public class JavaxSimpleEchoSocket +{ + private static final Logger LOG = Log.getLogger(JavaxSimpleEchoSocket.class); + private Session session; + public CountDownLatch messageLatch = new CountDownLatch(1); + public CountDownLatch closeLatch = new CountDownLatch(1); + + @OnError + public void onError(Throwable t) + { + LOG.warn(t); + fail(t.getMessage()); + } + + @OnClose + public void onClose(CloseReason close) + { + LOG.debug("Closed: {}, {}", close.getCloseCode().getCode(), close.getReasonPhrase()); + closeLatch.countDown(); + } + + @OnMessage + public void onMessage(String message) + { + LOG.debug("Received: {}", message); + messageLatch.countDown(); + } + + @OnOpen + public void onOpen(Session session) + { + LOG.debug("Opened"); + this.session = session; + } +} diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JavaxWebSocketTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JavaxWebSocketTest.java new file mode 100644 index 00000000000..3dfa2e5a99c --- /dev/null +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JavaxWebSocketTest.java @@ -0,0 +1,89 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// 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.test.websocket; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.net.URI; +import java.util.concurrent.TimeUnit; + +import javax.websocket.ContainerProvider; +import javax.websocket.RemoteEndpoint; +import javax.websocket.Session; +import javax.websocket.WebSocketContainer; + +import org.eclipse.jetty.http.HttpScheme; +import org.eclipse.jetty.test.support.XmlBasedJettyServer; +import org.eclipse.jetty.websocket.api.util.WSURI; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class JavaxWebSocketTest +{ + private static XmlBasedJettyServer server; + + @BeforeAll + public static void setUpServer() throws Exception + { + server = new XmlBasedJettyServer(); + server.setScheme(HttpScheme.HTTP.asString()); + server.addXmlConfiguration("basic-server.xml"); + server.addXmlConfiguration("login-service.xml"); + // server.addXmlConfiguration("configurations-addknown-all.xml"); + server.addXmlConfiguration("deploy.xml"); + server.addXmlConfiguration("NIOHttp.xml"); + + server.load(); + // server.getServer().setDumpAfterStart(true); + server.start(); + } + + @AfterAll + public static void tearDownServer() throws Exception + { + server.stop(); + } + + @Test + public void testChatEndpoint() throws Exception + { + URI uri = WSURI.toWebsocket(server.getServerURI().resolve("/test-jetty-webapp/javax.websocket")); + + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + + // to encourage client container to shutdown with server ... + server.getServer().addBean(container, true); + + JavaxSimpleEchoSocket socket = new JavaxSimpleEchoSocket(); + Session session = container.connectToServer(socket, uri); + try + { + RemoteEndpoint.Basic remote = session.getBasicRemote(); + String msg = "Foo"; + remote.sendText(msg); + assertTrue(socket.messageLatch.await(5, TimeUnit.SECONDS)); // give remote 1 second to respond + } + finally + { + session.close(); + assertTrue(socket.closeLatch.await(5, TimeUnit.SECONDS)); // give remote 1 second to acknowledge response + } + } +} diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JettySimpleEchoSocket.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JettySimpleEchoSocket.java new file mode 100644 index 00000000000..b5f43ebcf33 --- /dev/null +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JettySimpleEchoSocket.java @@ -0,0 +1,84 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// 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.test.websocket; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.StatusCode; +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; + +/** + * Basic Echo Client Socket + */ +@WebSocket(maxTextMessageSize = 64 * 1024) +public class JettySimpleEchoSocket +{ + private static final Logger LOG = Log.getLogger(JettySimpleEchoSocket.class); + private final CountDownLatch closeLatch; + @SuppressWarnings("unused") + private Session session; + + public JettySimpleEchoSocket() + { + this.closeLatch = new CountDownLatch(1); + } + + public boolean awaitClose(int duration, TimeUnit unit) throws InterruptedException + { + return this.closeLatch.await(duration, unit); + } + + @OnWebSocketClose + public void onClose(int statusCode, String reason) + { + LOG.debug("Connection closed: {} - {}", statusCode, reason); + this.session = null; + this.closeLatch.countDown(); // trigger latch + } + + @OnWebSocketConnect + public void onConnect(Session session) + { + LOG.debug("Got connect: {}", session); + this.session = session; + try + { + session.getRemote().sendString("Foo"); + session.close(StatusCode.NORMAL, "I'm done"); + } + catch (Throwable t) + { + LOG.warn(t); + } + } + + @OnWebSocketMessage + public void onMessage(String msg) + { + LOG.debug("Got msg: {}", msg); + } +} diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JettyWebSocketTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JettyWebSocketTest.java new file mode 100644 index 00000000000..7eafa5352e8 --- /dev/null +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/websocket/JettyWebSocketTest.java @@ -0,0 +1,85 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// 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.test.websocket; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.net.URI; +import java.util.concurrent.TimeUnit; + +import org.eclipse.jetty.http.HttpScheme; +import org.eclipse.jetty.test.support.XmlBasedJettyServer; +import org.eclipse.jetty.websocket.api.util.WSURI; +import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; +import org.eclipse.jetty.websocket.client.WebSocketClient; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class JettyWebSocketTest +{ + private static XmlBasedJettyServer server; + + @BeforeAll + public static void setUpServer() throws Exception + { + server = new XmlBasedJettyServer(); + server.setScheme(HttpScheme.HTTP.asString()); + server.addXmlConfiguration("basic-server.xml"); + server.addXmlConfiguration("login-service.xml"); + // server.addXmlConfiguration("configurations-addknown-all.xml"); + server.addXmlConfiguration("deploy.xml"); + server.addXmlConfiguration("NIOHttp.xml"); + + server.load(); + // server.getServer().setDumpAfterStart(true); + server.start(); + } + + @AfterAll + public static void tearDownServer() throws Exception + { + server.stop(); + } + + @Test + public void testChatEndpoint() throws Exception + { + URI uri = WSURI.toWebsocket(server.getServerURI().resolve("/test-jetty-webapp/ws/foo")); + + WebSocketClient client = new WebSocketClient(); + + try + { + JettySimpleEchoSocket socket = new JettySimpleEchoSocket(); + + client.start(); + + ClientUpgradeRequest request = new ClientUpgradeRequest(); + request.setSubProtocols("chat"); + client.connect(socket,uri,request); + // wait for closed socket connection. + assertTrue(socket.awaitClose(5, TimeUnit.SECONDS)); + } + finally + { + client.stop(); + } + } +} diff --git a/tests/test-integration/src/test/resources/DefaultHandler.xml b/tests/test-integration/src/test/resources/DefaultHandler.xml index a438ef02119..cd92354eabe 100644 --- a/tests/test-integration/src/test/resources/DefaultHandler.xml +++ b/tests/test-integration/src/test/resources/DefaultHandler.xml @@ -1,59 +1,52 @@ - - - - - - - - - - + - - https - - 32768 - 8192 - 8192 - true - false - 4096 - - - - - - - - - - - - - - - /tests - /default - - default - - - - - + + https + + + 32768 + 8192 + 8192 + true + false + 4096 + - - - - true - 1000 + + + + + + + + + + + + + /tests + /default + + + + + default + + + + + + + + + + + true + 1000 diff --git a/tests/test-integration/src/test/resources/add-jetty-test-webapp.xml b/tests/test-integration/src/test/resources/add-jetty-test-webapp.xml new file mode 100644 index 00000000000..af32ed57790 --- /dev/null +++ b/tests/test-integration/src/test/resources/add-jetty-test-webapp.xml @@ -0,0 +1,17 @@ + + + + + + + /test-jetty-webapp + /test-jetty-webapp.war + + + 1024 + + + + + diff --git a/tests/test-integration/src/test/resources/basic-server.xml b/tests/test-integration/src/test/resources/basic-server.xml new file mode 100644 index 00000000000..9073072dbce --- /dev/null +++ b/tests/test-integration/src/test/resources/basic-server.xml @@ -0,0 +1,43 @@ + + + + + + https + + + + 32768 + 8192 + 8192 + true + false + 4096 + + + + + + + + + + + + + + + + + + + + + + + + true + 1000 + + diff --git a/tests/test-integration/src/test/resources/configurations-addknown-all.xml b/tests/test-integration/src/test/resources/configurations-addknown-all.xml new file mode 100644 index 00000000000..fb5ad05efb3 --- /dev/null +++ b/tests/test-integration/src/test/resources/configurations-addknown-all.xml @@ -0,0 +1,26 @@ + + + + + + + + org.eclipse.jetty.webapp.FragmentConfiguration + org.eclipse.jetty.webapp.JettyWebXmlConfiguration + org.eclipse.jetty.webapp.WebXmlConfiguration + org.eclipse.jetty.webapp.WebAppConfiguration + org.eclipse.jetty.webapp.ServletsConfiguration + org.eclipse.jetty.webapp.JspConfiguration + org.eclipse.jetty.webapp.JaasConfiguration + org.eclipse.jetty.webapp.JndiConfiguration + org.eclipse.jetty.plus.webapp.PlusConfiguration + org.eclipse.jetty.plus.webapp.EnvConfiguration + org.eclipse.jetty.webapp.JmxConfiguration + org.eclipse.jetty.annotations.AnnotationConfiguration + org.eclipse.jetty.websocket.server.JettyWebSocketConfiguration + org.eclipse.jetty.websocket.jsr356.server.JavaxWebSocketConfiguration + + + + diff --git a/tests/test-integration/src/test/resources/deploy.xml b/tests/test-integration/src/test/resources/deploy.xml new file mode 100644 index 00000000000..0a7786e863b --- /dev/null +++ b/tests/test-integration/src/test/resources/deploy.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern + .*/[^/]*servlet-api-[^/]*\.jar$ + + + + + + 1 + true + + + /testable-jetty-server-config.properties + + + + + + + + + \ No newline at end of file diff --git a/tests/test-integration/src/test/resources/login-service.xml b/tests/test-integration/src/test/resources/login-service.xml new file mode 100644 index 00000000000..55a2c01cc6c --- /dev/null +++ b/tests/test-integration/src/test/resources/login-service.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + Test Realm + + false + + + +