Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/partial/PartialTextSocket.java')
-rw-r--r--jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/partial/PartialTextSocket.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/partial/PartialTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/partial/PartialTextSocket.java
new file mode 100644
index 0000000000..009c3fa72d
--- /dev/null
+++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/partial/PartialTextSocket.java
@@ -0,0 +1,63 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.jsr356.server.samples.partial;
+
+import java.io.IOException;
+
+import javax.websocket.OnError;
+import javax.websocket.OnMessage;
+import javax.websocket.OnOpen;
+import javax.websocket.Session;
+import javax.websocket.server.ServerEndpoint;
+
+import org.eclipse.jetty.util.log.Log;
+import org.eclipse.jetty.util.log.Logger;
+import org.eclipse.jetty.websocket.jsr356.server.StackUtil;
+
+@ServerEndpoint("/echo/partial/text")
+public class PartialTextSocket
+{
+ private static final Logger LOG = Log.getLogger(PartialTextSocket.class);
+ private Session session;
+ private StringBuilder buf = new StringBuilder();
+
+ @OnOpen
+ public void onOpen(Session session)
+ {
+ this.session = session;
+ }
+
+ @OnMessage
+ public void onPartial(String msg, boolean fin) throws IOException
+ {
+ buf.append("('").append(msg).append("',").append(fin).append(')');
+ if (fin)
+ {
+ session.getBasicRemote().sendText(buf.toString());
+ buf.setLength(0);
+ }
+ }
+
+ @OnError
+ public void onError(Throwable cause) throws IOException
+ {
+ LOG.warn("Error",cause);
+ session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause));
+ }
+}

Back to the top