tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1459972 - in /tomcat/trunk/java/org/apache/tomcat/websocket: Util.java WsRemoteEndpointImplBase.java pojo/PojoMethodMapping.java
Date Fri, 22 Mar 2013 20:31:29 GMT
Author: markt
Date: Fri Mar 22 20:31:29 2013
New Revision: 1459972

URL: http://svn.apache.org/r1459972
Log:
Automatically encode primitives and their object equivalents.

Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/Util.java
    tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
    tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/Util.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/Util.java?rev=1459972&r1=1459971&r2=1459972&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/Util.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/Util.java Fri Mar 22 20:31:29 2013
@@ -217,4 +217,21 @@ public class Util {
             return null;
         }
     }
+
+
+    public static boolean isPrimitive(Class<?> clazz) {
+        if (clazz.isPrimitive()) {
+            return true;
+        } else if(clazz.equals(Boolean.class) ||
+                clazz.equals(Byte.class) ||
+                clazz.equals(Character.class) ||
+                clazz.equals(Double.class) ||
+                clazz.equals(Float.class) ||
+                clazz.equals(Integer.class) ||
+                clazz.equals(Long.class) ||
+                clazz.equals(Short.class)) {
+            return true;
+        }
+        return false;
+    }
 }

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java?rev=1459972&r1=1459971&r2=1459972&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java Fri Mar 22
20:31:29 2013
@@ -419,6 +419,12 @@ public abstract class WsRemoteEndpointIm
     @SuppressWarnings({"unchecked", "rawtypes"})
     public void sendObjectByCompletion(Object obj, SendHandler completion) {
 
+        if (Util.isPrimitive(obj.getClass())) {
+            String msg = obj.toString();
+            sendStringByCompletion(msg, completion);
+            return;
+        }
+
         Encoder encoder = findEncoder(obj);
 
         try {

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java?rev=1459972&r1=1459971&r2=1459972&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java Fri Mar 22 20:31:29
2013
@@ -357,7 +357,7 @@ public class PojoMethodMapping {
                                 "pojoMethodMapping.duplicateMessageParam",
                                 m.getName(), m.getDeclaringClass().getName()));
                     }
-                } else if (isPrimitive(types[i])) {
+                } else if (Util.isPrimitive(types[i])) {
                     if (indexPrimitive == -1) {
                         indexPrimitive = i;
                     } else {
@@ -497,23 +497,6 @@ public class PojoMethodMapping {
         }
 
 
-        private boolean isPrimitive(Class<?> clazz) {
-            if (clazz.isPrimitive()) {
-                return true;
-            } else if(clazz.equals(Boolean.class) ||
-                    clazz.equals(Byte.class) ||
-                    clazz.equals(Character.class) ||
-                    clazz.equals(Double.class) ||
-                    clazz.equals(Float.class) ||
-                    clazz.equals(Integer.class) ||
-                    clazz.equals(Long.class) ||
-                    clazz.equals(Short.class)) {
-                return true;
-            }
-            return false;
-        }
-
-
         public MessageHandler getMessageHandler(Object pojo,
                 Map<String,String> pathParameters, Session session,
                 EndpointConfig config) {



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


Mime
View raw message