Author: markt
Date: Mon Dec 24 13:42:37 2012
New Revision: 1425647
URL: http://svn.apache.org/viewvc?rev=1425647&view=rev
Log:
Fix Ping/Pong issues identified by Autobahn
Added:
tomcat/trunk/java/org/apache/tomcat/websocket/WsIOException.java (with
props)
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java
tomcat/trunk/java/org/apache/tomcat/websocket/WsProtocolHandler.java
tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java?rev=1425647&r1=1425646&r2=1425647&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java Mon Dec 24
13:42:37 2012
@@ -34,7 +34,7 @@ import org.apache.tomcat.util.res.String
*/
public class WsFrame {
- private static StringManager sm =
+ private static final StringManager sm =
StringManager.getManager(Constants.PACKAGE_NAME);
// Connection level attributes
@@ -177,9 +177,11 @@ public class WsFrame {
}
if (isControl()) {
if (payloadLength > 125) {
- throw new IOException(sm.getString(
- "wsFrame.controlPayloadTooBig",
- Long.valueOf(payloadLength)));
+ CloseReason cr = new CloseReason(
+ CloseCodes.PROTOCOL_ERROR,
+ sm.getString("wsFrame.controlPayloadTooBig",
+ Long.valueOf(payloadLength)));
+ throw new WsIOException(cr);
}
if (!fin) {
throw new IOException("wsFrame.controlNoFin");
@@ -202,7 +204,7 @@ public class WsFrame {
if (opCode == Constants.OPCODE_CLOSE) {
messageBuffer.flip();
String reason = null;
- int code = CloseCodes.NO_STATUS_CODE.getCode();
+ int code = CloseCodes.NORMAL_CLOSURE.getCode();
if (messageBuffer.remaining() > 1) {
code = messageBuffer.getShort();
if (messageBuffer.remaining() > 0) {
Added: tomcat/trunk/java/org/apache/tomcat/websocket/WsIOException.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsIOException.java?rev=1425647&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsIOException.java (added)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsIOException.java Mon Dec 24
13:42:37 2012
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.websocket;
+
+import java.io.IOException;
+
+import javax.websocket.CloseReason;
+
+public class WsIOException extends IOException {
+
+ private static final long serialVersionUID = 1L;
+
+ private final CloseReason closeReason;
+
+ public WsIOException(CloseReason closeReason) {
+ this.closeReason = closeReason;
+ }
+
+ public CloseReason getCloseReason() {
+ return closeReason;
+ }
+}
Propchange: tomcat/trunk/java/org/apache/tomcat/websocket/WsIOException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsProtocolHandler.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsProtocolHandler.java?rev=1425647&r1=1425646&r2=1425647&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsProtocolHandler.java
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsProtocolHandler.java Mon
Dec 24 13:42:37 2012
@@ -111,19 +111,25 @@ public class WsProtocolHandler implement
public void onDataAvailable() {
try {
wsFrame.onDataAvailable();
- } catch (IOException e) {
- if (e instanceof EOFException){
- try {
- CloseReason cr = new CloseReason(
- CloseCodes.CLOSED_ABNORMALLY, e.getMessage());
- wsSession.onClose(cr);
- wsSession.close(cr);
- } catch (IOException e1) {
- // TODO
- }
- } else {
- onError(e);
+ } catch (WsIOException ws) {
+ CloseReason cr = ws.getCloseReason();
+ wsSession.onClose(cr);
+ try {
+ wsSession.close(cr);
+ } catch (IOException e) {
+ // TODO Log?
}
+ } catch (EOFException eof) {
+ try {
+ CloseReason cr = new CloseReason(
+ CloseCodes.CLOSED_ABNORMALLY, eof.getMessage());
+ wsSession.onClose(cr);
+ wsSession.close(cr);
+ } catch (IOException e1) {
+ // TODO Log?
+ }
+ } catch (IOException ioe) {
+ onError(ioe);
}
}
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java?rev=1425647&r1=1425646&r2=1425647&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Mon Dec 24
13:42:37 2012
@@ -46,8 +46,7 @@ public class WsSession implements Sessio
private WsRemoteEndpoint wsRemoteEndpoint;
private MessageHandler textMessageHandler = null;
private MessageHandler binaryMessageHandler = null;
- private MessageHandler.Basic<PongMessage> pongMessageHandler =
- new DefaultPingMessageHandler(this);
+ private MessageHandler.Basic<PongMessage> pongMessageHandler = null;
protected WsSession(Endpoint localEndpoint) {
this.localEndpoint = localEndpoint;
@@ -352,27 +351,6 @@ public class WsSession implements Sessio
}
- private static class DefaultPingMessageHandler implements
- MessageHandler.Basic<PongMessage> {
-
- private final WsSession wsSession;
-
-
- private DefaultPingMessageHandler(WsSession wsSession) {
- this.wsSession = wsSession;
- }
-
-
- @Override
- public void onMessage(PongMessage message) {
- RemoteEndpoint remoteEndpoint = wsSession.getRemote();
- if (remoteEndpoint != null) {
- remoteEndpoint.sendPong(message.getApplicationData());
- }
- }
- }
-
-
@Override
public String getId() {
// TODO Auto-generated method stub
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]