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 2012/11/29 14:54:25 UTC

svn commit: r1415160 - in /tomcat/trunk: java/org/apache/tomcat/websocket/WsEndpointPojo.java webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java webapps/examples/websocket/echo.html

Author: markt
Date: Thu Nov 29 13:54:24 2012
New Revision: 1415160

URL: http://svn.apache.org/viewvc?rev=1415160&view=rev
Log:
WebSocket 1.0 implementation part4 of many
Start to think about POJO handling. This is roughly what needs to be done but is certainly incomplete and probably in the wrong place.

Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/WsEndpointPojo.java
    tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java
    tomcat/trunk/webapps/examples/websocket/echo.html

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsEndpointPojo.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsEndpointPojo.java?rev=1415160&r1=1415159&r2=1415160&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsEndpointPojo.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsEndpointPojo.java Thu Nov 29 13:54:24 2012
@@ -24,6 +24,9 @@ import javax.websocket.DefaultServerConf
 import javax.websocket.Endpoint;
 import javax.websocket.EndpointConfiguration;
 import javax.websocket.Session;
+import javax.websocket.WebSocketClose;
+import javax.websocket.WebSocketError;
+import javax.websocket.WebSocketOpen;
 
 public class WsEndpointPojo extends Endpoint {
 
@@ -36,12 +39,35 @@ public class WsEndpointPojo extends Endp
     public WsEndpointPojo(Class<?> clazzPojo, String path)
             throws InstantiationException, IllegalAccessException {
         this.pojo = clazzPojo.newInstance();
-        this.config = new DefaultServerConfiguration(path);
+        this.config = new DefaultServerConfiguration(path) {
 
-        // TODO - Find these
-        this.onOpen = null;
-        this.onClose = null;
-        this.onError = null;
+            @Override
+            public boolean checkOrigin(String originHeaderValue) {
+                return true;
+            }
+
+        };
+
+        // TODO - Don't want to have to do this on every connection
+        Method open = null;
+        Method close = null;
+        Method error = null;
+        Method[] methods = clazzPojo.getMethods();
+        for (int i = 0; i < methods.length; i++) {
+            if (open == null &&
+                    methods[i].getAnnotation(WebSocketOpen.class) != null) {
+                open = methods[i];
+            } else if (close == null &&
+                    methods[i].getAnnotation(WebSocketClose.class) != null) {
+                close = methods[i];
+            } else if (error == null &&
+                    methods[i].getAnnotation(WebSocketError.class) != null) {
+                error = methods[i];
+            }
+        }
+        this.onOpen = open;
+        this.onClose = close;
+        this.onError = error;
     }
 
     @Override
@@ -52,6 +78,7 @@ public class WsEndpointPojo extends Endp
     @Override
     public void onOpen(Session session) {
         if (onOpen != null) {
+
             try {
                 onOpen.invoke(pojo, session);
             } catch (IllegalAccessException | IllegalArgumentException

Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java?rev=1415160&r1=1415159&r2=1415160&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java Thu Nov 29 13:54:24 2012
@@ -17,8 +17,13 @@
 package websocket.echo;
 
 import javax.websocket.WebSocketEndpoint;
+import javax.websocket.WebSocketOpen;
 
 @WebSocketEndpoint("/websocket/echoAnnotation")
 public class EchoAnnotation {
 
+    @WebSocketOpen
+    public void printOpen() {
+        System.out.println("EchoAnnotation.printOpen()");
+    }
 }

Modified: tomcat/trunk/webapps/examples/websocket/echo.html
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/websocket/echo.html?rev=1415160&r1=1415159&r2=1415160&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/websocket/echo.html (original)
+++ tomcat/trunk/webapps/examples/websocket/echo.html Thu Nov 29 13:54:24 2012
@@ -137,9 +137,12 @@
             <!-- echo example using messages on the server side -->
             <input id="radio2" type="radio" name="group1" value="/examples/websocket/echoMessage"
                    onclick="updateTarget(this.value);"> <label for="radio2">messages</label>
-            <!-- echo example using new programmatic API on the  server side -->
+            <!-- echo example using new programmatic API on the server side -->
             <input id="radio3" type="radio" name="group1" value="/examples/websocket/echoProgrammatic"
                    onclick="updateTarget(this.value);"> <label for="radio2">new programmatic</label>
+            <!-- echo example using new annotation API on the server side -->
+            <input id="radio3" type="radio" name="group1" value="/examples/websocket/echoAnnotation"
+                   onclick="updateTarget(this.value);"> <label for="radio2">new annotation</label>
         </div>
         <div>
             <input id="target" type="text" size="40" style="width: 350px"/>



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