add websocket test for http keyword in response message from reported issue
This commit is contained in:
parent
af233a8a37
commit
494f7e48fc
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue