Author: markt
Date: Tue Mar  5 15:50:03 2013
New Revision: 1452863

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

Removed:
    tomcat/trunk/java/javax/websocket/ClientEndpointConfigurationBuilder.java
    tomcat/trunk/java/javax/websocket/ClientEndpointConfigurator.java
Modified:
    tomcat/trunk/java/javax/websocket/ClientEndpoint.java
    tomcat/trunk/java/javax/websocket/ClientEndpointConfig.java
    tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfig.java
    tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
    tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java
    tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java

Modified: tomcat/trunk/java/javax/websocket/ClientEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/ClientEndpoint.java?rev=1452863&r1=1452862&r2=1452863&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/ClientEndpoint.java (original)
+++ tomcat/trunk/java/javax/websocket/ClientEndpoint.java Tue Mar  5 15:50:03 
2013
@@ -21,12 +21,14 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+import javax.websocket.ClientEndpointConfig.Configurator;
+
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.TYPE)
 public @interface ClientEndpoint {
     String[] subprotocols();
     Class<? extends Decoder>[] decoders();
     Class<? extends Encoder>[] encoders();
-    public Class<? extends ClientEndpointConfigurator> configurator()
-            default ClientEndpointConfigurator.class;
+    public Class<? extends Configurator> configurator()
+            default Configurator.class;
 }

Modified: tomcat/trunk/java/javax/websocket/ClientEndpointConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/ClientEndpointConfig.java?rev=1452863&r1=1452862&r2=1452863&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/ClientEndpointConfig.java (original)
+++ tomcat/trunk/java/javax/websocket/ClientEndpointConfig.java Tue Mar  5 
15:50:03 2013
@@ -16,7 +16,9 @@
  */
 package javax.websocket;
 
+import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 public interface ClientEndpointConfig extends EndpointConfig {
 
@@ -24,5 +26,111 @@ public interface ClientEndpointConfig ex
 
     List<Extension> getExtensions();
 
-    public ClientEndpointConfigurator getClientEndpointConfigurator();
+    public Configurator getConfigurator();
+
+    public final class Builder {
+
+        private static final Configurator DEFAULT_CONFIGURATOR =
+                new Configurator() {};
+
+
+        public static Builder create() {
+            return new Builder();
+        }
+
+
+        private Builder() {
+            // Hide default constructor
+        }
+
+        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;
+
+
+        public ClientEndpointConfig build() {
+            return new DefaultClientEndpointConfig(preferredSubprotocols,
+                    extensions, encoders, decoders, configurator);
+        }
+
+
+        public Builder configurator(Configurator configurator) {
+            if (configurator == null) {
+                this.configurator = DEFAULT_CONFIGURATOR;
+            } else {
+                this.configurator = configurator;
+            }
+            return this;
+        }
+
+
+        public Builder preferredSubprotocols(
+                List<String> preferredSubprotocols) {
+            if (preferredSubprotocols == null ||
+                    preferredSubprotocols.size() == 0) {
+                this.preferredSubprotocols = Collections.EMPTY_LIST;
+            } else {
+                this.preferredSubprotocols =
+                        Collections.unmodifiableList(preferredSubprotocols);
+            }
+            return this;
+        }
+
+
+        public Builder extensions(
+                List<Extension> extensions) {
+            if (extensions == null || extensions.size() == 0) {
+                this.extensions = Collections.EMPTY_LIST;
+            } else {
+                this.extensions = Collections.unmodifiableList(extensions);
+            }
+            return this;
+        }
+
+
+        public Builder encoders(List<Encoder> encoders) {
+            if (encoders == null || encoders.size() == 0) {
+                this.encoders = Collections.EMPTY_LIST;
+            } else {
+                this.encoders = Collections.unmodifiableList(encoders);
+            }
+            return this;
+        }
+
+
+        public Builder decoders(List<Decoder> decoders) {
+            if (decoders == null || decoders.size() == 0) {
+                this.decoders = Collections.EMPTY_LIST;
+            } else {
+                this.decoders = Collections.unmodifiableList(decoders);
+            }
+            return this;
+        }
+    }
+
+
+    public abstract class Configurator {
+
+        /**
+         * Provides the client with a mechanism to inspect and/or modify the 
headers
+         * that are sent to the server to start the WebSocket handshake.
+         *
+         * @param headers   The HTTP headers
+         */
+        public void beforeRequest(Map<String, List<String>> headers) {
+            // NO-OP
+        }
+
+        /**
+         * Provides the client with a mechanism to inspect the handshake 
response
+         * that is returned from the server.
+         *
+         * @param handshakeResponse The response
+         */
+        public void afterResponse(HandshakeResponse handshakeResponse) {
+            // NO-OP
+        }
+    }
 }

Modified: tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfig.java?rev=1452863&r1=1452862&r2=1452863&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfig.java 
(original)
+++ tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfig.java Tue Mar  
5 15:50:03 2013
@@ -27,12 +27,12 @@ final class DefaultClientEndpointConfig 
     private final List<Encoder> encoders;
     private final List<Decoder> decoders;
     private final Map<String,Object> userProperties = new HashMap<>();
-    private final ClientEndpointConfigurator configurator;
+    private final Configurator configurator;
 
 
     DefaultClientEndpointConfig(List<String> preferredSubprotocols,
             List<Extension> extensions, List<Encoder> encoders,
-            List<Decoder> decoders, ClientEndpointConfigurator configurator) {
+            List<Decoder> decoders, Configurator configurator) {
         this.preferredSubprotocols = preferredSubprotocols;
         this.extensions = extensions;
         this.decoders = decoders;
@@ -72,7 +72,7 @@ final class DefaultClientEndpointConfig 
 
 
     @Override
-    public ClientEndpointConfigurator getClientEndpointConfigurator() {
+    public Configurator getConfigurator() {
         return configurator;
     }
 }

Modified: 
tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java?rev=1452863&r1=1452862&r2=1452863&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java Tue 
Mar  5 15:50:03 2013
@@ -95,7 +95,7 @@ public class WsWebSocketContainer
         }
         int port = path.getPort();
         Map<String,List<String>> reqHeaders = createRequestHeaders(host, port);
-        clientEndpointConfiguration.getClientEndpointConfigurator().
+        clientEndpointConfiguration.getConfigurator().
                 beforeRequest(reqHeaders);
 
         ByteBuffer request = createRequest(path.getRawPath(), reqHeaders);
@@ -142,7 +142,7 @@ public class WsWebSocketContainer
 
             HandshakeResponse handshakeResponse =
                     processResponse(response, channel);
-            clientEndpointConfiguration.getClientEndpointConfigurator().
+            clientEndpointConfiguration.getConfigurator().
                     afterResponse(handshakeResponse);
 
             // Sub-protocol

Modified: 
tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java?rev=1452863&r1=1452862&r2=1452863&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java 
(original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java Tue 
Mar  5 15:50:03 2013
@@ -22,7 +22,7 @@ import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import javax.websocket.ClientEndpointConfigurationBuilder;
+import javax.websocket.ClientEndpointConfig.Builder;
 import javax.websocket.ContainerProvider;
 import javax.websocket.Session;
 import javax.websocket.WebSocketContainer;
@@ -65,7 +65,7 @@ public class TestWsRemoteEndpoint extend
         tomcat.start();
 
         Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
-                ClientEndpointConfigurationBuilder.create().build(),
+                Builder.create().build(),
                 new URI("http://localhost:"; + getPort() +
                         TesterEchoServer.Config.PATH_ASYNC));
 

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=1452863&r1=1452862&r2=1452863&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java 
(original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java 
Tue Mar  5 15:50:03 2013
@@ -27,7 +27,7 @@ import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
 import javax.servlet.ServletContextEvent;
-import javax.websocket.ClientEndpointConfigurationBuilder;
+import javax.websocket.ClientEndpointConfig.Builder;
 import javax.websocket.ContainerProvider;
 import javax.websocket.DeploymentException;
 import javax.websocket.Endpoint;
@@ -84,7 +84,7 @@ public class TestWsWebSocketContainer ex
         WebSocketContainer wsContainer =
                 ContainerProvider.getWebSocketContainer();
         Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
-                ClientEndpointConfigurationBuilder.create().build(),
+                Builder.create().build(),
                 new URI("http://localhost:"; + getPort() +
                         TesterEchoServer.Config.PATH_ASYNC));
         CountDownLatch latch = new CountDownLatch(1);
@@ -115,7 +115,7 @@ public class TestWsWebSocketContainer ex
         WebSocketContainer wsContainer =
                 ContainerProvider.getWebSocketContainer();
         wsContainer.connectToServer(TesterEndpoint.class,
-                ClientEndpointConfigurationBuilder.create().build(),
+                Builder.create().build(),
                 new URI("ftp://localhost:"; + getPort() +
                         TesterEchoServer.Config.PATH_ASYNC));
     }
@@ -134,7 +134,7 @@ public class TestWsWebSocketContainer ex
         WebSocketContainer wsContainer =
                 ContainerProvider.getWebSocketContainer();
         wsContainer.connectToServer(TesterEndpoint.class,
-                ClientEndpointConfigurationBuilder.create().build(),
+                Builder.create().build(),
                 new URI("http://"; + TesterEchoServer.Config.PATH_ASYNC));
     }
 
@@ -222,7 +222,7 @@ public class TestWsWebSocketContainer ex
         tomcat.start();
 
         Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
-                ClientEndpointConfigurationBuilder.create().build(),
+                Builder.create().build(),
                         new URI("http://localhost:"; + getPort() +
                                 TesterEchoServer.Config.PATH_BASIC));
         BasicHandler<?> handler;
@@ -293,7 +293,7 @@ public class TestWsWebSocketContainer ex
         tomcat.start();
 
         Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
-                ClientEndpointConfigurationBuilder.create().build(),
+                Builder.create().build(),
                 new URI("http://localhost:"; + getPort() + 
BlockingConfig.PATH));
 
         if (!setTimeoutOnContainer) {
@@ -374,7 +374,7 @@ public class TestWsWebSocketContainer ex
         tomcat.start();
 
         Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
-                ClientEndpointConfigurationBuilder.create().build(),
+                Builder.create().build(),
                 new URI("http://localhost:"; + getPort() +
                         ConstantTxConfig.PATH));
 
@@ -668,7 +668,7 @@ public class TestWsWebSocketContainer ex
     private Session connectToEchoServerBasic(WebSocketContainer wsContainer,
             Class<? extends Endpoint> clazz) throws Exception {
         return wsContainer.connectToServer(clazz,
-                ClientEndpointConfigurationBuilder.create().build(),
+                Builder.create().build(),
                 new URI("http://localhost:"; + getPort() +
                         TesterEchoServer.Config.PATH_BASIC));
     }



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

Reply via email to