You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/02/09 21:22:08 UTC

svn commit: r1444422 - in /tomcat/trunk/test/org/apache/tomcat/websocket: TestWsWebSocketContainer.java TesterEcho.java

Author: markt
Date: Sat Feb  9 20:22:07 2013
New Revision: 1444422

URL: http://svn.apache.org/r1444422
Log:
Extract Echo endpoints for use in other tests

Added:
    tomcat/trunk/test/org/apache/tomcat/websocket/TesterEcho.java   (with props)
Modified:
    tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java

Modified: tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java?rev=1444422&r1=1444421&r2=1444422&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java Sat Feb  9 20:22:07 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.tomcat.websocket;
 
-import java.io.IOException;
 import java.net.URI;
 import java.nio.ByteBuffer;
 import java.util.List;
@@ -74,7 +73,7 @@ public class TestWsWebSocketContainer ex
         // Must have a real docBase - just use temp
         Context ctx =
             tomcat.addContext("", System.getProperty("java.io.tmpdir"));
-        ctx.addApplicationListener(EchoConfig.class.getName());
+        ctx.addApplicationListener(TesterEcho.Config.class.getName());
 
         tomcat.start();
 
@@ -82,7 +81,7 @@ public class TestWsWebSocketContainer ex
                 ContainerProvider.createClientContainer();
         Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
                 new DefaultClientConfiguration(), new URI("http://localhost:" +
-                        getPort() + EchoConfig.PATH_ASYNC));
+                        getPort() + TesterEcho.Config.PATH_ASYNC));
         CountDownLatch latch = new CountDownLatch(1);
         TesterMessageHandlerText handler = new TesterMessageHandlerText(latch);
         wsSession.addMessageHandler(handler);
@@ -104,7 +103,7 @@ public class TestWsWebSocketContainer ex
         // Must have a real docBase - just use temp
         Context ctx =
             tomcat.addContext("", System.getProperty("java.io.tmpdir"));
-        ctx.addApplicationListener(EchoConfig.class.getName());
+        ctx.addApplicationListener(TesterEcho.Config.class.getName());
 
         tomcat.start();
 
@@ -112,7 +111,7 @@ public class TestWsWebSocketContainer ex
                 ContainerProvider.createClientContainer();
         wsContainer.connectToServer(TesterEndpoint.class,
                 new DefaultClientConfiguration(), new URI("ftp://localhost:" +
-                        getPort() + EchoConfig.PATH_ASYNC));
+                        getPort() + TesterEcho.Config.PATH_ASYNC));
     }
 
 
@@ -122,7 +121,7 @@ public class TestWsWebSocketContainer ex
         // Must have a real docBase - just use temp
         Context ctx =
             tomcat.addContext("", System.getProperty("java.io.tmpdir"));
-        ctx.addApplicationListener(EchoConfig.class.getName());
+        ctx.addApplicationListener(TesterEcho.Config.class.getName());
 
         tomcat.start();
 
@@ -130,7 +129,7 @@ public class TestWsWebSocketContainer ex
                 ContainerProvider.createClientContainer();
         wsContainer.connectToServer(TesterEndpoint.class,
                 new DefaultClientConfiguration(),
-                new URI("http://" + EchoConfig.PATH_ASYNC));
+                new URI("http://" + TesterEcho.Config.PATH_ASYNC));
     }
 
 
@@ -189,7 +188,7 @@ public class TestWsWebSocketContainer ex
         // Must have a real docBase - just use temp
         Context ctx =
             tomcat.addContext("", System.getProperty("java.io.tmpdir"));
-        ctx.addApplicationListener(EchoConfig.class.getName());
+        ctx.addApplicationListener(TesterEcho.Config.class.getName());
 
         WebSocketContainer wsContainer =
                 ContainerProvider.createClientContainer();
@@ -218,7 +217,7 @@ public class TestWsWebSocketContainer ex
 
         Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
                 new DefaultClientConfiguration(), new URI("http://localhost:" +
-                        getPort() + EchoConfig.PATH_BASIC));
+                        getPort() + TesterEcho.Config.PATH_BASIC));
         TesterMessageHandler<?> handler;
         CountDownLatch latch = new CountDownLatch(1);
         wsSession.getUserProperties().put("latch", latch);
@@ -485,89 +484,6 @@ public class TestWsWebSocketContainer ex
     }
 
 
-    public static class EchoConfig implements ServletContextListener {
-
-        public static final String PATH_ASYNC = "/echoAsync";
-        public static final String PATH_BASIC = "/echoBasic";
-
-        @Override
-        public void contextInitialized(ServletContextEvent sce) {
-            ServerContainerImpl sc = ServerContainerImpl.getServerContainer();
-            sc.publishServer(
-                    EchoAsync.class, sce.getServletContext(), PATH_ASYNC);
-            sc.publishServer(
-                    EchoBasic.class, sce.getServletContext(), PATH_BASIC);
-        }
-
-        @Override
-        public void contextDestroyed(ServletContextEvent sce) {
-            // NO-OP
-        }
-    }
-
-
-    public static class EchoBasic {
-        @WebSocketMessage
-        public void echoTextMessage(Session session, String msg) {
-            try {
-                session.getRemote().sendString(msg);
-            } catch (IOException e) {
-                try {
-                    session.close();
-                } catch (IOException e1) {
-                    // Ignore
-                }
-            }
-        }
-
-
-        @WebSocketMessage
-        public void echoBinaryMessage(Session session, ByteBuffer msg) {
-            try {
-                session.getRemote().sendBytes(msg);
-            } catch (IOException e) {
-                try {
-                    session.close();
-                } catch (IOException e1) {
-                    // Ignore
-                }
-            }
-        }
-    }
-
-
-    public static class EchoAsync {
-
-        @WebSocketMessage
-        public void echoTextMessage(Session session, String msg, boolean last) {
-            try {
-                session.getRemote().sendPartialString(msg, last);
-            } catch (IOException e) {
-                try {
-                    session.close();
-                } catch (IOException e1) {
-                    // Ignore
-                }
-            }
-        }
-
-
-        @WebSocketMessage
-        public void echoBinaryMessage(Session session, ByteBuffer msg,
-                boolean last) {
-            try {
-                session.getRemote().sendPartialBytes(msg, last);
-            } catch (IOException e) {
-                try {
-                    session.close();
-                } catch (IOException e1) {
-                    // Ignore
-                }
-            }
-        }
-    }
-
-
     public static class BlockingConfig implements ServletContextListener {
 
         public static final String PATH = "/block";

Added: tomcat/trunk/test/org/apache/tomcat/websocket/TesterEcho.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TesterEcho.java?rev=1444422&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TesterEcho.java (added)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TesterEcho.java Sat Feb  9 20:22:07 2013
@@ -0,0 +1,109 @@
+/*
+ * 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 java.nio.ByteBuffer;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.websocket.Session;
+import javax.websocket.WebSocketMessage;
+
+import org.apache.tomcat.websocket.server.ServerContainerImpl;
+
+public class TesterEcho {
+
+    public static class Config implements ServletContextListener {
+
+        public static final String PATH_ASYNC = "/echoAsync";
+        public static final String PATH_BASIC = "/echoBasic";
+
+        @Override
+        public void contextInitialized(ServletContextEvent sce) {
+            ServerContainerImpl sc = ServerContainerImpl.getServerContainer();
+            sc.publishServer(Async.class, sce.getServletContext(), PATH_ASYNC);
+            sc.publishServer(
+                    Basic.class, sce.getServletContext(), PATH_BASIC);
+        }
+
+        @Override
+        public void contextDestroyed(ServletContextEvent sce) {
+            // NO-OP
+        }
+    }
+
+    public static class Async {
+
+        @WebSocketMessage
+        public void echoTextMessage(Session session, String msg, boolean last) {
+            try {
+                session.getRemote().sendPartialString(msg, last);
+            } catch (IOException e) {
+                try {
+                    session.close();
+                } catch (IOException e1) {
+                    // Ignore
+                }
+            }
+        }
+
+
+        @WebSocketMessage
+        public void echoBinaryMessage(Session session, ByteBuffer msg,
+                boolean last) {
+            try {
+                session.getRemote().sendPartialBytes(msg, last);
+            } catch (IOException e) {
+                try {
+                    session.close();
+                } catch (IOException e1) {
+                    // Ignore
+                }
+            }
+        }
+    }
+
+    public static class Basic {
+        @WebSocketMessage
+        public void echoTextMessage(Session session, String msg) {
+            try {
+                session.getRemote().sendString(msg);
+            } catch (IOException e) {
+                try {
+                    session.close();
+                } catch (IOException e1) {
+                    // Ignore
+                }
+            }
+        }
+
+
+        @WebSocketMessage
+        public void echoBinaryMessage(Session session, ByteBuffer msg) {
+            try {
+                session.getRemote().sendBytes(msg);
+            } catch (IOException e) {
+                try {
+                    session.close();
+                } catch (IOException e1) {
+                    // Ignore
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

Propchange: tomcat/trunk/test/org/apache/tomcat/websocket/TesterEcho.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org