From 08161b5bf72b920697fd4e462b3611641d8f45dd Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 8 May 2013 11:22:42 -0700 Subject: [PATCH] Cleaning up examples for doc --- .../{MyExampleServlet.java => MyEchoServlet.java} | 11 +++++++---- .../{MyExampleSocket.java => MyEchoSocket.java} | 13 ++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) rename jetty-websocket/websocket-servlet/src/test/java/examples/{MyExampleServlet.java => MyEchoServlet.java} (79%) rename jetty-websocket/websocket-servlet/src/test/java/examples/{MyExampleSocket.java => MyEchoSocket.java} (71%) diff --git a/jetty-websocket/websocket-servlet/src/test/java/examples/MyExampleServlet.java b/jetty-websocket/websocket-servlet/src/test/java/examples/MyEchoServlet.java similarity index 79% rename from jetty-websocket/websocket-servlet/src/test/java/examples/MyExampleServlet.java rename to jetty-websocket/websocket-servlet/src/test/java/examples/MyEchoServlet.java index b81559a7543..cc778b01036 100644 --- a/jetty-websocket/websocket-servlet/src/test/java/examples/MyExampleServlet.java +++ b/jetty-websocket/websocket-servlet/src/test/java/examples/MyEchoServlet.java @@ -18,18 +18,21 @@ package examples; +import javax.servlet.annotation.WebServlet; + import org.eclipse.jetty.websocket.servlet.WebSocketServlet; import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; -@SuppressWarnings("serial") -public class MyExampleServlet extends WebSocketServlet +@WebServlet(name = "MyEcho WebSocket Servlet", urlPatterns = { "/echo" }) +public class MyEchoServlet extends WebSocketServlet { @Override public void configure(WebSocketServletFactory factory) { // set a 10 second timeout factory.getPolicy().setIdleTimeout(10000); - // register my socket - factory.register(MyExampleSocket.class); + + // register MyEchoSocket as the WebSocket to create on Upgrade + factory.register(MyEchoSocket.class); } } diff --git a/jetty-websocket/websocket-servlet/src/test/java/examples/MyExampleSocket.java b/jetty-websocket/websocket-servlet/src/test/java/examples/MyEchoSocket.java similarity index 71% rename from jetty-websocket/websocket-servlet/src/test/java/examples/MyExampleSocket.java rename to jetty-websocket/websocket-servlet/src/test/java/examples/MyEchoSocket.java index cffefaa6c89..cb3e016eef9 100644 --- a/jetty-websocket/websocket-servlet/src/test/java/examples/MyExampleSocket.java +++ b/jetty-websocket/websocket-servlet/src/test/java/examples/MyEchoSocket.java @@ -18,17 +18,20 @@ package examples; -import org.eclipse.jetty.websocket.api.WebSocketAdapter; +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; +import org.eclipse.jetty.websocket.api.annotations.WebSocket; /** * Example WebSocket, simple echo */ -public class MyExampleSocket extends WebSocketAdapter +@WebSocket +public class MyEchoSocket { - @Override - public void onWebSocketText(String message) + @OnWebSocketMessage + public void onWebSocketText(Session session, String message) { // Echo message back, asynchronously - getSession().getRemote().sendStringByFuture(message); + session.getRemote().sendStringByFuture(message); } }