diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/Session.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/Session.java index 9771f8296cc..a73959af711 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/Session.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/Session.java @@ -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(); } diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketAdapter.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketAdapter.java index ad0091192ab..f3a1fa70b4e 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketAdapter.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketAdapter.java @@ -18,8 +18,6 @@ package org.eclipse.jetty.websocket.api; -import org.eclipse.jetty.websocket.api.io.WebSocketBlockingConnection; - /** * Default implementation of the {@link WebSocketListener}. *

@@ -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 diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnection.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnection.java index bc76da6590b..472fa0112c7 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnection.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnection.java @@ -26,7 +26,10 @@ import java.util.concurrent.Future; /** * Connection interface for WebSocket protocol RFC-6455. + * + * @deprecated replaced with more JSR friendly {@link Session} interface */ +@Deprecated public interface WebSocketConnection { /** diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketListener.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketListener.java index d86cc033e08..786c9fb8eae 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketListener.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketListener.java @@ -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. *

- * 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. *

+ * This is a way for the internal implementation to notify of exceptions occured during the processing of websocket. + *

* Usually this occurs from bad / malformed incoming packets. (example: bad UTF8 data, frames that are too big, violations of the spec) *

- * This will result in the {@link WebSocketConnection} being closed by the implementing side. - *

- * 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. diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketClose.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketClose.java index 38f5a85770b..cd348b9a090 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketClose.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketClose.java @@ -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: methodName can be any name you want to use. *

    *
  1. public void methodName(int statusCode, String reason)
  2. - *
  3. public void methodName({@link WebSocketConnection} conn, int statusCode, String reason)
  4. + *
  5. public void methodName({@link Session} session, int statusCode, String reason)
  6. *
*/ @Documented diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketConnect.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketConnect.java index cda8f2a3489..f9e427e0d56 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketConnect.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketConnect.java @@ -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.
* Note: methodName can be any name you want to use. *
    - *
  1. public void methodName({@link WebSocketConnection} conn)
  2. + *
  3. public void methodName({@link Session} session)
  4. *
*/ @Documented diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketError.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketError.java index 8fbf14f3381..ea4412e5e90 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketError.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketError.java @@ -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; *

*

    *
  1. public void methodName({@link WebSocketException} error)
  2. + *
  3. public void methodName({@link Session} session, {@link WebSocketException} error)
  4. *
*/ @Documented diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketFrame.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketFrame.java index 3437c8c7703..532c5901ad8 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketFrame.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketFrame.java @@ -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: methodName can be any name you want to use. *
    *
  1. public void methodName({@link WebSocketFrame} frame)
  2. - *
  3. public void methodName({@link WebSocketConnection} conn, {@link WebSocketFrame} frame)
  4. + *
  5. public void methodName({@link Session} session, {@link WebSocketFrame} frame)
  6. *
*/ @Documented diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketMessage.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketMessage.java index f7f42d5fa50..9d628770557 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketMessage.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketMessage.java @@ -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; * Text Message Versions *
    *
  1. public void methodName(String text)
  2. - *
  3. public void methodName({@link WebSocketConnection} conn, String text)
  4. + *
  5. public void methodName({@link Session} session, String text)
  6. *
  7. public void methodName(Reader reader)
  8. - *
  9. public void methodName({@link WebSocketConnection} conn, Reader reader)
  10. + *
  11. public void methodName({@link Session} session, Reader reader)
  12. *
* 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; * Binary Message Versions *
    *
  1. public void methodName(byte buf[], int offset, int length)
  2. - *
  3. public void methodName({@link WebSocketConnection} conn, byte buf[], int offset, int length)
  4. + *
  5. public void methodName({@link Session} session, byte buf[], int offset, int length)
  6. *
  7. public void methodName(InputStream stream)
  8. - *
  9. public void methodName({@link WebSocketConnection} conn, InputStream stream)
  10. + *
  11. public void methodName({@link Session} session, InputStream stream)
  12. *
*/ @Documented diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketBlockingConnection.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketBlockingConnection.java index 6e3ae25d5d0..69c36a0a5a9 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketBlockingConnection.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketBlockingConnection.java @@ -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. *

* 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 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 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); } } diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java index 77d35597b55..4936b710b47 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/BadNetworkTest.java @@ -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); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientWriteThread.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientWriteThread.java index 61626f8dbcc..0d41b175b4c 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientWriteThread.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientWriteThread.java @@ -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 lastMessage = null; + RemoteEndpoint remote = session.getRemote(); while (m.get() < messageCount) { - lastMessage = conn.write(message + "/" + m.get() + "/"); + lastMessage = remote.sendStringByFuture(message + "/" + m.get() + "/"); m.incrementAndGet(); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java index 6ad3388db82..49ca8c1ac2f 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowClientTest.java @@ -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); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java index 7eb1ff0a850..741d8fa4f40 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/SlowServerTest.java @@ -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); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TomcatServerQuirksTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TomcatServerQuirksTest.java index 8342802f0b9..a97c255572c 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TomcatServerQuirksTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TomcatServerQuirksTest.java @@ -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(); } diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TrackingSocket.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TrackingSocket.java index 68fd883d08f..01a3eb2423f 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TrackingSocket.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/TrackingSocket.java @@ -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(); } diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java index 34c4dc75d08..efe1e16b154 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java @@ -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()); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java index bd87e0d02ec..f7974210412 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java @@ -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()); } } diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/EventDriverFactory.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/EventDriverFactory.java index e05f9e7ffe9..8eac8444b73 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/EventDriverFactory.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/EventDriverFactory.java @@ -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, EventMethods> cache; diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/EventMethod.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/EventMethod.java index ba584b289b7..e551d265656 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/EventMethod.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/EventMethod.java @@ -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() diff --git a/jetty-websocket/websocket-common/src/test/java/examples/AdapterConnectCloseSocket.java b/jetty-websocket/websocket-common/src/test/java/examples/AdapterConnectCloseSocket.java index 762eed657b0..72b9efc6031 100644 --- a/jetty-websocket/websocket-common/src/test/java/examples/AdapterConnectCloseSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/examples/AdapterConnectCloseSocket.java @@ -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); } } diff --git a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedBinaryArraySocket.java b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedBinaryArraySocket.java index 7033fe7c62b..135da233121 100644 --- a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedBinaryArraySocket.java +++ b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedBinaryArraySocket.java @@ -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); } } diff --git a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedBinaryStreamSocket.java b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedBinaryStreamSocket.java index 8c98d38608a..d0e3b904892 100644 --- a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedBinaryStreamSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedBinaryStreamSocket.java @@ -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); } - } diff --git a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedFramesSocket.java b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedFramesSocket.java index 29750d9abba..b6c36328d93 100644 --- a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedFramesSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedFramesSocket.java @@ -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 diff --git a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedStreamingSocket.java b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedStreamingSocket.java index 30806d8952f..8596f9b3cc0 100644 --- a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedStreamingSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedStreamingSocket.java @@ -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 diff --git a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedTextSocket.java b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedTextSocket.java index 0eb2fe63203..0dcd73cfe91 100644 --- a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedTextSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedTextSocket.java @@ -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 diff --git a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedTextStreamSocket.java b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedTextStreamSocket.java index 98340404b98..e8f55b121f9 100644 --- a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedTextStreamSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedTextStreamSocket.java @@ -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 diff --git a/jetty-websocket/websocket-common/src/test/java/examples/ListenerBasicSocket.java b/jetty-websocket/websocket-common/src/test/java/examples/ListenerBasicSocket.java index 8a12c4a4f36..02b21778b03 100644 --- a/jetty-websocket/websocket-common/src/test/java/examples/ListenerBasicSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/examples/ListenerBasicSocket.java @@ -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 diff --git a/jetty-websocket/websocket-common/src/test/java/examples/echo/AdapterEchoSocket.java b/jetty-websocket/websocket-common/src/test/java/examples/echo/AdapterEchoSocket.java index c4dd5978db3..a0cca6d7902 100644 --- a/jetty-websocket/websocket-common/src/test/java/examples/echo/AdapterEchoSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/examples/echo/AdapterEchoSocket.java @@ -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) { diff --git a/jetty-websocket/websocket-common/src/test/java/examples/echo/ListenerEchoSocket.java b/jetty-websocket/websocket-common/src/test/java/examples/echo/ListenerEchoSocket.java index d22f5743a69..a70ddbd544a 100644 --- a/jetty-websocket/websocket-common/src/test/java/examples/echo/ListenerEchoSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/examples/echo/ListenerEchoSocket.java @@ -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); } } diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/MyEchoSocket.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/MyEchoSocket.java index 25f7d99d98b..7c8205ac639 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/MyEchoSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/MyEchoSocket.java @@ -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 diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/MyStatelessEchoSocket.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/MyStatelessEchoSocket.java index b2b74220071..1a36a940b0e 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/MyStatelessEchoSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/MyStatelessEchoSocket.java @@ -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); } } diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/events/EventDriverFactoryTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/events/EventDriverFactoryTest.java index cf7b137ad47..a0a6f39ef3d 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/events/EventDriverFactoryTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/events/EventDriverFactoryTest.java @@ -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()); } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketOverSSLTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketOverSSLTest.java index 504d5e8dd51..920793a9e46 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketOverSSLTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketOverSSLTest.java @@ -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(); } }); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABSocket.java index 29e18ff0ee3..a510e74d953 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABSocket.java @@ -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); } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/BasicEchoSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/BasicEchoSocket.java index b0be837c518..a6b4b6df520 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/BasicEchoSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/BasicEchoSocket.java @@ -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) { diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/MyEchoSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/MyEchoSocket.java index 2b8be065cf7..8e9a0202222 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/MyEchoSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/MyEchoSocket.java @@ -38,7 +38,7 @@ public class MyEchoSocket extends WebSocketAdapter try { // echo the data back - getBlockingConnection().write(message); + getRemote().sendString(message); } catch (IOException e) { diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/echo/LogSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/echo/LogSocket.java index 09722e6bd74..5a75ac063ed 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/echo/LogSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/echo/LogSocket.java @@ -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); } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/EchoSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/EchoSocket.java index 0b0c74aeae4..89d7e0e9629 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/EchoSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/EchoSocket.java @@ -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); } } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/RFCSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/RFCSocket.java index e87550b02ce..9d03d04c760 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/RFCSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/RFCSocket.java @@ -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); } } \ No newline at end of file diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/SessionSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/SessionSocket.java index ca12ac91963..a5f6c3e3696 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/SessionSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/SessionSocket.java @@ -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 diff --git a/tests/test-webapps/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java b/tests/test-webapps/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java index 037994f9dc5..836aa0cdfe7 100644 --- a/tests/test-webapps/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java +++ b/tests/test-webapps/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java @@ -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); } }