399343 - OnWebSocketConnect should use api.Session parameter instead.
+ Changed method signature for WebSocketListener and the various @OnWebSocket* annotations
This commit is contained in:
parent
871b64cf38
commit
4f48bc7e7b
|
@ -19,6 +19,7 @@
|
|||
package org.eclipse.jetty.websocket.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public interface Session
|
||||
{
|
||||
|
@ -35,6 +36,17 @@ public interface Session
|
|||
*/
|
||||
void close(CloseStatus closeStatus) throws IOException;
|
||||
|
||||
/**
|
||||
* Send a websocket Close frame, with status code.
|
||||
*
|
||||
* @param statusCode
|
||||
* the status code
|
||||
* @param reason
|
||||
* the (optional) reason. (can be null for no reason)
|
||||
* @see StatusCode
|
||||
*/
|
||||
void close(int statusCode, String reason) throws IOException;
|
||||
|
||||
/**
|
||||
* Return the number of milliseconds before this conversation will be closed by the container if it is inactive, ie no messages are either sent or received
|
||||
* in that time.
|
||||
|
@ -43,6 +55,13 @@ public interface Session
|
|||
*/
|
||||
long getIdleTimeout();
|
||||
|
||||
/**
|
||||
* Get the address of the local side.
|
||||
*
|
||||
* @return the local side address
|
||||
*/
|
||||
public InetSocketAddress getLocalAddress();
|
||||
|
||||
/**
|
||||
* The maximum total length of messages, text or binary, that this Session can handle.
|
||||
*
|
||||
|
@ -50,6 +69,13 @@ public interface Session
|
|||
*/
|
||||
long getMaximumMessageSize();
|
||||
|
||||
/**
|
||||
* Access the (now read-only) {@link WebSocketPolicy} in use for this connection.
|
||||
*
|
||||
* @return the policy in use
|
||||
*/
|
||||
WebSocketPolicy getPolicy();
|
||||
|
||||
/**
|
||||
* Returns the version of the websocket protocol currently being used. This is taken as the value of the Sec-WebSocket-Version header used in the opening
|
||||
* handshake. i.e. "13".
|
||||
|
@ -65,6 +91,13 @@ public interface Session
|
|||
*/
|
||||
RemoteEndpoint getRemote();
|
||||
|
||||
/**
|
||||
* Get the address of the remote side.
|
||||
*
|
||||
* @return the remote side address
|
||||
*/
|
||||
public InetSocketAddress getRemoteAddress();
|
||||
|
||||
/**
|
||||
* Get the UpgradeRequest used to create this session
|
||||
*
|
||||
|
@ -105,4 +138,11 @@ public interface Session
|
|||
* Sets the maximum total length of messages, text or binary, that this Session can handle.
|
||||
*/
|
||||
void setMaximumMessageSize(long length);
|
||||
|
||||
/**
|
||||
* Suspend a the incoming read events on the connection.
|
||||
*
|
||||
* @return the suspend token suitable for resuming the reading of data on the connection.
|
||||
*/
|
||||
SuspendToken suspend();
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.api;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.io.WebSocketBlockingConnection;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link WebSocketListener}.
|
||||
* <p>
|
||||
|
@ -27,27 +25,26 @@ import org.eclipse.jetty.websocket.api.io.WebSocketBlockingConnection;
|
|||
*/
|
||||
public class WebSocketAdapter implements WebSocketListener
|
||||
{
|
||||
private WebSocketConnection connection;
|
||||
private WebSocketBlockingConnection blocking;
|
||||
private Session session;
|
||||
|
||||
public WebSocketBlockingConnection getBlockingConnection()
|
||||
public RemoteEndpoint getRemote()
|
||||
{
|
||||
return blocking;
|
||||
return session.getRemote();
|
||||
}
|
||||
|
||||
public WebSocketConnection getConnection()
|
||||
public Session getSession()
|
||||
{
|
||||
return connection;
|
||||
return session;
|
||||
}
|
||||
|
||||
public boolean isConnected()
|
||||
{
|
||||
return (connection != null) && (connection.isOpen());
|
||||
return (session != null) && (session.isOpen());
|
||||
}
|
||||
|
||||
public boolean isNotConnected()
|
||||
{
|
||||
return (connection == null) || (!connection.isOpen());
|
||||
return (session == null) || (!session.isOpen());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,14 +56,13 @@ public class WebSocketAdapter implements WebSocketListener
|
|||
@Override
|
||||
public void onWebSocketClose(int statusCode, String reason)
|
||||
{
|
||||
this.connection = null;
|
||||
this.session = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnect(WebSocketConnection connection)
|
||||
public void onWebSocketConnect(Session sess)
|
||||
{
|
||||
this.connection = connection;
|
||||
this.blocking = new WebSocketBlockingConnection(this.connection);
|
||||
this.session = sess;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,7 +26,10 @@ import java.util.concurrent.Future;
|
|||
|
||||
/**
|
||||
* Connection interface for WebSocket protocol <a href="https://tools.ietf.org/html/rfc6455">RFC-6455</a>.
|
||||
*
|
||||
* @deprecated replaced with more JSR friendly {@link Session} interface
|
||||
*/
|
||||
@Deprecated
|
||||
public interface WebSocketConnection
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -48,24 +48,23 @@ public interface WebSocketListener
|
|||
void onWebSocketClose(int statusCode, String reason);
|
||||
|
||||
/**
|
||||
* A WebSocketConnection has connected successfully and is ready to be used.
|
||||
* A WebSocket {@link Session} has connected successfully and is ready to be used.
|
||||
* <p>
|
||||
* Note: It is a good idea to track this connection as a field in your object so that you can write messages back.
|
||||
* Note: It is a good idea to track this session as a field in your object so that you can write messages back via the {@link RemoteEndpoint}
|
||||
*
|
||||
* @param connection
|
||||
* the connection to use to send messages on.
|
||||
* @param session
|
||||
* the websocket session.
|
||||
*/
|
||||
void onWebSocketConnect(WebSocketConnection connection);
|
||||
void onWebSocketConnect(Session session);
|
||||
|
||||
/**
|
||||
* A WebSocket exception has occurred.
|
||||
* <p>
|
||||
* This is a way for the internal implementation to notify of exceptions occured during the processing of websocket.
|
||||
* <p>
|
||||
* Usually this occurs from bad / malformed incoming packets. (example: bad UTF8 data, frames that are too big, violations of the spec)
|
||||
* <p>
|
||||
* This will result in the {@link WebSocketConnection} being closed by the implementing side.
|
||||
* <p>
|
||||
* Note: you will receive no {@link #onWebSocketClose(int, String)} as this condition results in the API calling
|
||||
* {@link WebSocketConnection#close(int, String)} for you.
|
||||
* This will result in the {@link Session} being closed by the implementing side.
|
||||
*
|
||||
* @param error
|
||||
* the error that occurred.
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
|
||||
/**
|
||||
* Annotation for tagging methods to receive connection close events.
|
||||
|
@ -33,7 +33,7 @@ import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
|||
* Note: <code>methodName</code> can be any name you want to use.
|
||||
* <ol>
|
||||
* <li><code>public void methodName(int statusCode, String reason)</code></li>
|
||||
* <li><code>public void methodName({@link WebSocketConnection} conn, int statusCode, String reason)</code></li>
|
||||
* <li><code>public void methodName({@link Session} session, int statusCode, String reason)</code></li>
|
||||
* </ol>
|
||||
*/
|
||||
@Documented
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
|
||||
/**
|
||||
* Annotation for tagging methods to receive connection open events.
|
||||
|
@ -32,7 +32,7 @@ import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
|||
* Only 1 acceptable method pattern for this annotation.<br>
|
||||
* Note: <code>methodName</code> can be any name you want to use.
|
||||
* <ol>
|
||||
* <li><code>public void methodName({@link WebSocketConnection} conn)</code></li>
|
||||
* <li><code>public void methodName({@link Session} session)</code></li>
|
||||
* </ol>
|
||||
*/
|
||||
@Documented
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
|
||||
/**
|
||||
|
@ -34,6 +35,7 @@ import org.eclipse.jetty.websocket.api.WebSocketException;
|
|||
* <p>
|
||||
* <ol>
|
||||
* <li><code>public void methodName({@link WebSocketException} error)</code></li>
|
||||
* <li><code>public void methodName({@link Session} session, {@link WebSocketException} error)</code></li>
|
||||
* </ol>
|
||||
*/
|
||||
@Documented
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
|
||||
/**
|
||||
* (ADVANCED) Annotation for tagging methods to receive frame events.
|
||||
|
@ -35,7 +35,7 @@ import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
|||
* Note: <code>methodName</code> can be any name you want to use.
|
||||
* <ol>
|
||||
* <li><code>public void methodName({@link WebSocketFrame} frame)</code></li>
|
||||
* <li><code>public void methodName({@link WebSocketConnection} conn, {@link WebSocketFrame} frame)</code></li>
|
||||
* <li><code>public void methodName({@link Session} session, {@link WebSocketFrame} frame)</code></li>
|
||||
* </ol>
|
||||
*/
|
||||
@Documented
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
|
||||
/**
|
||||
* Annotation for tagging methods to receive Binary or Text Message events.
|
||||
|
@ -36,9 +36,9 @@ import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
|||
* <u>Text Message Versions</u>
|
||||
* <ol>
|
||||
* <li><code>public void methodName(String text)</code></li>
|
||||
* <li><code>public void methodName({@link WebSocketConnection} conn, String text)</code></li>
|
||||
* <li><code>public void methodName({@link Session} session, String text)</code></li>
|
||||
* <li><code>public void methodName(Reader reader)</code></li>
|
||||
* <li><code>public void methodName({@link WebSocketConnection} conn, Reader reader)</code></li>
|
||||
* <li><code>public void methodName({@link Session} session, Reader reader)</code></li>
|
||||
* </ol>
|
||||
* Note: that the {@link Reader} in this case will always use UTF-8 encoding/charset (this is dictated by the RFC 6455 spec for Text Messages. If you need to
|
||||
* use a non-UTF-8 encoding/charset, you are instructed to use the binary messaging techniques.
|
||||
|
@ -46,9 +46,9 @@ import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
|||
* <u>Binary Message Versions</u>
|
||||
* <ol>
|
||||
* <li><code>public void methodName(byte buf[], int offset, int length)</code></li>
|
||||
* <li><code>public void methodName({@link WebSocketConnection} conn, byte buf[], int offset, int length)</code></li>
|
||||
* <li><code>public void methodName({@link Session} session, byte buf[], int offset, int length)</code></li>
|
||||
* <li><code>public void methodName(InputStream stream)</code></li>
|
||||
* <li><code>public void methodName({@link WebSocketConnection} conn, InputStream stream)</code></li>
|
||||
* <li><code>public void methodName({@link Session} session, InputStream stream)</code></li>
|
||||
* </ol>
|
||||
*/
|
||||
@Documented
|
||||
|
|
|
@ -19,24 +19,23 @@
|
|||
package org.eclipse.jetty.websocket.api.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.RemoteEndpoint;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
|
||||
/**
|
||||
* For working with the {@link WebSocketConnection} in a blocking technique.
|
||||
* For working with the {@link Session} in a blocking technique.
|
||||
* <p>
|
||||
* This is an end-user accessible class.
|
||||
*/
|
||||
public class WebSocketBlockingConnection
|
||||
{
|
||||
private final WebSocketConnection conn;
|
||||
private final RemoteEndpoint remote;
|
||||
|
||||
public WebSocketBlockingConnection(WebSocketConnection conn)
|
||||
public WebSocketBlockingConnection(Session session)
|
||||
{
|
||||
this.conn = conn;
|
||||
this.remote = session.getRemote();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,19 +45,8 @@ public class WebSocketBlockingConnection
|
|||
*/
|
||||
public void write(byte[] data, int offset, int length) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Future<Void> blocker = conn.write(data,offset,length);
|
||||
blocker.get(); // block till finished
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
throw new WebSocketException("Blocking write failed",e);
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
throw new IOException(e.getCause());
|
||||
}
|
||||
ByteBuffer buf = ByteBuffer.wrap(data,offset,length);
|
||||
remote.sendBytes(buf);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,18 +56,6 @@ public class WebSocketBlockingConnection
|
|||
*/
|
||||
public void write(String message) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
Future<Void> blocker = conn.write(message);
|
||||
blocker.get(); // block till finished
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
throw new WebSocketException("Blocking write failed",e);
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
throw new IOException(e.getCause());
|
||||
}
|
||||
remote.sendString(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.eclipse.jetty.toolchain.test.TestTracker;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer;
|
||||
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection;
|
||||
import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection;
|
||||
|
@ -94,10 +93,10 @@ public class BadNetworkTest
|
|||
wsocket.waitForConnected(500,TimeUnit.MILLISECONDS);
|
||||
|
||||
// Have client disconnect abruptly
|
||||
WebSocketConnection conn = wsocket.getConnection();
|
||||
Session conn = wsocket.getSession();
|
||||
Assert.assertThat("Connection",conn,instanceOf(AbstractWebSocketConnection.class));
|
||||
AbstractWebSocketConnection awsc = (AbstractWebSocketConnection)conn;
|
||||
awsc.disconnect(false);
|
||||
awsc.disconnect(false); // FIXME: Session.disconnect
|
||||
|
||||
// Client Socket should see close
|
||||
wsocket.waitForClose(10,TimeUnit.SECONDS);
|
||||
|
|
|
@ -26,19 +26,20 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.RemoteEndpoint;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
|
||||
public class ClientWriteThread extends Thread
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(ClientWriteThread.class);
|
||||
private final WebSocketConnection conn;
|
||||
private final Session session;
|
||||
private int slowness = -1;
|
||||
private int messageCount = 100;
|
||||
private String message = "Hello";
|
||||
|
||||
public ClientWriteThread(WebSocketConnection conn)
|
||||
public ClientWriteThread(Session session)
|
||||
{
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public String getMessage()
|
||||
|
@ -66,9 +67,10 @@ public class ClientWriteThread extends Thread
|
|||
LOG.debug("Writing {} messages to connection {}",messageCount);
|
||||
LOG.debug("Artificial Slowness {} ms",slowness);
|
||||
Future<Void> lastMessage = null;
|
||||
RemoteEndpoint remote = session.getRemote();
|
||||
while (m.get() < messageCount)
|
||||
{
|
||||
lastMessage = conn.write(message + "/" + m.get() + "/");
|
||||
lastMessage = remote.sendStringByFuture(message + "/" + m.get() + "/");
|
||||
|
||||
m.incrementAndGet();
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ public class SlowClientTest
|
|||
// Have client write slowly.
|
||||
int messageCount = 1000;
|
||||
|
||||
ClientWriteThread writer = new ClientWriteThread(tsocket.getConnection());
|
||||
ClientWriteThread writer = new ClientWriteThread(tsocket.getSession());
|
||||
writer.setMessageCount(messageCount);
|
||||
writer.setMessage("Hello");
|
||||
writer.setSlowness(10);
|
||||
|
@ -108,7 +108,7 @@ public class SlowClientTest
|
|||
Assert.assertThat("Frame Receive Count",reader.getFrameCount(),is(messageCount));
|
||||
|
||||
// Close
|
||||
tsocket.getConnection().close(StatusCode.NORMAL,"Done");
|
||||
tsocket.getSession().close(StatusCode.NORMAL,"Done");
|
||||
|
||||
Assert.assertTrue("Client Socket Closed",tsocket.closeLatch.await(3,TimeUnit.MINUTES));
|
||||
tsocket.assertCloseCode(StatusCode.NORMAL);
|
||||
|
|
|
@ -100,7 +100,7 @@ public class SlowServerTest
|
|||
reader.start();
|
||||
|
||||
// Have client write as quickly as it can.
|
||||
ClientWriteThread writer = new ClientWriteThread(tsocket.getConnection());
|
||||
ClientWriteThread writer = new ClientWriteThread(tsocket.getSession());
|
||||
writer.setMessageCount(messageCount);
|
||||
writer.setMessage("Hello");
|
||||
writer.setSlowness(-1); // disable slowness
|
||||
|
@ -112,7 +112,7 @@ public class SlowServerTest
|
|||
Assert.assertThat("Frame Receive Count",reader.getFrameCount(),is(messageCount));
|
||||
|
||||
// Close
|
||||
tsocket.getConnection().close(StatusCode.NORMAL,"Done");
|
||||
tsocket.getSession().close(StatusCode.NORMAL,"Done");
|
||||
|
||||
Assert.assertTrue("Client Socket Closed",tsocket.closeLatch.await(10,TimeUnit.SECONDS));
|
||||
tsocket.assertCloseCode(StatusCode.NORMAL);
|
||||
|
|
|
@ -24,8 +24,8 @@ import java.nio.ByteBuffer;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer;
|
||||
import org.eclipse.jetty.websocket.client.blockhead.BlockheadServer.ServerConnection;
|
||||
import org.junit.Assert;
|
||||
|
@ -46,7 +46,7 @@ public class TomcatServerQuirksTest
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnect(WebSocketConnection connection)
|
||||
public void onWebSocketConnect(Session session)
|
||||
{
|
||||
openLatch.countDown();
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ import java.util.concurrent.TimeoutException;
|
|||
import org.eclipse.jetty.util.BlockingArrayQueue;
|
||||
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.WebSocketAdapter;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
|
@ -140,9 +140,9 @@ public class TrackingSocket extends WebSocketAdapter
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnect(WebSocketConnection connection)
|
||||
public void onWebSocketConnect(Session session)
|
||||
{
|
||||
super.onWebSocketConnect(connection);
|
||||
super.onWebSocketConnect(session);
|
||||
openLatch.countDown();
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ public class WebSocketClientTest
|
|||
|
||||
Assert.assertThat("client.connectionManager.sessions.size",client.getConnectionManager().getSessions().size(),is(1));
|
||||
|
||||
cliSock.getConnection().write("Hello World!");
|
||||
cliSock.getSession().getRemote().sendStringByFuture("Hello World!");
|
||||
srvSock.echoMessage(1,TimeUnit.MILLISECONDS,500);
|
||||
// wait for response from server
|
||||
cliSock.waitForMessage(500,TimeUnit.MILLISECONDS);
|
||||
|
@ -151,8 +151,8 @@ public class WebSocketClientTest
|
|||
|
||||
Assert.assertTrue(wsocket.openLatch.await(1,TimeUnit.SECONDS));
|
||||
|
||||
InetSocketAddress local = wsocket.getConnection().getLocalAddress();
|
||||
InetSocketAddress remote = wsocket.getConnection().getRemoteAddress();
|
||||
InetSocketAddress local = wsocket.getSession().getLocalAddress();
|
||||
InetSocketAddress remote = wsocket.getSession().getRemoteAddress();
|
||||
|
||||
Assert.assertThat("Local Socket Address",local,notNullValue());
|
||||
Assert.assertThat("Remote Socket Address",remote,notNullValue());
|
||||
|
@ -229,7 +229,7 @@ public class WebSocketClientTest
|
|||
|
||||
Assert.assertTrue(wsocket.openLatch.await(1,TimeUnit.SECONDS));
|
||||
|
||||
Session session = (Session)wsocket.getConnection();
|
||||
Session session = wsocket.getSession();
|
||||
UpgradeRequest req = session.getUpgradeRequest();
|
||||
Assert.assertThat("Upgrade Request",req,notNullValue());
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.eclipse.jetty.websocket.common.OpCode;
|
||||
|
@ -42,11 +42,6 @@ public class TestClient
|
|||
{
|
||||
public class TestSocket extends WebSocketAdapter
|
||||
{
|
||||
public void disconnect() throws Exception
|
||||
{
|
||||
super.getConnection().close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketBinary(byte[] payload, int offset, int len)
|
||||
{
|
||||
|
@ -59,11 +54,11 @@ public class TestClient
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnect(WebSocketConnection connection)
|
||||
public void onWebSocketConnect(Session session)
|
||||
{
|
||||
if (_verbose)
|
||||
{
|
||||
System.err.printf("%s#onWebSocketConnect %s %s\n",this.getClass().getSimpleName(),connection,connection.getClass().getSimpleName());
|
||||
System.err.printf("%s#onWebSocketConnect %s %s\n",this.getClass().getSimpleName(),session,session.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.websocket.api.InvalidWebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketListener;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
|
@ -77,31 +77,31 @@ public class EventDriverFactory
|
|||
static
|
||||
{
|
||||
validConnectParams = new ParamList();
|
||||
validConnectParams.addParams(WebSocketConnection.class);
|
||||
validConnectParams.addParams(Session.class);
|
||||
|
||||
validCloseParams = new ParamList();
|
||||
validCloseParams.addParams(int.class,String.class);
|
||||
validCloseParams.addParams(WebSocketConnection.class,int.class,String.class);
|
||||
validCloseParams.addParams(Session.class,int.class,String.class);
|
||||
|
||||
validErrorParams = new ParamList();
|
||||
validErrorParams.addParams(WebSocketException.class);
|
||||
validErrorParams.addParams(WebSocketConnection.class,WebSocketException.class);
|
||||
validErrorParams.addParams(Session.class,WebSocketException.class);
|
||||
|
||||
validTextParams = new ParamList();
|
||||
validTextParams.addParams(String.class);
|
||||
validTextParams.addParams(WebSocketConnection.class,String.class);
|
||||
validTextParams.addParams(Session.class,String.class);
|
||||
validTextParams.addParams(Reader.class);
|
||||
validTextParams.addParams(WebSocketConnection.class,Reader.class);
|
||||
validTextParams.addParams(Session.class,Reader.class);
|
||||
|
||||
validBinaryParams = new ParamList();
|
||||
validBinaryParams.addParams(byte[].class,int.class,int.class);
|
||||
validBinaryParams.addParams(WebSocketConnection.class,byte[].class,int.class,int.class);
|
||||
validBinaryParams.addParams(Session.class,byte[].class,int.class,int.class);
|
||||
validBinaryParams.addParams(InputStream.class);
|
||||
validBinaryParams.addParams(WebSocketConnection.class,InputStream.class);
|
||||
validBinaryParams.addParams(Session.class,InputStream.class);
|
||||
|
||||
validFrameParams = new ParamList();
|
||||
validFrameParams.addParams(Frame.class);
|
||||
validFrameParams.addParams(WebSocketConnection.class,Frame.class);
|
||||
validFrameParams.addParams(Session.class,Frame.class);
|
||||
}
|
||||
|
||||
private ConcurrentHashMap<Class<?>, EventMethods> cache;
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.lang.reflect.Method;
|
|||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
|
||||
public class EventMethod
|
||||
|
@ -45,7 +45,7 @@ public class EventMethod
|
|||
|
||||
protected Class<?> pojo;
|
||||
protected Method method;
|
||||
private boolean hasConnection = false;
|
||||
private boolean hasSession = false;
|
||||
private boolean isStreaming = false;
|
||||
private Class<?>[] paramTypes;
|
||||
|
||||
|
@ -120,7 +120,7 @@ public class EventMethod
|
|||
|
||||
private void identifyPresentParamTypes()
|
||||
{
|
||||
this.hasConnection = false;
|
||||
this.hasSession = false;
|
||||
this.isStreaming = false;
|
||||
|
||||
if (paramTypes == null)
|
||||
|
@ -130,9 +130,9 @@ public class EventMethod
|
|||
|
||||
for (Class<?> paramType : paramTypes)
|
||||
{
|
||||
if (WebSocketConnection.class.isAssignableFrom(paramType))
|
||||
if (Session.class.isAssignableFrom(paramType))
|
||||
{
|
||||
this.hasConnection = true;
|
||||
this.hasSession = true;
|
||||
}
|
||||
if (Reader.class.isAssignableFrom(paramType) || InputStream.class.isAssignableFrom(paramType))
|
||||
{
|
||||
|
@ -141,9 +141,9 @@ public class EventMethod
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isHasConnection()
|
||||
public boolean isHasSession()
|
||||
{
|
||||
return hasConnection;
|
||||
return hasSession;
|
||||
}
|
||||
|
||||
public boolean isStreaming()
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
package examples;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.common.events.EventCapture;
|
||||
|
||||
public class AdapterConnectCloseSocket extends WebSocketAdapter
|
||||
|
@ -33,8 +33,8 @@ public class AdapterConnectCloseSocket extends WebSocketAdapter
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnect(WebSocketConnection connection)
|
||||
public void onWebSocketConnect(Session sess)
|
||||
{
|
||||
capture.add("onWebSocketConnect(%s)",connection);
|
||||
capture.add("onWebSocketConnect(%s)",sess);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
package examples;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
|
@ -43,9 +43,9 @@ public class AnnotatedBinaryArraySocket
|
|||
}
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onConnect(WebSocketConnection conn)
|
||||
public void onConnect(Session sess)
|
||||
{
|
||||
capture.add("onConnect(%s)", conn);
|
||||
capture.add("onConnect(%s)",sess);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ package examples;
|
|||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
|
@ -45,9 +45,8 @@ public class AnnotatedBinaryStreamSocket
|
|||
}
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onConnect(WebSocketConnection conn)
|
||||
public void onConnect(Session sess)
|
||||
{
|
||||
capture.add("onConnect(%s)", conn);
|
||||
capture.add("onConnect(%s)",sess);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
package examples;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame;
|
||||
|
@ -38,9 +38,9 @@ public class AnnotatedFramesSocket
|
|||
}
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onConnect(WebSocketConnection conn)
|
||||
public void onConnect(Session sess)
|
||||
{
|
||||
capture.add("onConnect(%s)",conn);
|
||||
capture.add("onConnect(%s)",sess);
|
||||
}
|
||||
|
||||
@OnWebSocketFrame
|
||||
|
|
|
@ -21,7 +21,7 @@ package examples;
|
|||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame;
|
||||
|
@ -42,9 +42,9 @@ public class AnnotatedStreamingSocket
|
|||
}
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onConnect(WebSocketConnection conn)
|
||||
public void onConnect(Session sess)
|
||||
{
|
||||
capture.add("onConnect(%s)",conn);
|
||||
capture.add("onConnect(%s)",sess);
|
||||
}
|
||||
|
||||
@OnWebSocketFrame
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
package examples;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
|
@ -39,9 +39,9 @@ public class AnnotatedTextSocket
|
|||
}
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onConnect(WebSocketConnection conn)
|
||||
public void onConnect(Session sess)
|
||||
{
|
||||
capture.add("onConnect(%s)", conn);
|
||||
capture.add("onConnect(%s)",sess);
|
||||
}
|
||||
|
||||
@OnWebSocketError
|
||||
|
|
|
@ -20,7 +20,7 @@ package examples;
|
|||
|
||||
import java.io.Reader;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
|
@ -39,9 +39,9 @@ public class AnnotatedTextStreamSocket
|
|||
}
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onConnect(WebSocketConnection conn)
|
||||
public void onConnect(Session sess)
|
||||
{
|
||||
capture.add("onConnect(%s)", conn);
|
||||
capture.add("onConnect(%s)",sess);
|
||||
}
|
||||
|
||||
@OnWebSocketMessage
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
package examples;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketListener;
|
||||
import org.eclipse.jetty.websocket.common.events.EventCapture;
|
||||
|
@ -40,9 +40,9 @@ public class ListenerBasicSocket implements WebSocketListener
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnect(WebSocketConnection connection)
|
||||
public void onWebSocketConnect(Session session)
|
||||
{
|
||||
capture.add("onWebSocketConnect(%s)",connection);
|
||||
capture.add("onWebSocketConnect(%s)",session);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -44,7 +44,7 @@ public class AdapterEchoSocket extends WebSocketAdapter
|
|||
{
|
||||
LOG.debug("Echoing back message [{}]",message);
|
||||
// echo the data back
|
||||
getBlockingConnection().write(message);
|
||||
getRemote().sendString(message);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@ package examples.echo;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketListener;
|
||||
|
||||
|
@ -31,7 +31,7 @@ import org.eclipse.jetty.websocket.api.WebSocketListener;
|
|||
public class ListenerEchoSocket implements WebSocketListener
|
||||
{
|
||||
private static final Logger LOG = Logger.getLogger(ListenerEchoSocket.class.getName());
|
||||
private WebSocketConnection outbound;
|
||||
private Session outbound;
|
||||
|
||||
@Override
|
||||
public void onWebSocketBinary(byte[] payload, int offset, int len)
|
||||
|
@ -46,9 +46,9 @@ public class ListenerEchoSocket implements WebSocketListener
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnect(WebSocketConnection connection)
|
||||
public void onWebSocketConnect(Session session)
|
||||
{
|
||||
this.outbound = connection;
|
||||
this.outbound = session;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,6 +65,6 @@ public class ListenerEchoSocket implements WebSocketListener
|
|||
return;
|
||||
}
|
||||
|
||||
outbound.write(message);
|
||||
outbound.getRemote().sendStringByFuture(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.eclipse.jetty.websocket.common.annotations;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
|
@ -35,7 +35,7 @@ import org.eclipse.jetty.websocket.api.io.WebSocketBlockingConnection;
|
|||
@WebSocket
|
||||
public class MyEchoSocket
|
||||
{
|
||||
private WebSocketConnection conn;
|
||||
private Session session;
|
||||
private WebSocketBlockingConnection blocking;
|
||||
|
||||
public WebSocketBlockingConnection getConnection()
|
||||
|
@ -46,20 +46,20 @@ public class MyEchoSocket
|
|||
@OnWebSocketClose
|
||||
public void onClose(int statusCode, String reason)
|
||||
{
|
||||
this.conn = null;
|
||||
this.session = null;
|
||||
}
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onConnect(WebSocketConnection conn)
|
||||
public void onConnect(Session session)
|
||||
{
|
||||
this.conn = conn;
|
||||
this.blocking = new WebSocketBlockingConnection(conn);
|
||||
this.session = session;
|
||||
this.blocking = new WebSocketBlockingConnection(session);
|
||||
}
|
||||
|
||||
@OnWebSocketMessage
|
||||
public void onText(String message)
|
||||
{
|
||||
if (conn == null)
|
||||
if (session == null)
|
||||
{
|
||||
// no connection, do nothing.
|
||||
// this is possible due to async behavior
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.common.annotations;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
|
||||
|
@ -34,8 +34,8 @@ import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
|||
public class MyStatelessEchoSocket
|
||||
{
|
||||
@OnWebSocketMessage
|
||||
public void onText(WebSocketConnection conn, String text)
|
||||
public void onText(Session session, String text)
|
||||
{
|
||||
conn.write(text);
|
||||
session.getRemote().sendStringByFuture(text);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ public class EventDriverFactoryTest
|
|||
assertNoEventMethod(classId + ".onText",methods.onText);
|
||||
assertNoEventMethod(classId + ".onFrame",methods.onFrame);
|
||||
|
||||
Assert.assertFalse(classId + ".onBinary.hasConnection",methods.onBinary.isHasConnection());
|
||||
Assert.assertFalse(classId + ".onBinary.hasSession",methods.onBinary.isHasSession());
|
||||
Assert.assertFalse(classId + ".onBinary.isStreaming",methods.onBinary.isStreaming());
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ public class EventDriverFactoryTest
|
|||
assertNoEventMethod(classId + ".onText",methods.onText);
|
||||
assertNoEventMethod(classId + ".onFrame",methods.onFrame);
|
||||
|
||||
Assert.assertFalse(classId + ".onBinary.hasConnection",methods.onBinary.isHasConnection());
|
||||
Assert.assertFalse(classId + ".onBinary.hasSession",methods.onBinary.isHasSession());
|
||||
Assert.assertTrue(classId + ".onBinary.isStreaming",methods.onBinary.isStreaming());
|
||||
}
|
||||
|
||||
|
@ -263,7 +263,7 @@ public class EventDriverFactoryTest
|
|||
assertHasEventMethod(classId + ".onText",methods.onText);
|
||||
assertNoEventMethod(classId + ".onFrame",methods.onFrame);
|
||||
|
||||
Assert.assertTrue(classId + ".onText.hasConnection",methods.onText.isHasConnection());
|
||||
Assert.assertTrue(classId + ".onText.hasSession",methods.onText.isHasSession());
|
||||
Assert.assertFalse(classId + ".onText.isStreaming",methods.onText.isStreaming());
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ public class EventDriverFactoryTest
|
|||
assertHasEventMethod(classId + ".onText",methods.onText);
|
||||
assertNoEventMethod(classId + ".onFrame",methods.onFrame);
|
||||
|
||||
Assert.assertFalse(classId + ".onText.hasConnection",methods.onText.isHasConnection());
|
||||
Assert.assertFalse(classId + ".onText.hasSession",methods.onText.isHasSession());
|
||||
Assert.assertFalse(classId + ".onText.isStreaming",methods.onText.isStreaming());
|
||||
}
|
||||
|
||||
|
@ -353,7 +353,7 @@ public class EventDriverFactoryTest
|
|||
assertHasEventMethod(classId + ".onText",methods.onText);
|
||||
assertNoEventMethod(classId + ".onFrame",methods.onFrame);
|
||||
|
||||
Assert.assertFalse(classId + ".onText.hasConnection",methods.onText.isHasConnection());
|
||||
Assert.assertFalse(classId + ".onText.hasSession",methods.onText.isHasSession());
|
||||
Assert.assertTrue(classId + ".onText.isStreaming",methods.onText.isStreaming());
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.jetty.server.ServerConnector;
|
|||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.server.examples.MyEchoSocket;
|
||||
|
@ -139,19 +140,19 @@ public class WebSocketOverSSLTest
|
|||
final CountDownLatch serverLatch = new CountDownLatch(1);
|
||||
startServer(new WebSocketAdapter()
|
||||
{
|
||||
private WebSocketConnection connection;
|
||||
private Session session;
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnect(WebSocketConnection connection)
|
||||
public void onWebSocketConnect(Session session)
|
||||
{
|
||||
this.connection = connection;
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketText(String message)
|
||||
{
|
||||
Assert.assertEquals(message,message);
|
||||
connection.write(message);
|
||||
session.getRemote().sendStringByFuture(message);
|
||||
serverLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -18,9 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.server.ab;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
|
@ -33,7 +35,7 @@ public class ABSocket
|
|||
{
|
||||
private static Logger LOG = Log.getLogger(ABSocket.class);
|
||||
|
||||
private WebSocketConnection conn;
|
||||
private Session session;
|
||||
|
||||
private String abbreviate(String message)
|
||||
{
|
||||
|
@ -50,13 +52,14 @@ public class ABSocket
|
|||
LOG.debug("onBinary(byte[{}],{},{})",buf.length,offset,len);
|
||||
|
||||
// echo the message back.
|
||||
this.conn.write(buf,offset,len);
|
||||
ByteBuffer data = ByteBuffer.wrap(buf,offset,len);
|
||||
this.session.getRemote().sendBytesByFuture(data);
|
||||
}
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onOpen(WebSocketConnection conn)
|
||||
public void onOpen(Session sess)
|
||||
{
|
||||
this.conn = conn;
|
||||
this.session = sess;
|
||||
}
|
||||
|
||||
@OnWebSocketMessage
|
||||
|
@ -75,6 +78,6 @@ public class ABSocket
|
|||
}
|
||||
|
||||
// echo the message back.
|
||||
this.conn.write(message);
|
||||
this.session.getRemote().sendStringByFuture(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.eclipse.jetty.websocket.server.examples;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
|
||||
|
||||
|
@ -36,7 +37,8 @@ public class BasicEchoSocket extends WebSocketAdapter
|
|||
}
|
||||
try
|
||||
{
|
||||
getBlockingConnection().write(payload,offset,len);
|
||||
ByteBuffer buf = ByteBuffer.wrap(payload,offset,len);
|
||||
getRemote().sendBytes(buf);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
@ -53,7 +55,7 @@ public class BasicEchoSocket extends WebSocketAdapter
|
|||
}
|
||||
try
|
||||
{
|
||||
getBlockingConnection().write(message);
|
||||
getRemote().sendString(message);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
|
|
@ -38,7 +38,7 @@ public class MyEchoSocket extends WebSocketAdapter
|
|||
try
|
||||
{
|
||||
// echo the data back
|
||||
getBlockingConnection().write(message);
|
||||
getRemote().sendString(message);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.server.examples.echo;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketListener;
|
||||
|
||||
|
@ -50,11 +50,11 @@ public class LogSocket implements WebSocketListener
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnect(WebSocketConnection connection)
|
||||
public void onWebSocketConnect(Session session)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
System.err.printf("onWebSocketConnect(%s)%n",connection);
|
||||
System.err.printf("onWebSocketConnect(%s)%n",session);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.server.helper;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
|
@ -33,7 +35,7 @@ public class EchoSocket
|
|||
{
|
||||
private static Logger LOG = Log.getLogger(EchoSocket.class);
|
||||
|
||||
private WebSocketConnection conn;
|
||||
private Session session;
|
||||
|
||||
@OnWebSocketMessage
|
||||
public void onBinary(byte buf[], int offset, int len)
|
||||
|
@ -41,13 +43,14 @@ public class EchoSocket
|
|||
LOG.debug("onBinary(byte[{}],{},{})",buf.length,offset,len);
|
||||
|
||||
// echo the message back.
|
||||
this.conn.write(buf,offset,len);
|
||||
ByteBuffer data = ByteBuffer.wrap(buf,offset,len);
|
||||
this.session.getRemote().sendBytesByFuture(data);
|
||||
}
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onOpen(WebSocketConnection conn)
|
||||
public void onOpen(Session sess)
|
||||
{
|
||||
this.conn = conn;
|
||||
this.session = sess;
|
||||
}
|
||||
|
||||
@OnWebSocketMessage
|
||||
|
@ -56,6 +59,6 @@ public class EchoSocket
|
|||
LOG.debug("onText({})",message);
|
||||
|
||||
// echo the message back.
|
||||
this.conn.write(message);
|
||||
this.session.getRemote().sendStringByFuture(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.server.helper;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
|
@ -30,7 +32,7 @@ public class RFCSocket
|
|||
{
|
||||
private static Logger LOG = Log.getLogger(RFCSocket.class);
|
||||
|
||||
private WebSocketConnection conn;
|
||||
private Session session;
|
||||
|
||||
@OnWebSocketMessage
|
||||
public void onBinary(byte buf[], int offset, int len)
|
||||
|
@ -38,13 +40,14 @@ public class RFCSocket
|
|||
LOG.debug("onBinary(byte[{}],{},{})",buf.length,offset,len);
|
||||
|
||||
// echo the message back.
|
||||
this.conn.write(buf,offset,len);
|
||||
ByteBuffer data = ByteBuffer.wrap(buf,offset,len);
|
||||
this.session.getRemote().sendBytesByFuture(data);
|
||||
}
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onOpen(WebSocketConnection conn)
|
||||
public void onOpen(Session sess)
|
||||
{
|
||||
this.conn = conn;
|
||||
this.session = sess;
|
||||
}
|
||||
|
||||
@OnWebSocketMessage
|
||||
|
@ -59,6 +62,6 @@ public class RFCSocket
|
|||
}
|
||||
|
||||
// echo the message back.
|
||||
this.conn.write(message);
|
||||
this.session.getRemote().sendStringByFuture(message);
|
||||
}
|
||||
}
|
|
@ -23,7 +23,6 @@ import java.util.Map;
|
|||
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.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
|
@ -35,9 +34,9 @@ public class SessionSocket
|
|||
private Session session;
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onConnect(WebSocketConnection conn)
|
||||
public void onConnect(Session sess)
|
||||
{
|
||||
this.session = (Session)conn;
|
||||
this.session = sess;
|
||||
}
|
||||
|
||||
@OnWebSocketMessage
|
||||
|
|
|
@ -46,9 +46,9 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.api.UpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketConnection;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
|
@ -89,12 +89,12 @@ public class WebSocketChatServlet extends WebSocketServlet implements WebSocketC
|
|||
@WebSocket
|
||||
public class ChatWebSocket
|
||||
{
|
||||
volatile WebSocketConnection connection;
|
||||
volatile Session session;
|
||||
|
||||
@OnWebSocketConnect
|
||||
public void onOpen(WebSocketConnection conn)
|
||||
public void onOpen(Session sess)
|
||||
{
|
||||
connection = conn;
|
||||
session = sess;
|
||||
members.add(this);
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ public class WebSocketChatServlet extends WebSocketServlet implements WebSocketC
|
|||
{
|
||||
try
|
||||
{
|
||||
connection.close();
|
||||
session.close();
|
||||
}
|
||||
catch (IOException ignore)
|
||||
{
|
||||
|
@ -120,14 +120,14 @@ public class WebSocketChatServlet extends WebSocketServlet implements WebSocketC
|
|||
ChatWebSocket member = iter.next();
|
||||
|
||||
// Test if member is now disconnected
|
||||
if (!member.connection.isOpen())
|
||||
if (!member.session.isOpen())
|
||||
{
|
||||
iter.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Async write the message back.
|
||||
member.connection.write(data);
|
||||
member.session.getRemote().sendStringByFuture(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue