Author: markt
Date: Mon Jul 1 22:08:06 2013
New Revision: 1498719
URL: http://svn.apache.org/r1498719
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=55174
WebSocket 1.0
Javadoc for Endpoint.onError states that it should be called for runtime errors
in message handlers.
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java?rev=1498719&r1=1498718&r2=1498719&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java Mon Jul 1
22:08:06 2013
@@ -28,6 +28,7 @@ import javax.websocket.CloseReason.Close
import javax.websocket.MessageHandler;
import javax.websocket.PongMessage;
+import org.apache.tomcat.util.ExceptionUtils;
import org.apache.tomcat.util.buf.Utf8Decoder;
import org.apache.tomcat.util.res.StringManager;
@@ -312,7 +313,14 @@ public abstract class WsFrameBase {
MessageHandler.Whole<PongMessage> mhPong =
wsSession.getPongMessageHandler();
if (mhPong != null) {
- mhPong.onMessage(new WsPongMessage(controlBufferBinary));
+ try {
+ mhPong.onMessage(new WsPongMessage(controlBufferBinary));
+ } catch (Throwable t) {
+ ExceptionUtils.handleThrowable(t);
+ wsSession.getLocal().onError(wsSession, t);
+ } finally {
+ controlBufferBinary.clear();
+ }
}
} else {
// Should have caught this earlier but just in case...
@@ -344,15 +352,21 @@ public abstract class WsFrameBase {
}
}
- if (mh instanceof MessageHandler.Partial<?>) {
- ((MessageHandler.Partial<String>) mh).onMessage(
- messageBufferText.toString(), last);
- } else {
- // Caller ensures last == true if this branch is used
- ((MessageHandler.Whole<String>) mh).onMessage(
- messageBufferText.toString());
+ try {
+ if (mh instanceof MessageHandler.Partial<?>) {
+ ((MessageHandler.Partial<String>) mh).onMessage(
+ messageBufferText.toString(), last);
+ } else {
+ // Caller ensures last == true if this branch is used
+ ((MessageHandler.Whole<String>) mh).onMessage(
+ messageBufferText.toString());
+ }
+ } catch (Throwable t) {
+ ExceptionUtils.handleThrowable(t);
+ wsSession.getLocal().onError(wsSession, t);
+ } finally {
+ messageBufferText.clear();
}
- messageBufferText.clear();
}
}
@@ -520,11 +534,16 @@ public abstract class WsFrameBase {
Long.valueOf(maxMessageSize))));
}
}
- if (mh instanceof MessageHandler.Partial<?>) {
- ((MessageHandler.Partial<ByteBuffer>) mh).onMessage(msg, last);
- } else {
- // Caller ensures last == true if this branch is used
- ((MessageHandler.Whole<ByteBuffer>) mh).onMessage(msg);
+ try {
+ if (mh instanceof MessageHandler.Partial<?>) {
+ ((MessageHandler.Partial<ByteBuffer>) mh).onMessage(msg,
last);
+ } else {
+ // Caller ensures last == true if this branch is used
+ ((MessageHandler.Whole<ByteBuffer>) mh).onMessage(msg);
+ }
+ } catch(Throwable t) {
+ ExceptionUtils.handleThrowable(t);
+ wsSession.getLocal().onError(wsSession, t);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]