Author: markt
Date: Tue Mar 1 00:24:52 2016
New Revision: 1732979
URL: http://svn.apache.org/viewvc?rev=1732979&view=rev
Log:
Extend the WebSocket programmatic echo endpoint provided in the examples to
handle binary messages and also partial messages. This aligns the code with
Tomcat 8 and makes it easier to run the Autobahn testsuite against the
WebSocket implementation.
Modified:
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1732979&r1=1732978&r2=1732979&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Tue Mar 1 00:24:52 2016
@@ -115,6 +115,12 @@
Correctly handle compression of partial messages when the final message
fragment has a zero length payload. (markt)
</fix>
+ <add>
+ Extend the WebSocket programmatic echo endpoint provided in the
examples
+ to handle binary messages and also partial messages. This aligns the
+ code with Tomcat 8 and makes it easier to run the Autobahn testsuite
+ against the WebSocket implementation. (markt)
+ </add>
</changelog>
</subsection>
<subsection name="Other">
Modified:
tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java?rev=1732979&r1=1732978&r2=1732979&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java
(original)
+++
tomcat/tc7.0.x/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java
Tue Mar 1 00:24:52 2016
@@ -17,6 +17,7 @@
package websocket.echo;
import java.io.IOException;
+import java.nio.ByteBuffer;
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfig;
@@ -29,23 +30,46 @@ public class EchoEndpoint extends Endpoi
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
RemoteEndpoint.Basic remoteEndpointBasic = session.getBasicRemote();
- session.addMessageHandler(new EchoMessageHandler(remoteEndpointBasic));
+ session.addMessageHandler(new
EchoMessageHandlerText(remoteEndpointBasic));
+ session.addMessageHandler(new
EchoMessageHandlerBinary(remoteEndpointBasic));
}
- private static class EchoMessageHandler
- implements MessageHandler.Whole<String> {
+ private static class EchoMessageHandlerText
+ implements MessageHandler.Partial<String> {
private final RemoteEndpoint.Basic remoteEndpointBasic;
- private EchoMessageHandler(RemoteEndpoint.Basic remoteEndpointBasic) {
+ private EchoMessageHandlerText(RemoteEndpoint.Basic
remoteEndpointBasic) {
this.remoteEndpointBasic = remoteEndpointBasic;
}
@Override
- public void onMessage(String message) {
+ public void onMessage(String message, boolean last) {
try {
if (remoteEndpointBasic != null) {
- remoteEndpointBasic.sendText(message);
+ remoteEndpointBasic.sendText(message, last);
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static class EchoMessageHandlerBinary
+ implements MessageHandler.Partial<ByteBuffer> {
+
+ private final RemoteEndpoint.Basic remoteEndpointBasic;
+
+ private EchoMessageHandlerBinary(RemoteEndpoint.Basic
remoteEndpointBasic) {
+ this.remoteEndpointBasic = remoteEndpointBasic;
+ }
+
+ @Override
+ public void onMessage(ByteBuffer message, boolean last) {
+ try {
+ if (remoteEndpointBasic != null) {
+ remoteEndpointBasic.sendBinary(message, last);
}
} catch (IOException e) {
// TODO Auto-generated catch block
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]