Merge pull request #3172 from eclipse/jetty-10.0.x-integration-testing-websockets
Adding both WebSocket tests to /test-integration/ to verify behavior that is causing problems from within OSGi.
This commit is contained in:
commit
aa667562c6
|
@ -30,11 +30,8 @@
|
|||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includeGroupId>org.eclipse.jetty.tests</includeGroupId>
|
||||
<includeScope>test</includeScope>
|
||||
<includeTypes>war</includeTypes>
|
||||
<overwriteSnapshots>true</overwriteSnapshots>
|
||||
<overwriteReleases>true</overwriteReleases>
|
||||
<stripVersion>true</stripVersion>
|
||||
<outputDirectory>${project.build.directory}/webapps</outputDirectory>
|
||||
</configuration>
|
||||
|
@ -123,6 +120,36 @@
|
|||
<artifactId>http2-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-annotations</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlets</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>jetty-websocket-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>jetty-websocket-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>javax-websocket-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-webapp-rfc2616</artifactId>
|
||||
|
@ -130,6 +157,13 @@
|
|||
<type>war</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>test-jetty-webapp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>war</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-alpn-server</artifactId>
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<URL> _xmlConfigurations;
|
||||
private final Map<String,String> _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)
|
||||
{
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,59 +1,52 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Configure the Jetty Server -->
|
||||
<!-- -->
|
||||
<!-- Documentation of this file format can be found at: -->
|
||||
<!-- http://docs.codehaus.org/display/JETTY/jetty.xml -->
|
||||
<!-- -->
|
||||
<!-- =============================================================== -->
|
||||
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
|
||||
"http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
|
||||
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
|
||||
<Set name="secureScheme">https</Set>
|
||||
<Set name="securePort"><Property name="jetty.secure.port" default="8443" /></Set>
|
||||
<Set name="outputBufferSize">32768</Set>
|
||||
<Set name="requestHeaderSize">8192</Set>
|
||||
<Set name="responseHeaderSize">8192</Set>
|
||||
<Set name="sendServerVersion">true</Set>
|
||||
<Set name="sendDateHeader">false</Set>
|
||||
<Set name="headerCacheSize">4096</Set>
|
||||
|
||||
<!-- Uncomment to enable handling of X-Forwarded- style headers
|
||||
<Call name="addCustomizer">
|
||||
<Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
|
||||
</Call>
|
||||
-->
|
||||
</New>
|
||||
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Set handler Collection Structure -->
|
||||
<!-- =========================================================== -->
|
||||
<Set name="handler">
|
||||
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
|
||||
<Set name="handlers">
|
||||
<Array type="org.eclipse.jetty.server.Handler">
|
||||
<Item>
|
||||
<New id="defcontext" class="org.eclipse.jetty.server.handler.ContextHandler">
|
||||
<Set name="contextPath">/tests</Set>
|
||||
<Set name="ResourceBase"><Property name="test.docroot.base"/>/default</Set>
|
||||
<Set name="Handler"><New id="reshandler" class="org.eclipse.jetty.server.handler.ResourceHandler"/></Set>
|
||||
<Set name="DisplayName">default</Set>
|
||||
</New>
|
||||
</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
</New>
|
||||
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
|
||||
<Set name="secureScheme">https</Set>
|
||||
<Set name="securePort">
|
||||
<Property name="jetty.secure.port" default="8443"/>
|
||||
</Set>
|
||||
<Set name="outputBufferSize">32768</Set>
|
||||
<Set name="requestHeaderSize">8192</Set>
|
||||
<Set name="responseHeaderSize">8192</Set>
|
||||
<Set name="sendServerVersion">true</Set>
|
||||
<Set name="sendDateHeader">false</Set>
|
||||
<Set name="headerCacheSize">4096</Set>
|
||||
</New>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- extra options -->
|
||||
<!-- =========================================================== -->
|
||||
<Set name="stopAtShutdown">true</Set>
|
||||
<Set name="stopTimeout">1000</Set>
|
||||
<!-- =========================================================== -->
|
||||
<!-- Set handler Collection Structure -->
|
||||
<!-- =========================================================== -->
|
||||
<Set name="handler">
|
||||
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
|
||||
<Set name="handlers">
|
||||
<Array type="org.eclipse.jetty.server.Handler">
|
||||
<Item>
|
||||
<New id="Contexts" class="org.eclipse.jetty.server.handler.HandlerCollection" />
|
||||
</Item>
|
||||
<Item>
|
||||
<New id="defcontext" class="org.eclipse.jetty.server.handler.ContextHandler">
|
||||
<Set name="contextPath">/tests</Set>
|
||||
<Set name="ResourceBase"><Property name="test.docroot.base"/>/default
|
||||
</Set>
|
||||
<Set name="Handler">
|
||||
<New id="reshandler" class="org.eclipse.jetty.server.handler.ResourceHandler"/>
|
||||
</Set>
|
||||
<Set name="DisplayName">default</Set>
|
||||
</New>
|
||||
</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
</New>
|
||||
</Set>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- extra options -->
|
||||
<!-- =========================================================== -->
|
||||
<Set name="stopAtShutdown">true</Set>
|
||||
<Set name="stopTimeout">1000</Set>
|
||||
|
||||
</Configure>
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
|
||||
"http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<Configure id="Contexts" class="org.eclipse.jetty.server.handler.HandlerCollection">
|
||||
<Call name="addHandler">
|
||||
<New class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
<Set name="contextPath">/test-jetty-webapp</Set>
|
||||
<Set name="war"><Property name="test.webapps" default="." />/test-jetty-webapp.war</Set>
|
||||
<Set name="gzipHandler">
|
||||
<New class="org.eclipse.jetty.server.handler.gzip.GzipHandler">
|
||||
<Set name="minGzipSize">1024</Set>
|
||||
</New>
|
||||
</Set>
|
||||
</New>
|
||||
</Call>
|
||||
</Configure>
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
|
||||
"http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
|
||||
<Set name="secureScheme">https</Set>
|
||||
<Set name="securePort">
|
||||
<Property name="jetty.secure.port" default="8443"/>
|
||||
</Set>
|
||||
<Set name="outputBufferSize">32768</Set>
|
||||
<Set name="requestHeaderSize">8192</Set>
|
||||
<Set name="responseHeaderSize">8192</Set>
|
||||
<Set name="sendServerVersion">true</Set>
|
||||
<Set name="sendDateHeader">false</Set>
|
||||
<Set name="headerCacheSize">4096</Set>
|
||||
</New>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Set handler Collection Structure -->
|
||||
<!-- =========================================================== -->
|
||||
<Set name="handler">
|
||||
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
|
||||
<Set name="handlers">
|
||||
<Array type="org.eclipse.jetty.server.Handler">
|
||||
<Item>
|
||||
<New id="WebappContexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection" />
|
||||
</Item>
|
||||
<Item>
|
||||
<New id="defcontext" class="org.eclipse.jetty.server.handler.DefaultHandler" />
|
||||
</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
</New>
|
||||
</Set>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- extra options -->
|
||||
<!-- =========================================================== -->
|
||||
<Set name="stopAtShutdown">true</Set>
|
||||
<Set name="stopTimeout">1000</Set>
|
||||
|
||||
</Configure>
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
|
||||
"http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
<Call class="org.eclipse.jetty.webapp.Configurations" name="setKnown">
|
||||
<Arg>
|
||||
<Array type="String">
|
||||
<Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.WebAppConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.ServletsConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JspConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JaasConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JndiConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JmxConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.websocket.server.JettyWebSocketConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.websocket.jsr356.server.JavaxWebSocketConfiguration</Item>
|
||||
</Array>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Configure>
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
|
||||
"http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
|
||||
<Set name="contexts">
|
||||
<Ref refid="WebappContexts" />
|
||||
</Set>
|
||||
<Call name="setContextAttribute">
|
||||
<Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
|
||||
<Arg>.*/[^/]*servlet-api-[^/]*\.jar$</Arg>
|
||||
</Call>
|
||||
<Call id="webappprovider" name="addAppProvider">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
|
||||
<Set name="monitoredDirName"><Property name="test.webapps" default="target/webapps" /></Set>
|
||||
<Set name="scanInterval">1</Set>
|
||||
<Set name="extractWars">true</Set>
|
||||
<Set name="configurationManager">
|
||||
<New class="org.eclipse.jetty.deploy.PropertiesConfigurationManager">
|
||||
<Set name="file"><Property name="test.targetdir" default="target"/>/testable-jetty-server-config.properties</Set>
|
||||
</New>
|
||||
</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Configure>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
|
||||
"http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
<!-- =========================================================== -->
|
||||
<!-- Configure Authentication Login Service -->
|
||||
<!-- Realms may be configured for the entire server here, or -->
|
||||
<!-- they can be configured for a specific web app in a context -->
|
||||
<!-- configuration (see $(jetty.home)/webapps/test.xml for an -->
|
||||
<!-- example). -->
|
||||
<!-- =========================================================== -->
|
||||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.security.HashLoginService">
|
||||
<Set name="name">Test Realm</Set>
|
||||
<Set name="config"><Property name="login.realm" default="src/test/resources/realm.properties"/></Set>
|
||||
<Set name="hotReload">false</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Configure>
|
Loading…
Reference in New Issue