Author: remy.maucherat(a)jboss.com
Date: 2014-01-22 04:09:40 -0500 (Wed, 22 Jan 2014)
New Revision: 2350
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsFrameBase.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java
branches/7.4.x/src/main/java/org/jboss/web/WebsocketsMessages.java
Log:
Port patch: close after IO error.
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsFrameBase.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsFrameBase.java 2014-01-21
15:44:23 UTC (rev 2349)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsFrameBase.java 2014-01-22
09:09:40 UTC (rev 2350)
@@ -329,8 +329,7 @@
try {
mhPong.onMessage(new WsPongMessage(controlBufferBinary));
} catch (Throwable t) {
- ExceptionUtils.handleThrowable(t);
- wsSession.getLocal().onError(wsSession, t);
+ handleThrowableOnSend(t);
} finally {
controlBufferBinary.clear();
}
@@ -371,8 +370,7 @@
messageBufferText.toString());
}
} catch (Throwable t) {
- ExceptionUtils.handleThrowable(t);
- wsSession.getLocal().onError(wsSession, t);
+ handleThrowableOnSend(t);
} finally {
messageBufferText.clear();
}
@@ -525,6 +523,15 @@
}
+ private void handleThrowableOnSend(Throwable t) throws WsIOException {
+ ExceptionUtils.handleThrowable(t);
+ wsSession.getLocal().onError(wsSession, t);
+ CloseReason cr = new CloseReason(CloseCodes.CLOSED_ABNORMALLY,
+ MESSAGES.closeAfterError());
+ throw new WsIOException(cr);
+ }
+
+
@SuppressWarnings("unchecked")
private void sendMessageBinary(ByteBuffer msg, boolean last)
throws WsIOException {
@@ -546,8 +553,7 @@
((MessageHandler.Whole<ByteBuffer>)
binaryMsgHandler).onMessage(msg);
}
} catch(Throwable t) {
- ExceptionUtils.handleThrowable(t);
- wsSession.getLocal().onError(wsSession, t);
+ handleThrowableOnSend(t);
}
}
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java 2014-01-21
15:44:23 UTC (rev 2349)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java 2014-01-22
09:09:40 UTC (rev 2350)
@@ -462,7 +462,13 @@
// 125 is maximum size for the payload of a control message
ByteBuffer msg = ByteBuffer.allocate(125);
CloseCode closeCode = closeReason.getCloseCode();
- msg.putShort((short) closeCode.getCode());
+ // CLOSED_ABNORMALLY should not be put on the wire
+ if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
+ // PROTOCOL_ERROR is probably better than GOING_AWAY here
+ msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
+ } else {
+ msg.putShort((short) closeCode.getCode());
+ }
String reason = closeReason.getReasonPhrase();
if (reason != null && reason.length() > 0) {
Modified: branches/7.4.x/src/main/java/org/jboss/web/WebsocketsMessages.java
===================================================================
--- branches/7.4.x/src/main/java/org/jboss/web/WebsocketsMessages.java 2014-01-21 15:44:23
UTC (rev 2349)
+++ branches/7.4.x/src/main/java/org/jboss/web/WebsocketsMessages.java 2014-01-22 09:09:40
UTC (rev 2350)
@@ -305,4 +305,7 @@
@Message(id = 8589, value = "The maximum supported message size for this
implementation is Integer.MAX_VALUE")
IllegalArgumentException messageTooLarge();
+ @Message(id = 8590, value = "Closing session following IO error")
+ String closeAfterError();
+
}
Show replies by date