From 022b8d4a12b7bf91bc3034cb6a09f2c43e82ddd3 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 10 Jul 2013 16:35:50 -0700 Subject: [PATCH] JSR-356 - adding more examples of using Primitives for @OnMessage --- .../jsr356/annotations/JsrParamIdBinary.java | 10 +++ .../jsr356/annotations/JsrParamIdText.java | 25 +++++-- ...tedEndpointScanner_GoodSignaturesTest.java | 31 ++++++++- .../websocket/jsr356/server/StackUtil.java | 42 ++++++++++++ .../primitives/ByteObjectTextSocket.java | 66 +++++++++++++++++++ .../samples/primitives/ByteTextSocket.java | 59 +++++++++++++++++ .../samples/primitives/CharTextSocket.java | 59 +++++++++++++++++ .../primitives/CharacterObjectTextSocket.java | 66 +++++++++++++++++++ .../primitives/DoubleObjectTextSocket.java | 66 +++++++++++++++++++ .../samples/primitives/DoubleTextSocket.java | 59 +++++++++++++++++ .../primitives/FloatObjectTextSocket.java | 66 +++++++++++++++++++ .../samples/primitives/FloatTextSocket.java | 59 +++++++++++++++++ .../samples/primitives/IntTextSocket.java | 59 +++++++++++++++++ .../primitives/IntegerObjectTextSocket.java | 66 +++++++++++++++++++ .../primitives/LongObjectTextSocket.java | 66 +++++++++++++++++++ .../samples/primitives/LongTextSocket.java | 59 +++++++++++++++++ .../primitives/ShortObjectTextSocket.java | 66 +++++++++++++++++++ .../samples/primitives/ShortTextSocket.java | 59 +++++++++++++++++ .../samples/streaming/ReaderParamSocket.java | 65 ++++++++++++++++++ .../StringReturnReaderParamSocket.java | 56 ++++++++++++++++ 20 files changed, 1096 insertions(+), 8 deletions(-) create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/StackUtil.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ByteObjectTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ByteTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/CharTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/CharacterObjectTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/DoubleObjectTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/DoubleTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/FloatObjectTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/FloatTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/IntTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/IntegerObjectTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/LongObjectTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/LongTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ShortObjectTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ShortTextSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/streaming/ReaderParamSocket.java create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/streaming/StringReturnReaderParamSocket.java diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/annotations/JsrParamIdBinary.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/annotations/JsrParamIdBinary.java index d5ee1560b73..c790c6b765c 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/annotations/JsrParamIdBinary.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/annotations/JsrParamIdBinary.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.websocket.jsr356.annotations; +import java.io.InputStream; import java.nio.ByteBuffer; import javax.websocket.OnMessage; @@ -59,6 +60,15 @@ public class JsrParamIdBinary extends JsrParamIdOnMessage implements IJsrParamId return true; } + // Streaming + if (param.type.isAssignableFrom(InputStream.class)) + { + assertPartialMessageSupportDisabled(param,callable); + param.bind(Role.MESSAGE_BINARY_STREAM); + // Streaming have no decoder + return true; + } + // Boolean (for indicating partial message support) if (param.type.isAssignableFrom(Boolean.TYPE)) { diff --git a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/annotations/JsrParamIdText.java b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/annotations/JsrParamIdText.java index 33a560b59b6..21b7c06d0b7 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/annotations/JsrParamIdText.java +++ b/jetty-websocket/javax-websocket-client-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/annotations/JsrParamIdText.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.websocket.jsr356.annotations; +import java.io.Reader; + import javax.websocket.OnMessage; import javax.websocket.Session; @@ -66,49 +68,49 @@ public class JsrParamIdText extends JsrParamIdOnMessage implements IJsrParamId callable.setDecoderClass(BooleanDecoder.class); return true; } - if (param.type.isAssignableFrom(Byte.class)) + if (param.type.isAssignableFrom(Byte.class) || (param.type == Byte.TYPE)) { assertPartialMessageSupportDisabled(param,callable); param.bind(Role.MESSAGE_TEXT); callable.setDecoderClass(ByteDecoder.class); return true; } - if (param.type.isAssignableFrom(Character.class)) + if (param.type.isAssignableFrom(Character.class) || (param.type == Character.TYPE)) { assertPartialMessageSupportDisabled(param,callable); param.bind(Role.MESSAGE_TEXT); callable.setDecoderClass(CharacterDecoder.class); return true; } - if (param.type.isAssignableFrom(Double.class)) + if (param.type.isAssignableFrom(Double.class) || (param.type == Double.TYPE)) { assertPartialMessageSupportDisabled(param,callable); param.bind(Role.MESSAGE_TEXT); callable.setDecoderClass(DoubleDecoder.class); return true; } - if (param.type.isAssignableFrom(Float.class)) + if (param.type.isAssignableFrom(Float.class) || (param.type == Float.TYPE)) { assertPartialMessageSupportDisabled(param,callable); param.bind(Role.MESSAGE_TEXT); callable.setDecoderClass(FloatDecoder.class); return true; } - if (param.type.isAssignableFrom(Integer.class)) + if (param.type.isAssignableFrom(Integer.class) || (param.type == Integer.TYPE)) { assertPartialMessageSupportDisabled(param,callable); param.bind(Role.MESSAGE_TEXT); callable.setDecoderClass(IntegerDecoder.class); return true; } - if (param.type.isAssignableFrom(Long.class)) + if (param.type.isAssignableFrom(Long.class) || (param.type == Long.TYPE)) { assertPartialMessageSupportDisabled(param,callable); param.bind(Role.MESSAGE_TEXT); callable.setDecoderClass(LongDecoder.class); return true; } - if (param.type.isAssignableFrom(Short.class)) + if (param.type.isAssignableFrom(Short.class) || (param.type == Short.TYPE)) { assertPartialMessageSupportDisabled(param,callable); param.bind(Role.MESSAGE_TEXT); @@ -116,6 +118,15 @@ public class JsrParamIdText extends JsrParamIdOnMessage implements IJsrParamId return true; } + // Streaming + if (param.type.isAssignableFrom(Reader.class)) + { + assertPartialMessageSupportDisabled(param,callable); + param.bind(Role.MESSAGE_TEXT_STREAM); + // Streaming have no decoder + return true; + } + // Boolean (for indicating partial message support) if (param.type.isAssignableFrom(Boolean.TYPE)) { diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ServerAnnotatedEndpointScanner_GoodSignaturesTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ServerAnnotatedEndpointScanner_GoodSignaturesTest.java index eeaff9f8c1d..5b71e08fff7 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ServerAnnotatedEndpointScanner_GoodSignaturesTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ServerAnnotatedEndpointScanner_GoodSignaturesTest.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.jsr356.server; import static org.hamcrest.Matchers.*; +import java.io.Reader; import java.lang.reflect.Field; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -29,6 +30,8 @@ import java.util.List; import javax.websocket.CloseReason; import javax.websocket.PongMessage; import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; +import javax.websocket.server.ServerEndpointConfig; import org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner; import org.eclipse.jetty.websocket.jsr356.annotations.JsrCallable; @@ -47,6 +50,18 @@ import org.eclipse.jetty.websocket.jsr356.server.samples.BasicOpenSocket; import org.eclipse.jetty.websocket.jsr356.server.samples.BasicPongMessageSocket; import org.eclipse.jetty.websocket.jsr356.server.samples.BasicTextMessageStringSocket; import org.eclipse.jetty.websocket.jsr356.server.samples.StatelessTextMessageStringSocket; +import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.ByteObjectTextSocket; +import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.ByteTextSocket; +import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.CharTextSocket; +import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.CharacterObjectTextSocket; +import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.DoubleObjectTextSocket; +import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.DoubleTextSocket; +import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.FloatObjectTextSocket; +import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.FloatTextSocket; +import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.IntTextSocket; +import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.IntegerObjectTextSocket; +import org.eclipse.jetty.websocket.jsr356.server.samples.streaming.ReaderParamSocket; +import org.eclipse.jetty.websocket.jsr356.server.samples.streaming.StringReturnReaderParamSocket; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -113,6 +128,20 @@ public class ServerAnnotatedEndpointScanner_GoodSignaturesTest // -- Text Events Case.add(data, BasicTextMessageStringSocket.class, fText, String.class); Case.add(data, StatelessTextMessageStringSocket.class, fText, Session.class, String.class); + // -- Primitives + Case.add(data, ByteTextSocket.class, fText, Byte.TYPE); + Case.add(data, ByteObjectTextSocket.class, fText, Byte.class); + Case.add(data, CharTextSocket.class, fText, Character.TYPE); + Case.add(data, CharacterObjectTextSocket.class, fText, Character.class); + Case.add(data, DoubleTextSocket.class, fText, Double.TYPE); + Case.add(data, DoubleObjectTextSocket.class, fText, Double.class); + Case.add(data, FloatTextSocket.class, fText, Float.TYPE); + Case.add(data, FloatObjectTextSocket.class, fText, Float.class); + Case.add(data, IntTextSocket.class, fText, Integer.TYPE); + Case.add(data, IntegerObjectTextSocket.class, fText, Integer.class); + // -- Reader Events + Case.add(data, ReaderParamSocket.class, fText, Reader.class, String.class); + Case.add(data, StringReturnReaderParamSocket.class, fText, Reader.class, String.class); // -- Binary Events Case.add(data, BasicBinaryMessageByteBufferSocket.class, fBinary, ByteBuffer.class); // -- Pong Events @@ -140,7 +169,7 @@ public class ServerAnnotatedEndpointScanner_GoodSignaturesTest public void testScan_Basic() throws Exception { AnnotatedServerEndpointMetadata metadata = new AnnotatedServerEndpointMetadata(container,testcase.pojo); - AnnotatedEndpointScanner scanner = new AnnotatedEndpointScanner(metadata); + AnnotatedEndpointScanner scanner = new AnnotatedEndpointScanner<>(metadata); scanner.scan(); Assert.assertThat("Metadata",metadata,notNullValue()); diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/StackUtil.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/StackUtil.java new file mode 100644 index 00000000000..296c9471368 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/StackUtil.java @@ -0,0 +1,42 @@ +// +// ======================================================================== +// 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; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; + +public final class StackUtil +{ + public static String toString(Throwable t) + { + try (StringWriter w = new StringWriter()) + { + try (PrintWriter out = new PrintWriter(w)) + { + t.printStackTrace(out); + return w.toString(); + } + } + catch (IOException e) + { + return "Unable to get stacktrace for: " + t; + } + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ByteObjectTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ByteObjectTextSocket.java new file mode 100644 index 00000000000..e807b3957be --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ByteObjectTextSocket.java @@ -0,0 +1,66 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/byteobject") +public class ByteObjectTextSocket +{ + private static final Logger LOG = Log.getLogger(ByteObjectTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(Byte b) throws IOException + { + if (b == null) + { + session.getAsyncRemote().sendText("Error: Byte is null"); + } + else + { + String msg = String.format("0x%02x",b); + session.getAsyncRemote().sendText(msg); + } + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ByteTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ByteTextSocket.java new file mode 100644 index 00000000000..6a23b9679c0 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ByteTextSocket.java @@ -0,0 +1,59 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/byte") +public class ByteTextSocket +{ + private static final Logger LOG = Log.getLogger(ByteTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(byte b) throws IOException + { + String msg = String.format("0x%02x",b); + session.getAsyncRemote().sendText(msg); + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/CharTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/CharTextSocket.java new file mode 100644 index 00000000000..d7fee3cc617 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/CharTextSocket.java @@ -0,0 +1,59 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/char") +public class CharTextSocket +{ + private static final Logger LOG = Log.getLogger(CharTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(char c) throws IOException + { + String msg = Character.toString(c); + session.getAsyncRemote().sendText(msg); + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/CharacterObjectTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/CharacterObjectTextSocket.java new file mode 100644 index 00000000000..0b9f3472e65 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/CharacterObjectTextSocket.java @@ -0,0 +1,66 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/characterobject") +public class CharacterObjectTextSocket +{ + private static final Logger LOG = Log.getLogger(CharacterObjectTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(Character c) throws IOException + { + if (c == null) + { + session.getAsyncRemote().sendText("Error: Character is null"); + } + else + { + String msg = c.toString(); + session.getAsyncRemote().sendText(msg); + } + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/DoubleObjectTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/DoubleObjectTextSocket.java new file mode 100644 index 00000000000..38f66ca5871 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/DoubleObjectTextSocket.java @@ -0,0 +1,66 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/doubleobject") +public class DoubleObjectTextSocket +{ + private static final Logger LOG = Log.getLogger(DoubleObjectTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(Double d) throws IOException + { + if (d == null) + { + session.getAsyncRemote().sendText("Error: Double is null"); + } + else + { + String msg = d.toString(); + session.getAsyncRemote().sendText(msg); + } + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/DoubleTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/DoubleTextSocket.java new file mode 100644 index 00000000000..6cfd7d45d22 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/DoubleTextSocket.java @@ -0,0 +1,59 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/double") +public class DoubleTextSocket +{ + private static final Logger LOG = Log.getLogger(DoubleTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(double d) throws IOException + { + String msg = Double.toString(d); + session.getAsyncRemote().sendText(msg); + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/FloatObjectTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/FloatObjectTextSocket.java new file mode 100644 index 00000000000..37952dc41b7 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/FloatObjectTextSocket.java @@ -0,0 +1,66 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/floatobject") +public class FloatObjectTextSocket +{ + private static final Logger LOG = Log.getLogger(FloatObjectTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(Float f) throws IOException + { + if (f == null) + { + session.getAsyncRemote().sendText("Error: Float is null"); + } + else + { + String msg = f.toString(); + session.getAsyncRemote().sendText(msg); + } + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/FloatTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/FloatTextSocket.java new file mode 100644 index 00000000000..043c3ecd7be --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/FloatTextSocket.java @@ -0,0 +1,59 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/float") +public class FloatTextSocket +{ + private static final Logger LOG = Log.getLogger(FloatTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(float f) throws IOException + { + String msg = Float.toString(f); + session.getAsyncRemote().sendText(msg); + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/IntTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/IntTextSocket.java new file mode 100644 index 00000000000..0e35130ad69 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/IntTextSocket.java @@ -0,0 +1,59 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/integer") +public class IntTextSocket +{ + private static final Logger LOG = Log.getLogger(IntTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(int i) throws IOException + { + String msg = Integer.toString(i); + session.getAsyncRemote().sendText(msg); + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/IntegerObjectTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/IntegerObjectTextSocket.java new file mode 100644 index 00000000000..fa8fce54216 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/IntegerObjectTextSocket.java @@ -0,0 +1,66 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/integerobject") +public class IntegerObjectTextSocket +{ + private static final Logger LOG = Log.getLogger(IntegerObjectTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(Integer i) throws IOException + { + if (i == null) + { + session.getAsyncRemote().sendText("Error: Integer is null"); + } + else + { + String msg = i.toString(); + session.getAsyncRemote().sendText(msg); + } + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/LongObjectTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/LongObjectTextSocket.java new file mode 100644 index 00000000000..96e74fa085e --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/LongObjectTextSocket.java @@ -0,0 +1,66 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/longobject") +public class LongObjectTextSocket +{ + private static final Logger LOG = Log.getLogger(LongObjectTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(Long l) throws IOException + { + if (l == null) + { + session.getAsyncRemote().sendText("Error: Long is null"); + } + else + { + String msg = l.toString(); + session.getAsyncRemote().sendText(msg); + } + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/LongTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/LongTextSocket.java new file mode 100644 index 00000000000..cac58564352 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/LongTextSocket.java @@ -0,0 +1,59 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/long") +public class LongTextSocket +{ + private static final Logger LOG = Log.getLogger(LongTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(long l) throws IOException + { + String msg = Long.toString(l); + session.getAsyncRemote().sendText(msg); + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ShortObjectTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ShortObjectTextSocket.java new file mode 100644 index 00000000000..8f83284cad5 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ShortObjectTextSocket.java @@ -0,0 +1,66 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/shortobject") +public class ShortObjectTextSocket +{ + private static final Logger LOG = Log.getLogger(ShortObjectTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(Short s) throws IOException + { + if (s == null) + { + session.getAsyncRemote().sendText("Error: Short is null"); + } + else + { + String msg = s.toString(); + session.getAsyncRemote().sendText(msg); + } + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ShortTextSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ShortTextSocket.java new file mode 100644 index 00000000000..fc4d528dd62 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/primitives/ShortTextSocket.java @@ -0,0 +1,59 @@ +// +// ======================================================================== +// 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.primitives; + +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/primitives/short") +public class ShortTextSocket +{ + private static final Logger LOG = Log.getLogger(ShortTextSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onMessage(short s) throws IOException + { + String msg = Short.toString(s); + session.getAsyncRemote().sendText(msg); + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/streaming/ReaderParamSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/streaming/ReaderParamSocket.java new file mode 100644 index 00000000000..a15ca8476c3 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/streaming/ReaderParamSocket.java @@ -0,0 +1,65 @@ +// +// ======================================================================== +// 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.streaming; + +import java.io.IOException; +import java.io.Reader; + +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; + +import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.jsr356.server.StackUtil; + +@ServerEndpoint("/echo/streaming/readerparam/{param}") +public class ReaderParamSocket +{ + private static final Logger LOG = Log.getLogger(ReaderParamSocket.class); + + private Session session; + + @OnOpen + public void onOpen(Session session) + { + this.session = session; + } + + @OnMessage + public void onReader(Reader reader, @PathParam("param") String param) throws IOException + { + StringBuilder msg = new StringBuilder(); + msg.append(IO.toString(reader)); + msg.append('|'); + msg.append(param); + session.getAsyncRemote().sendText(msg.toString()); + } + + @OnError + public void onError(Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +} diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/streaming/StringReturnReaderParamSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/streaming/StringReturnReaderParamSocket.java new file mode 100644 index 00000000000..dfc2fb0c46d --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/samples/streaming/StringReturnReaderParamSocket.java @@ -0,0 +1,56 @@ +// +// ======================================================================== +// 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.streaming; + +import java.io.IOException; +import java.io.Reader; + +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; + +import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.websocket.jsr356.server.StackUtil; + +@ServerEndpoint("/stringreaderparam/{param}") +public class StringReturnReaderParamSocket +{ + private static final Logger LOG = Log.getLogger(StringReturnReaderParamSocket.class); + + @OnMessage + public String onReader(Reader reader, @PathParam("param") String param) throws IOException + { + StringBuilder msg = new StringBuilder(); + msg.append(IO.toString(reader)); + msg.append('|'); + msg.append(param); + return msg.toString(); + } + + @OnError + public void onError(Session session, Throwable cause) throws IOException + { + LOG.warn("Error",cause); + session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause)); + } +}