Merge remote-tracking branch 'origin/master' into jetty-8
This commit is contained in:
commit
156e33bd23
|
@ -31,12 +31,11 @@ import org.eclipse.jetty.util.DateCache;
|
|||
* the eclipse jetty root level logger level to that specified level. (Default level is INFO)
|
||||
* <p>
|
||||
* If the system property "org.eclipse.jetty.util.log.SOURCE" is set, then the source method/file of a log is logged.
|
||||
* For named debuggers, the system property name+".SOURCE" is checked. If it is not not set, then
|
||||
* "org.eclipse.jetty.util.log.SOURCE" is used as the default.
|
||||
* For named debuggers, the system property name+".SOURCE" is checked, eg "org.eclipse.jetty.util.log.stderr.SOURCE".
|
||||
* If it is not not set, then "org.eclipse.jetty.util.log.SOURCE" is used as the default.
|
||||
* <p>
|
||||
* If the system property "org.eclipse.jetty.util.log.LONG" is set, then the full, unabbreviated name of the logger is
|
||||
* used for logging. For named debuggers, the system property name+".LONG" is checked. If it is not not set, then
|
||||
* "org.eclipse.jetty.util.log.LONG" is used as the default.
|
||||
* If the system property "org.eclipse.jetty.util.log.stderr.LONG" is set, then the full, unabbreviated name of the logger is
|
||||
* used for logging.
|
||||
*/
|
||||
public class StdErrLog extends AbstractLogger
|
||||
{
|
||||
|
|
|
@ -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