tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1452873 - in /tomcat/trunk: java/javax/websocket/ java/javax/websocket/server/ java/org/apache/tomcat/websocket/ java/org/apache/tomcat/websocket/server/ test/org/apache/tomcat/websocket/
Date Tue, 05 Mar 2013 16:12:30 GMT
Author: markt
Date: Tue Mar  5 16:12:30 2013
New Revision: 1452873

URL: http://svn.apache.org/r1452873
Log:
Refactoring towards v014 API (not yet complete)

Modified:
    tomcat/trunk/java/javax/websocket/ClientEndpointConfig.java
    tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfig.java
    tomcat/trunk/java/javax/websocket/EndpointConfig.java
    tomcat/trunk/java/javax/websocket/server/DefaultServerEndpointConfiguration.java
    tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurationBuilder.java
    tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties
    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/WsSession.java
    tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java
    tomcat/trunk/test/org/apache/tomcat/websocket/TestUtil.java

Modified: tomcat/trunk/java/javax/websocket/ClientEndpointConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/ClientEndpointConfig.java?rev=1452873&r1=1452872&r2=1452873&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/ClientEndpointConfig.java (original)
+++ tomcat/trunk/java/javax/websocket/ClientEndpointConfig.java Tue Mar  5 16:12:30 2013
@@ -46,8 +46,10 @@ public interface ClientEndpointConfig ex
         private Configurator configurator = DEFAULT_CONFIGURATOR;
         private List<String> preferredSubprotocols = Collections.EMPTY_LIST;
         private List<Extension> extensions = Collections.EMPTY_LIST;
-        private List<Encoder> encoders = Collections.EMPTY_LIST;
-        private List<Decoder> decoders = Collections.EMPTY_LIST;
+        private List<Class<? extends Encoder>> encoders =
+                Collections.EMPTY_LIST;
+        private List<Class<? extends Decoder>> decoders =
+                Collections.EMPTY_LIST;
 
 
         public ClientEndpointConfig build() {
@@ -90,7 +92,7 @@ public interface ClientEndpointConfig ex
         }
 
 
-        public Builder encoders(List<Encoder> encoders) {
+        public Builder encoders(List<Class<? extends Encoder>> encoders) {
             if (encoders == null || encoders.size() == 0) {
                 this.encoders = Collections.EMPTY_LIST;
             } else {
@@ -100,7 +102,7 @@ public interface ClientEndpointConfig ex
         }
 
 
-        public Builder decoders(List<Decoder> decoders) {
+        public Builder decoders(List<Class<? extends Decoder>> decoders) {
             if (decoders == null || decoders.size() == 0) {
                 this.decoders = Collections.EMPTY_LIST;
             } else {

Modified: tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfig.java?rev=1452873&r1=1452872&r2=1452873&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfig.java (original)
+++ tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfig.java Tue Mar  5 16:12:30
2013
@@ -24,15 +24,17 @@ final class DefaultClientEndpointConfig 
 
     private final List<String> preferredSubprotocols;
     private final List<Extension> extensions;
-    private final List<Encoder> encoders;
-    private final List<Decoder> decoders;
+    private final List<Class<? extends Encoder>> encoders;
+    private final List<Class<? extends Decoder>> decoders;
     private final Map<String,Object> userProperties = new HashMap<>();
     private final Configurator configurator;
 
 
     DefaultClientEndpointConfig(List<String> preferredSubprotocols,
-            List<Extension> extensions, List<Encoder> encoders,
-            List<Decoder> decoders, Configurator configurator) {
+            List<Extension> extensions,
+            List<Class<? extends Encoder>> encoders,
+            List<Class<? extends Decoder>> decoders,
+            Configurator configurator) {
         this.preferredSubprotocols = preferredSubprotocols;
         this.extensions = extensions;
         this.decoders = decoders;
@@ -54,13 +56,13 @@ final class DefaultClientEndpointConfig 
 
 
     @Override
-    public List<Encoder> getEncoders() {
+    public List<Class<? extends Encoder>> getEncoders() {
         return encoders;
     }
 
 
     @Override
-    public List<Decoder> getDecoders() {
+    public List<Class<? extends Decoder>> getDecoders() {
         return decoders;
     }
 

Modified: tomcat/trunk/java/javax/websocket/EndpointConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/EndpointConfig.java?rev=1452873&r1=1452872&r2=1452873&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/EndpointConfig.java (original)
+++ tomcat/trunk/java/javax/websocket/EndpointConfig.java Tue Mar  5 16:12:30 2013
@@ -21,9 +21,9 @@ import java.util.Map;
 
 public interface EndpointConfig {
 
-    List<Encoder> getEncoders();
+    List<Class<? extends Encoder>> getEncoders();
 
-    List<Decoder> getDecoders();
+    List<Class<? extends Decoder>> getDecoders();
 
     Map<String,Object> getUserProperties();
 }

Modified: tomcat/trunk/java/javax/websocket/server/DefaultServerEndpointConfiguration.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/server/DefaultServerEndpointConfiguration.java?rev=1452873&r1=1452872&r2=1452873&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/server/DefaultServerEndpointConfiguration.java (original)
+++ tomcat/trunk/java/javax/websocket/server/DefaultServerEndpointConfiguration.java Tue Mar
 5 16:12:30 2013
@@ -34,15 +34,16 @@ public class DefaultServerEndpointConfig
     private final String path;
     private final List<String> subprotocols;
     private final List<Extension> extensions;
-    private final List<Encoder> encoders;
-    private final List<Decoder> decoders;
+    private final List<Class<? extends Encoder>> encoders;
+    private final List<Class<? extends Decoder>> decoders;
     private final ServerEndpointConfigurator serverEndpointConfigurator;
     private final Map<String,Object> userProperties = new HashMap<>();
 
     DefaultServerEndpointConfiguration(
             Class<?> endpointClass, String path,
             List<String> subprotocols, List<Extension> extensions,
-            List<Encoder> encoders, List<Decoder> decoders,
+            List<Class<? extends Encoder>> encoders,
+            List<Class<? extends Decoder>> decoders,
             ServerEndpointConfigurator serverEndpointConfigurator) {
         this.endpointClass = endpointClass;
         this.path = path;
@@ -59,12 +60,12 @@ public class DefaultServerEndpointConfig
     }
 
     @Override
-    public List<Encoder> getEncoders() {
+    public List<Class<? extends Encoder>> getEncoders() {
         return this.encoders;
     }
 
     @Override
-    public List<Decoder> getDecoders() {
+    public List<Class<? extends Decoder>> getDecoders() {
         return this.decoders;
     }
 

Modified: tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurationBuilder.java?rev=1452873&r1=1452872&r2=1452873&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurationBuilder.java (original)
+++ tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurationBuilder.java Tue Mar
 5 16:12:30 2013
@@ -33,8 +33,8 @@ public class ServerEndpointConfiguration
 
     private final Class<?> endpointClass;
     private final String path;
-    private List<Encoder> encoders = Collections.EMPTY_LIST;
-    private List<Decoder> decoders = Collections.EMPTY_LIST;
+    private List<Class<? extends Encoder>> encoders = Collections.EMPTY_LIST;
+    private List<Class<? extends Decoder>> decoders = Collections.EMPTY_LIST;
     private List<String> subprotocols = Collections.EMPTY_LIST;
     private List<Extension> extensions = Collections.EMPTY_LIST;
     private ServerEndpointConfigurator configurator =
@@ -53,7 +53,8 @@ public class ServerEndpointConfiguration
     }
 
 
-    public ServerEndpointConfigurationBuilder encoders(List<Encoder> encoders) {
+    public ServerEndpointConfigurationBuilder encoders(
+            List<Class<? extends Encoder>> encoders) {
         if (encoders == null || encoders.size() == 0) {
             this.encoders = Collections.EMPTY_LIST;
         } else {
@@ -63,7 +64,8 @@ public class ServerEndpointConfiguration
     }
 
 
-    public ServerEndpointConfigurationBuilder decoders(List<Decoder> decoders) {
+    public ServerEndpointConfigurationBuilder decoders(
+            List<Class<? extends Decoder>> decoders) {
         if (decoders == null || decoders.size() == 0) {
             this.decoders = Collections.EMPTY_LIST;
         } else {

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties?rev=1452873&r1=1452872&r2=1452873&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties Tue Mar  5 16:12:30
2013
@@ -36,6 +36,7 @@ wsRemoteEndpoint.changeType=When sending
 wsRemoteEndpoint.concurrentMessageSend=Messages may not be sent concurrently even when using
the asynchronous send messages. The client must wait for the previous message to complete
before sending the next.
 wsRemoteEndpoint.flushOnCloseFailed=Flushing batched messages before closing the session
failed
 wsRemoteEndpoint.inProgress=Message will not be sent because the WebSocket session is currently
sending another message
+wsRemoteEndpoint.invalidEncoder=The specified encoder of type [{0}] could not be instantiated
 wsRemoteEndpoint.noEncoder=No encoder specified for object of class [{0}]
 
 # Note the following message is used as a close reason in a WebSocket control

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=1452873&r1=1452872&r2=1452873&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/Util.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/Util.java Tue Mar  5 16:12:30 2013
@@ -142,9 +142,8 @@ class Util {
     }
 
 
-    static Class<?> getEncoderType(Encoder encoder) {
-        return (Class<?>) Util.getGenericType(Encoder.class,
-                encoder.getClass());
+    static Class<?> getEncoderType(Class<? extends Encoder> encoder) {
+        return (Class<?>) Util.getGenericType(Encoder.class, encoder);
     }
 
 

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=1452873&r1=1452872&r2=1452873&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java Tue Mar  5
16:12:30 2013
@@ -35,6 +35,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import javax.websocket.DeploymentException;
 import javax.websocket.EncodeException;
 import javax.websocket.Encoder;
 import javax.websocket.RemoteEndpoint;
@@ -453,11 +454,20 @@ public abstract class WsRemoteEndpointIm
     }
 
 
-    protected void setEncoders(List<Encoder> encoders) {
+    protected void setEncoders(List<Class<? extends Encoder>> encoders)
+            throws DeploymentException {
         encoderEntries.clear();
-        for (Encoder encoder : encoders) {
-            EncoderEntry entry =
-                    new EncoderEntry(Util.getEncoderType(encoder), encoder);
+        for (Class<? extends Encoder> encoderClazz : encoders) {
+            Encoder instance;
+            try {
+                instance = encoderClazz.newInstance();
+            } catch (InstantiationException | IllegalAccessException e) {
+                throw new DeploymentException(
+                        sm.getString("wsRemoteEndpoint.invalidEncoder",
+                                encoderClazz.getName()), e);
+            }
+            EncoderEntry entry = new EncoderEntry(
+                    Util.getEncoderType(encoderClazz), instance);
             encoderEntries.add(entry);
         }
     }

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java?rev=1452873&r1=1452872&r2=1452873&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Tue Mar  5 16:12:30 2013
@@ -31,6 +31,7 @@ import java.util.concurrent.ConcurrentHa
 
 import javax.websocket.CloseReason;
 import javax.websocket.CloseReason.CloseCodes;
+import javax.websocket.DeploymentException;
 import javax.websocket.Encoder;
 import javax.websocket.Endpoint;
 import javax.websocket.Extension;
@@ -85,13 +86,15 @@ public class WsSession implements Sessio
      *
      * @param localEndpoint
      * @param wsRemoteEndpoint
+     * @throws DeploymentException
      */
     public WsSession(Endpoint localEndpoint,
             WsRemoteEndpointImplBase wsRemoteEndpoint,
             WsWebSocketContainer wsWebSocketContainer,
             WsRequest request, String subProtocol,
             Map<String,String> pathParameters,
-            boolean secure, List<Encoder> encoders) {
+            boolean secure, List<Class<? extends Encoder>> encoders)
+                    throws DeploymentException {
         this.localEndpoint = localEndpoint;
         this.wsRemoteEndpoint = wsRemoteEndpoint;
         this.wsRemoteEndpoint.setSession(this);

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java?rev=1452873&r1=1452872&r2=1452873&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java Tue Mar  5
16:12:30 2013
@@ -28,6 +28,7 @@ import javax.servlet.http.HttpUpgradeHan
 import javax.servlet.http.WebConnection;
 import javax.websocket.CloseReason;
 import javax.websocket.CloseReason.CloseCodes;
+import javax.websocket.DeploymentException;
 import javax.websocket.Endpoint;
 import javax.websocket.EndpointConfig;
 
@@ -105,6 +106,8 @@ public class WsProtocolHandler implement
                     new WsWriteListener(this, wsRemoteEndpointServer));
             ep.onOpen(wsSession, endpointConfig);
             webSocketContainer.registerSession(ep.getClass(), wsSession);
+        } catch (DeploymentException e) {
+            throw new IllegalArgumentException(e);
         } finally {
             t.setContextClassLoader(cl);
         }

Modified: tomcat/trunk/test/org/apache/tomcat/websocket/TestUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TestUtil.java?rev=1452873&r1=1452872&r2=1452873&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TestUtil.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TestUtil.java Tue Mar  5 16:12:30 2013
@@ -63,35 +63,35 @@ public class TestUtil {
     @Test
     public void testGetEncoderTypeSimple() {
         Assert.assertEquals(
-                String.class, Util.getEncoderType(new SimpleEncoder()));
+                String.class, Util.getEncoderType(SimpleEncoder.class));
     }
 
 
     @Test
     public void testGetEncoderTypeSubclass() {
         Assert.assertEquals(String.class,
-                Util.getEncoderType(new SubSimpleEncoder()));
+                Util.getEncoderType(SubSimpleEncoder.class));
     }
 
 
     @Test
     public void testGetEncoderTypeGenericSubclass() {
         Assert.assertEquals(String.class,
-                Util.getEncoderType(new GenericSubEncoder()));
+                Util.getEncoderType(GenericSubEncoder.class));
     }
 
 
     @Test
     public void testGetEncoderTypeGenericMultipleSubclass() {
         Assert.assertEquals(String.class,
-                Util.getEncoderType(new GenericMultipleSubSubEncoder()));
+                Util.getEncoderType(GenericMultipleSubSubEncoder.class));
     }
 
 
     @Test
     public void testGetEncoderTypeGenericMultipleSubclassSwap() {
         Assert.assertEquals(String.class,
-                Util.getEncoderType(new GenericMultipleSubSubSwapEncoder()));
+                Util.getEncoderType(GenericMultipleSubSubSwapEncoder.class));
     }
 
 



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


Mime
View raw message