summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJesse McConnell2012-09-25 09:18:06 (EDT)
committer Jesse McConnell2012-09-25 09:18:06 (EDT)
commit494f7e48fcc20c51066cd91a6dac1d738cacb54e (patch)
treea0e4bb98ede14a9e1bcbb737cc9e4e52e37de278
parentaf233a8a37581aa7805378a378d191c290731490 (diff)
downloadorg.eclipse.jetty.project-494f7e48fcc20c51066cd91a6dac1d738cacb54e.zip
org.eclipse.jetty.project-494f7e48fcc20c51066cd91a6dac1d738cacb54e.tar.gz
org.eclipse.jetty.project-494f7e48fcc20c51066cd91a6dac1d738cacb54e.tar.bz2
add websocket test for http keyword in response message from reported issue
-rw-r--r--jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketServletRFCTest.java42
-rw-r--r--jetty-websocket/src/test/java/org/eclipse/jetty/websocket/helper/MessageSender.java24
2 files changed, 64 insertions, 2 deletions
diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketServletRFCTest.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketServletRFCTest.java
index 5ef50ca..8296b1a 100644
--- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketServletRFCTest.java
+++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketServletRFCTest.java
@@ -80,6 +80,8 @@ public class WebSocketServletRFCTest
try
{
conn.sendMessage(data);
+
+ conn.close(1000, data);
}
catch (IOException e)
{
@@ -240,4 +242,44 @@ public class WebSocketServletRFCTest
sender.close();
}
}
+
+ /**
+ * Test the requirement of responding with server terminated close code 1011 when there is an unhandled (internal
+ * server error) being produced by the extended WebSocketServlet.
+ */
+ @Test
+ public void testResponseOfHttpKeyword() throws Exception
+ {
+ WebSocketClientFactory clientFactory = new WebSocketClientFactory();
+ clientFactory.start();
+
+ WebSocketClient wsc = clientFactory.newWebSocketClient();
+ MessageSender sender = new MessageSender();
+ wsc.open(serverUri,sender);
+
+ String message = "GET";
+
+ try
+ {
+ sender.awaitConnect();
+
+ // echo back a http keyword
+ sender.sendMessage(message);
+
+ // Give servlet 500 millisecond to process messages
+ TimeUnit.MILLISECONDS.sleep(500);
+
+ sender.awaitMessage();
+
+ Assert.assertEquals("Message should match",message, sender.getMessage());
+ Assert.assertThat("WebSocket should be closed",sender.isConnected(),is(false));
+ Assert.assertThat("WebSocket close clode",sender.getCloseCode(),is(1000));
+ Assert.assertEquals("WebSocket close message",message, sender.getCloseMessage());
+
+ }
+ finally
+ {
+ sender.close();
+ }
+ }
}
diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/helper/MessageSender.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/helper/MessageSender.java
index 8b3e577..ecff608 100644
--- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/helper/MessageSender.java
+++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/helper/MessageSender.java
@@ -24,13 +24,17 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.websocket.WebSocket;
-public class MessageSender implements WebSocket
+public class MessageSender implements WebSocket, WebSocket.OnTextMessage
{
private Connection conn;
private CountDownLatch connectLatch = new CountDownLatch(1);
+ private CountDownLatch messageLatch = new CountDownLatch(1);
+
private int closeCode = -1;
private String closeMessage = null;
-
+ private String message = null;
+
+
public void onOpen(Connection connection)
{
this.conn = connection;
@@ -43,6 +47,12 @@ public class MessageSender implements WebSocket
this.closeCode = closeCode;
this.closeMessage = message;
}
+
+
+ public void onMessage(String data)
+ {
+ message = data;
+ }
public boolean isConnected()
{
@@ -62,6 +72,11 @@ public class MessageSender implements WebSocket
{
return closeMessage;
}
+
+ public String getMessage()
+ {
+ return message;
+ }
public void sendMessage(String format, Object... args) throws IOException
{
@@ -72,6 +87,11 @@ public class MessageSender implements WebSocket
{
connectLatch.await(1,TimeUnit.SECONDS);
}
+
+ public void awaitMessage() throws InterruptedException
+ {
+ messageLatch.await(1,TimeUnit.SECONDS);
+ }
public void close()
{