Merge branch 'jetty-9.3.x'

This commit is contained in:
Joakim Erdfelt 2016-03-25 13:25:22 -07:00
commit 0fe1bbcd91
4 changed files with 12 additions and 2 deletions

View File

@ -31,6 +31,7 @@ public class EchoHandler extends WebSocketHandler implements WebSocketCreator
@Override @Override
public void configure(WebSocketServletFactory factory) public void configure(WebSocketServletFactory factory)
{ {
factory.getPolicy().setMaxTextMessageSize(2 * 1024 * 1024);
factory.setCreator(this); factory.setCreator(this);
} }

View File

@ -38,6 +38,9 @@ public class JettyEchoSocket extends WebSocketAdapter
@Override @Override
public void onWebSocketBinary(byte[] payload, int offset, int len) public void onWebSocketBinary(byte[] payload, int offset, int len)
{ {
if (isNotConnected())
return;
try try
{ {
RemoteEndpoint remote = getRemote(); RemoteEndpoint remote = getRemote();
@ -60,6 +63,9 @@ public class JettyEchoSocket extends WebSocketAdapter
@Override @Override
public void onWebSocketText(String message) public void onWebSocketText(String message)
{ {
if (isNotConnected())
return;
try try
{ {
RemoteEndpoint remote = getRemote(); RemoteEndpoint remote = getRemote();

View File

@ -68,6 +68,7 @@ public class MessageReceivingTest {
public static void startServer() throws Exception { public static void startServer() throws Exception {
server = new Server(); server = new Server();
ServerConnector connector = new ServerConnector(server); ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.addConnector(connector); server.addConnector(connector);
handler = new EchoHandler(); handler = new EchoHandler();

View File

@ -26,11 +26,11 @@ package org.eclipse.jetty.websocket.api;
public class WebSocketAdapter implements WebSocketListener public class WebSocketAdapter implements WebSocketListener
{ {
private volatile Session session; private volatile Session session;
private RemoteEndpoint remote;
public RemoteEndpoint getRemote() public RemoteEndpoint getRemote()
{ {
Session sess = this.session; return remote;
return sess == null?null:session.getRemote();
} }
public Session getSession() public Session getSession()
@ -60,12 +60,14 @@ public class WebSocketAdapter implements WebSocketListener
public void onWebSocketClose(int statusCode, String reason) public void onWebSocketClose(int statusCode, String reason)
{ {
this.session = null; this.session = null;
this.remote = null;
} }
@Override @Override
public void onWebSocketConnect(Session sess) public void onWebSocketConnect(Session sess)
{ {
this.session = sess; this.session = sess;
this.remote = sess.getRemote();
} }
@Override @Override