diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java index bf0a1826355..cb54e59fadb 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java @@ -90,6 +90,16 @@ public interface FrameHandler extends IncomingFrames */ void onFrame(Frame frame, Callback callback); + /** + * An error has occurred or been detected in websocket-core and being reported to FrameHandler. + * A call to onError will be followed by a call to {@link #onClosed(CloseStatus, Callback)} giving the close status + * derived from the error. + * + * @param cause the reason for the error + * @param callback the callback to indicate success in processing (or failure) + */ + void onError(Throwable cause, Callback callback); + /** * This is the Close Handshake Complete event. *

@@ -102,15 +112,6 @@ public interface FrameHandler extends IncomingFrames */ void onClosed(CloseStatus closeStatus, Callback callback); - /** - * An error has occurred or been detected in websocket-core and being reported to FrameHandler. - * A call to onError will be followed by a call to {@link #onClosed(CloseStatus, Callback)} giving the close status - * derived from the error. - * - * @param cause the reason for the error - * @param callback the callback to indicate success in processing (or failure) - */ - void onError(Throwable cause, Callback callback); /** * Does the FrameHandler manage it's own demand? @@ -216,22 +217,6 @@ public interface FrameHandler extends IncomingFrames */ boolean isSecure(); - /** - * Issue a harsh abort of the underlying connection. - *

- * This will terminate the connection, without sending a websocket close frame. - * No WebSocket Protocol close handshake will be performed. - *

- *

- * Once called, any read/write activity on the websocket from this point will be indeterminate. - * This can result in the {@link #onError(Throwable,Callback)} event being called indicating any issue that arises. - *

- *

- * Once the underlying connection has been determined to be closed, the {@link #onClosed(CloseStatus,Callback)} event will be called. - *

- */ - void abort(); - /** * @return Client or Server behaviour */ @@ -294,6 +279,22 @@ public interface FrameHandler extends IncomingFrames */ void close(int statusCode, String reason, Callback callback); + /** + * Issue a harsh abort of the underlying connection. + *

+ * This will terminate the connection, without sending a websocket close frame. + * No WebSocket Protocol close handshake will be performed. + *

+ *

+ * Once called, any read/write activity on the websocket from this point will be indeterminate. + * This can result in the {@link #onError(Throwable,Callback)} event being called indicating any issue that arises. + *

+ *

+ * Once the underlying connection has been determined to be closed, the {@link #onClosed(CloseStatus,Callback)} event will be called. + *

+ */ + void abort(); + /** * Manage flow control by indicating demand for handling Frames. A call to * {@link FrameHandler#onFrame(Frame, Callback)} will only be made if a diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannelState.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannelState.java index 251dc5e6d60..eceec214f69 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannelState.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannelState.java @@ -58,23 +58,23 @@ public class WebSocketChannelState { synchronized (this) { - if (_channelState != State.CONNECTED) - throw new IllegalStateException(_channelState.toString()); + switch(_channelState) + { + case CONNECTED: + _channelState = State.OPEN; + break; - _channelState = State.OPEN; + case OSHUT: + case CLOSED: + // Already closed in onOpen handler + break; + + default: + throw new IllegalStateException(_channelState.toString()); + } } } - @Override - public String toString() - { - return String.format("%s@%x{%s,i=%s,o=%s,c=%s}",getClass().getSimpleName(),hashCode(), - _channelState, - OpCode.name(_incomingContinuation), - OpCode.name(_outgoingContinuation), - _closeStatus); - } - public State getState() { @@ -205,6 +205,16 @@ public class WebSocketChannelState } + @Override + public String toString() + { + return String.format("%s@%x{%s,i=%s,o=%s,c=%s}",getClass().getSimpleName(),hashCode(), + _channelState, + OpCode.name(_incomingContinuation), + OpCode.name(_outgoingContinuation), + _closeStatus); + } + private static byte checkDataSequence(byte opcode, boolean fin, byte lastOpCode) throws ProtocolException { switch (opcode) diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/client/WebSocketClientServerTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/client/WebSocketClientServerTest.java index f564272c260..bf642358376 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/client/WebSocketClientServerTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/client/WebSocketClientServerTest.java @@ -113,6 +113,7 @@ public class WebSocketClientServerTest { LOG.info("channel aborted"); getCoreSession().abort(); + callback.failed(new Exception()); } else {