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/27 02:32:27 UTC

svn commit: r1450570 - in /tomcat/trunk: java/javax/websocket/ java/javax/websocket/server/ java/org/apache/tomcat/websocket/ java/org/apache/tomcat/websocket/pojo/ java/org/apache/tomcat/websocket/server/ res/META-INF/tomcat-websocket.jar/services/ te...

Author: markt
Date: Wed Feb 27 01:32:26 2013
New Revision: 1450570

URL: http://svn.apache.org/r1450570
Log:
Complete update of WebSocket to latest draft of spec

Added:
    tomcat/trunk/java/javax/websocket/ClientEndpointConfigurationBuilder.java
    tomcat/trunk/java/javax/websocket/ClientEndpointConfigurator.java
    tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfiguration.java
      - copied, changed from r1449658, tomcat/trunk/java/javax/websocket/DefaultClientConfiguration.java
    tomcat/trunk/java/javax/websocket/server/DefaultServerEndpointConfiguration.java
      - copied, changed from r1449658, tomcat/trunk/java/javax/websocket/server/DefaultServerConfiguration.java
    tomcat/trunk/java/javax/websocket/server/ServerEndpoint.java
      - copied, changed from r1449658, tomcat/trunk/java/javax/websocket/server/WebSocketEndpoint.java
    tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurationBuilder.java
    tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurator.java
    tomcat/trunk/java/org/apache/tomcat/websocket/server/DefaultServerEndpointConfigurator.java
    tomcat/trunk/res/META-INF/tomcat-websocket.jar/services/javax.websocket.server.ServerEndpointConfigurator
Removed:
    tomcat/trunk/java/javax/websocket/DefaultClientConfiguration.java
    tomcat/trunk/java/javax/websocket/server/DefaultServerConfiguration.java
    tomcat/trunk/java/javax/websocket/server/WebSocketEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoEndpointConfiguration.java
Modified:
    tomcat/trunk/java/javax/websocket/ClientEndpoint.java
    tomcat/trunk/java/javax/websocket/ClientEndpointConfiguration.java
    tomcat/trunk/java/javax/websocket/EndpointConfiguration.java
    tomcat/trunk/java/javax/websocket/server/ServerApplicationConfiguration.java
    tomcat/trunk/java/javax/websocket/server/ServerEndpointConfiguration.java
    tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
    tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java
    tomcat/trunk/java/org/apache/tomcat/websocket/server/ServerContainerImpl.java
    tomcat/trunk/java/org/apache/tomcat/websocket/server/WsSci.java
    tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServlet.java
    tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java
    tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
    tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java
    tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java
    tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/WsConfigListener.java
    tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java

Modified: tomcat/trunk/java/javax/websocket/ClientEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/ClientEndpoint.java?rev=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/ClientEndpoint.java (original)
+++ tomcat/trunk/java/javax/websocket/ClientEndpoint.java Wed Feb 27 01:32:26 2013
@@ -27,4 +27,6 @@ public @interface ClientEndpoint {
     String[] subprotocols();
     Class<? extends Decoder>[] decoders();
     Class<? extends Encoder>[] encoders();
+    public Class<? extends ClientEndpointConfigurator> configurator()
+            default ClientEndpointConfigurator.class;
 }

Modified: tomcat/trunk/java/javax/websocket/ClientEndpointConfiguration.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/ClientEndpointConfiguration.java?rev=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/ClientEndpointConfiguration.java (original)
+++ tomcat/trunk/java/javax/websocket/ClientEndpointConfiguration.java Wed Feb 27 01:32:26 2013
@@ -17,7 +17,6 @@
 package javax.websocket;
 
 import java.util.List;
-import java.util.Map;
 
 public interface ClientEndpointConfiguration extends EndpointConfiguration {
 
@@ -25,19 +24,5 @@ public interface ClientEndpointConfigura
 
     List<Extension> getExtensions();
 
-    /**
-     * 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
-     */
-    void beforeRequest(Map<String, List<String>> headers);
-
-    /**
-     * Provides the client with a mechanism to inspect the handshake response
-     * that is returned from the server.
-     *
-     * @param handshakeResponse The response
-     */
-    void afterResponse(HandshakeResponse handshakeResponse);
+    public ClientEndpointConfigurator getClientEndpointConfigurator();
 }

Added: tomcat/trunk/java/javax/websocket/ClientEndpointConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/ClientEndpointConfigurationBuilder.java?rev=1450570&view=auto
==============================================================================
--- tomcat/trunk/java/javax/websocket/ClientEndpointConfigurationBuilder.java (added)
+++ tomcat/trunk/java/javax/websocket/ClientEndpointConfigurationBuilder.java Wed Feb 27 01:32:26 2013
@@ -0,0 +1,99 @@
+/*
+ * 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 javax.websocket;
+
+import java.util.Collections;
+import java.util.List;
+
+public class ClientEndpointConfigurationBuilder {
+
+    private static final ClientEndpointConfigurator DEFAULT_CONFIGURATOR =
+            new ClientEndpointConfigurator() {};
+
+
+    public static ClientEndpointConfigurationBuilder create() {
+        return new ClientEndpointConfigurationBuilder();
+    }
+
+
+    private ClientEndpointConfigurator 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 ClientEndpointConfiguration build() {
+        return new DefaultClientEndpointConfiguration(preferredSubprotocols,
+                extensions, encoders, decoders, configurator);
+    }
+
+
+    public ClientEndpointConfigurationBuilder clientHandshakeConfigurator(
+            ClientEndpointConfigurator clientEndpointConfigurator) {
+        if (clientEndpointConfigurator == null) {
+            configurator = DEFAULT_CONFIGURATOR;
+        } else {
+            configurator = clientEndpointConfigurator;
+        }
+        return this;
+    }
+
+
+    public ClientEndpointConfigurationBuilder preferredSubprotocols(
+            List<String> preferredSubprotocols) {
+        if (preferredSubprotocols == null ||
+                preferredSubprotocols.size() == 0) {
+            this.preferredSubprotocols = Collections.EMPTY_LIST;
+        } else {
+            this.preferredSubprotocols =
+                    Collections.unmodifiableList(preferredSubprotocols);
+        }
+        return this;
+    }
+
+
+    public ClientEndpointConfigurationBuilder extensions(
+            List<Extension> extensions) {
+        if (extensions == null || extensions.size() == 0) {
+            this.extensions = Collections.EMPTY_LIST;
+        } else {
+            this.extensions = Collections.unmodifiableList(extensions);
+        }
+        return this;
+    }
+
+
+    public ClientEndpointConfigurationBuilder encoders(List<Encoder> encoders) {
+        if (encoders == null || encoders.size() == 0) {
+            this.encoders = Collections.EMPTY_LIST;
+        } else {
+            this.encoders = Collections.unmodifiableList(encoders);
+        }
+        return this;
+    }
+
+
+    public ClientEndpointConfigurationBuilder decoders(List<Decoder> decoders) {
+        if (decoders == null || decoders.size() == 0) {
+            this.decoders = Collections.EMPTY_LIST;
+        } else {
+            this.decoders = Collections.unmodifiableList(decoders);
+        }
+        return this;
+    }
+}

Added: tomcat/trunk/java/javax/websocket/ClientEndpointConfigurator.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/ClientEndpointConfigurator.java?rev=1450570&view=auto
==============================================================================
--- tomcat/trunk/java/javax/websocket/ClientEndpointConfigurator.java (added)
+++ tomcat/trunk/java/javax/websocket/ClientEndpointConfigurator.java Wed Feb 27 01:32:26 2013
@@ -0,0 +1,43 @@
+/*
+ * 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 javax.websocket;
+
+import java.util.List;
+import java.util.Map;
+
+public abstract class ClientEndpointConfigurator {
+
+    /**
+     * 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
+    }
+}

Copied: tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfiguration.java (from r1449658, tomcat/trunk/java/javax/websocket/DefaultClientConfiguration.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfiguration.java?p2=tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfiguration.java&p1=tomcat/trunk/java/javax/websocket/DefaultClientConfiguration.java&r1=1449658&r2=1450570&rev=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/DefaultClientConfiguration.java (original)
+++ tomcat/trunk/java/javax/websocket/DefaultClientEndpointConfiguration.java Wed Feb 27 01:32:26 2013
@@ -16,65 +16,64 @@
  */
 package javax.websocket;
 
-import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-public class DefaultClientConfiguration implements ClientEndpointConfiguration {
-    private List<String> preferredSubprotocols = new ArrayList<>();
-    private List<Extension> extensions = new ArrayList<>();
-    private List<Encoder> encoders = new ArrayList<>();
-    private List<Decoder> decoders = new ArrayList<>();
+public class DefaultClientEndpointConfiguration
+        implements ClientEndpointConfiguration {
+
+    private final List<String> preferredSubprotocols;
+    private final List<Extension> extensions;
+    private final List<Encoder> encoders;
+    private final List<Decoder> decoders;
+    private final Map<String,Object> userProperties = new HashMap<>();
+    private final ClientEndpointConfigurator configurator;
+
+
+    DefaultClientEndpointConfiguration(List<String> preferredSubprotocols,
+            List<Extension> extensions, List<Encoder> encoders,
+            List<Decoder> decoders, ClientEndpointConfigurator configurator) {
+        this.preferredSubprotocols = preferredSubprotocols;
+        this.extensions = extensions;
+        this.decoders = decoders;
+        this.encoders = encoders;
+        this.configurator = configurator;
+    }
+
 
     @Override
     public List<String> getPreferredSubprotocols() {
         return preferredSubprotocols;
     }
 
-    public DefaultClientConfiguration setPreferredSubprotocols(
-            List<String> preferredSubprotocols) {
-        this.preferredSubprotocols = preferredSubprotocols;
-        return this;
-    }
 
     @Override
     public List<Extension> getExtensions() {
         return extensions;
     }
 
-    public DefaultClientConfiguration setExtensions(
-            List<Extension> extensions) {
-        this.extensions = extensions;
-        return this;
-    }
 
     @Override
     public List<Encoder> getEncoders() {
         return encoders;
     }
 
-    public DefaultClientConfiguration setEncoders(List<Encoder> encoders) {
-        this.encoders = encoders;
-        return this;
-    }
 
     @Override
     public List<Decoder> getDecoders() {
         return decoders;
     }
 
-    public DefaultClientConfiguration setDecoders(List<Decoder> decoders) {
-        this.decoders = decoders;
-        return this;
-    }
 
     @Override
-    public void beforeRequest(Map<String, List<String>> headers) {
-        // NO-OP
+    public Map<String, Object> getUserProperties() {
+        return userProperties;
     }
 
+
     @Override
-    public void afterResponse(HandshakeResponse handshakeResponse) {
-        // NO-OP
+    public ClientEndpointConfigurator getClientEndpointConfigurator() {
+        return configurator;
     }
 }

Modified: tomcat/trunk/java/javax/websocket/EndpointConfiguration.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/EndpointConfiguration.java?rev=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/EndpointConfiguration.java (original)
+++ tomcat/trunk/java/javax/websocket/EndpointConfiguration.java Wed Feb 27 01:32:26 2013
@@ -17,7 +17,7 @@
 package javax.websocket;
 
 import java.util.List;
-//import java.util.Map;
+import java.util.Map;
 
 public interface EndpointConfiguration {
 
@@ -25,5 +25,5 @@ public interface EndpointConfiguration {
 
     List<Decoder> getDecoders();
 
-    //Map<String,Object> getUserProperties();
+    Map<String,Object> getUserProperties();
 }

Copied: tomcat/trunk/java/javax/websocket/server/DefaultServerEndpointConfiguration.java (from r1449658, tomcat/trunk/java/javax/websocket/server/DefaultServerConfiguration.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/server/DefaultServerEndpointConfiguration.java?p2=tomcat/trunk/java/javax/websocket/server/DefaultServerEndpointConfiguration.java&p1=tomcat/trunk/java/javax/websocket/server/DefaultServerConfiguration.java&r1=1449658&r2=1450570&rev=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/server/DefaultServerConfiguration.java (original)
+++ tomcat/trunk/java/javax/websocket/server/DefaultServerEndpointConfiguration.java Wed Feb 27 01:32:26 2013
@@ -16,63 +16,45 @@
  */
 package javax.websocket.server;
 
-import java.net.URI;
-import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.websocket.Decoder;
 import javax.websocket.Encoder;
-import javax.websocket.Endpoint;
 import javax.websocket.Extension;
-import javax.websocket.HandshakeResponse;
 
 /**
- * Provides the default implementation for WebSocket server endpoints.
+ * Provides the default configuration for WebSocket server endpoints.
  */
-public class DefaultServerConfiguration implements ServerEndpointConfiguration {
+public class DefaultServerEndpointConfiguration
+        implements ServerEndpointConfiguration {
 
-    private Class<? extends Endpoint> endpointClass;
-    private String path;
-    private List<String> subprotocols = new ArrayList<>();
-    private List<Extension> extensions = new ArrayList<>();
-    private List<Encoder> encoders = new ArrayList<>();
-    private List<Decoder> decoders = new ArrayList<>();
-
-    public DefaultServerConfiguration(Class<? extends Endpoint> endpointClass,
-            String path) {
+    private final Class<?> endpointClass;
+    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 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,
+            ServerEndpointConfigurator serverEndpointConfigurator) {
         this.endpointClass = endpointClass;
         this.path = path;
+        this.subprotocols = subprotocols;
+        this.extensions = extensions;
+        this.encoders = encoders;
+        this.decoders = decoders;
+        this.serverEndpointConfigurator = serverEndpointConfigurator;
     }
 
-    public DefaultServerConfiguration setEncoders(List<Encoder> encoders) {
-        this.encoders.clear();
-        this.encoders.addAll(encoders);
-        return this;
-    }
-
-    public DefaultServerConfiguration setDecoders(List<Decoder> decoders) {
-        this.decoders.clear();
-        this.decoders.addAll(decoders);
-        return this;
-    }
-
-    public DefaultServerConfiguration setSubprotocols(
-            List<String> subprotocols) {
-        this.subprotocols.clear();
-        this.subprotocols.addAll(subprotocols);
-        return this;
-    }
-
-    public DefaultServerConfiguration setExtensions(
-            List<Extension> extensions) {
-        this.extensions.clear();
-        this.extensions.addAll(extensions);
-        return this;
-    }
-
-
     @Override
-    public Class<? extends Endpoint> getEndpointClass() {
+    public Class<?> getEndpointClass() {
         return endpointClass;
     }
 
@@ -92,37 +74,22 @@ public class DefaultServerConfiguration 
     }
 
     @Override
-    public String getNegotiatedSubprotocol(List<String> requestedSubprotocols) {
-        // TODO
-        return null;
-    }
-
-    @Override
-    public List<Extension> getNegotiatedExtensions(
-            List<Extension> requestedExtensions) {
-        // TODO
-        return null;
+    public ServerEndpointConfigurator getServerEndpointConfigurator() {
+        return serverEndpointConfigurator;
     }
 
-    /**
-     * {@inheritDoc}
-     *
-     * The default implementation accepts all connection requests.
-     */
     @Override
-    public boolean checkOrigin(String originHeaderValue) {
-        return true;
+    public final Map<String, Object> getUserProperties() {
+        return userProperties;
     }
 
     @Override
-    public boolean matchesURI(URI uri) {
-        // TODO
-        return false;
+    public List<String> getSubprotocols() {
+        return subprotocols;
     }
 
     @Override
-    public void modifyHandshake(HandshakeRequest request,
-            HandshakeResponse response) {
-        // TODO
+    public List<Extension> getExtensions() {
+        return extensions;
     }
 }

Modified: tomcat/trunk/java/javax/websocket/server/ServerApplicationConfiguration.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/server/ServerApplicationConfiguration.java?rev=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/server/ServerApplicationConfiguration.java (original)
+++ tomcat/trunk/java/javax/websocket/server/ServerApplicationConfiguration.java Wed Feb 27 01:32:26 2013
@@ -18,9 +18,12 @@ package javax.websocket.server;
 
 import java.util.Set;
 
+import javax.websocket.Endpoint;
+
 public interface ServerApplicationConfiguration {
 
-    Set<Class<? extends ServerEndpointConfiguration>> getEndpointConfigurationClasses(Set<Class<? extends ServerEndpointConfiguration>> scanned);
+    Set<Class<? extends ServerEndpointConfiguration>> getEndpointConfiguration(
+            Set<Class<? extends Endpoint>> scanned);
 
     Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned);
 }

Copied: tomcat/trunk/java/javax/websocket/server/ServerEndpoint.java (from r1449658, tomcat/trunk/java/javax/websocket/server/WebSocketEndpoint.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/server/ServerEndpoint.java?p2=tomcat/trunk/java/javax/websocket/server/ServerEndpoint.java&p1=tomcat/trunk/java/javax/websocket/server/WebSocketEndpoint.java&r1=1449658&r2=1450570&rev=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/server/WebSocketEndpoint.java (original)
+++ tomcat/trunk/java/javax/websocket/server/ServerEndpoint.java Wed Feb 27 01:32:26 2013
@@ -26,7 +26,7 @@ import javax.websocket.Encoder;
 
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.TYPE)
-public @interface WebSocketEndpoint {
+public @interface ServerEndpoint {
 
     /**
      * URI or URI-template that the annotated class should be mapped to.
@@ -39,6 +39,6 @@ public @interface WebSocketEndpoint {
 
     Class<? extends Encoder>[] encoders() default {};
 
-    Class<? extends DefaultServerConfiguration> configuration()
-            default DefaultServerConfiguration.class;
+    public Class<? extends ServerEndpointConfigurator> configurator()
+            default ServerEndpointConfigurator.class;
 }

Modified: tomcat/trunk/java/javax/websocket/server/ServerEndpointConfiguration.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/server/ServerEndpointConfiguration.java?rev=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/server/ServerEndpointConfiguration.java (original)
+++ tomcat/trunk/java/javax/websocket/server/ServerEndpointConfiguration.java Wed Feb 27 01:32:26 2013
@@ -16,40 +16,29 @@
  */
 package javax.websocket.server;
 
-import java.net.URI;
 import java.util.List;
 
-import javax.websocket.Endpoint;
 import javax.websocket.EndpointConfiguration;
 import javax.websocket.Extension;
-import javax.websocket.HandshakeResponse;
 
+/**
+ * Provides configuration information for WebSocket endpoints published to a
+ * server. Applications may provide their own implementation or use
+ * {@link ServerEndpointConfigurationBuilder}.
+ */
 public interface ServerEndpointConfiguration extends EndpointConfiguration {
 
-    Class<? extends Endpoint> getEndpointClass();
+    Class<?> getEndpointClass();
 
-    String getNegotiatedSubprotocol(List<String> requestedSubprotocols);
+    List<String> getSubprotocols();
 
-    List<Extension> getNegotiatedExtensions(List<Extension> requestedExtensions);
-
-    /**
-     * Enables the WebSocket endpoint to accept or reject connections based on
-     * the HTTP origin header.
-     *
-     * @param originHeaderValue The HTTP origin header provided by the client.
-     *
-     * @return  <code>true</code> if the request should be accepted otherwise
-     *          <code>false</false>
-     */
-    boolean checkOrigin(String originHeaderValue);
-
-    boolean matchesURI(URI uri);
-
-    void modifyHandshake(HandshakeRequest request, HandshakeResponse response);
+    List<Extension> getExtensions();
 
     /**
      * Returns the path at which this WebSocket server endpoint has been
      * registered. It may be a path or a level 0 URI template.
      */
     String getPath();
+
+    ServerEndpointConfigurator getServerEndpointConfigurator();
 }

Added: tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurationBuilder.java?rev=1450570&view=auto
==============================================================================
--- tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurationBuilder.java (added)
+++ tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurationBuilder.java Wed Feb 27 01:32:26 2013
@@ -0,0 +1,107 @@
+/*
+ * 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 javax.websocket.server;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.websocket.Decoder;
+import javax.websocket.Encoder;
+import javax.websocket.Extension;
+
+public class ServerEndpointConfigurationBuilder {
+
+    public static ServerEndpointConfigurationBuilder create(
+            Class<?> endpointClass, String path) {
+        return new ServerEndpointConfigurationBuilder(endpointClass, path);
+    }
+
+
+    private final Class<?> endpointClass;
+    private final String path;
+    private List<Encoder> encoders = Collections.EMPTY_LIST;
+    private List<Decoder> decoders = Collections.EMPTY_LIST;
+    private List<String> subprotocols = Collections.EMPTY_LIST;
+    private List<Extension> extensions = Collections.EMPTY_LIST;
+    private ServerEndpointConfigurator configurator =
+            ServerEndpointConfigurator.getDefault();
+
+
+    private ServerEndpointConfigurationBuilder(Class<?> endpointClass,
+            String path) {
+        this.endpointClass = endpointClass;
+        this.path = path;
+    }
+
+    public ServerEndpointConfiguration build() {
+        return new DefaultServerEndpointConfiguration(endpointClass, path,
+                subprotocols, extensions, encoders, decoders, configurator);
+    }
+
+
+    public ServerEndpointConfigurationBuilder encoders(List<Encoder> encoders) {
+        if (encoders == null || encoders.size() == 0) {
+            this.encoders = Collections.EMPTY_LIST;
+        } else {
+            this.encoders = Collections.unmodifiableList(encoders);
+        }
+        return this;
+    }
+
+
+    public ServerEndpointConfigurationBuilder decoders(List<Decoder> decoders) {
+        if (decoders == null || decoders.size() == 0) {
+            this.decoders = Collections.EMPTY_LIST;
+        } else {
+            this.decoders = Collections.unmodifiableList(decoders);
+        }
+        return this;
+    }
+
+
+    public ServerEndpointConfigurationBuilder subprotocols(
+            List<String> subprotocols) {
+        if (subprotocols == null || subprotocols.size() == 0) {
+            this.subprotocols = Collections.EMPTY_LIST;
+        } else {
+            this.subprotocols = Collections.unmodifiableList(subprotocols);
+        }
+        return this;
+    }
+
+
+    public ServerEndpointConfigurationBuilder extensions(
+            List<Extension> extensions) {
+        if (extensions == null || extensions.size() == 0) {
+            this.extensions = Collections.EMPTY_LIST;
+        } else {
+            this.extensions = Collections.unmodifiableList(extensions);
+        }
+        return this;
+    }
+
+
+    public ServerEndpointConfigurationBuilder serverEndpointConfigurator(
+            ServerEndpointConfigurator serverEndpointConfigurator) {
+        if (serverEndpointConfigurator == null) {
+            this.configurator = ServerEndpointConfigurator.getDefault();
+        } else {
+            this.configurator = serverEndpointConfigurator;
+        }
+        return this;
+    }
+}

Added: tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurator.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurator.java?rev=1450570&view=auto
==============================================================================
--- tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurator.java (added)
+++ tomcat/trunk/java/javax/websocket/server/ServerEndpointConfigurator.java Wed Feb 27 01:32:26 2013
@@ -0,0 +1,101 @@
+/*
+ * 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 javax.websocket.server;
+
+import java.net.URI;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+import javax.websocket.Extension;
+import javax.websocket.HandshakeResponse;
+
+public abstract class ServerEndpointConfigurator {
+
+    private static volatile ServerEndpointConfigurator defaultImpl = null;
+    private static final Object defaultImplLock = new Object();
+
+    private static final String DEFAULT_IMPL_CLASSNAME =
+            "org.apache.tomcat.websocket.server.DefaultServerEndpointConfigurator";
+
+    static ServerEndpointConfigurator getDefault() {
+        if (defaultImpl == null) {
+            synchronized (defaultImplLock) {
+                if (defaultImpl == null) {
+                    defaultImpl = loadDefault();
+                }
+            }
+        }
+        return defaultImpl;
+    }
+
+
+    private static ServerEndpointConfigurator loadDefault() {
+        ServerEndpointConfigurator result = null;
+
+        ServiceLoader<ServerEndpointConfigurator> serviceLoader =
+                ServiceLoader.load(ServerEndpointConfigurator.class);
+
+        Iterator<ServerEndpointConfigurator> iter = serviceLoader.iterator();
+        while (result == null && iter.hasNext()) {
+            result = iter.next();
+        }
+
+        // Fall-back. Also used by unit tests
+        if (result == null) {
+            try {
+                Class<ServerEndpointConfigurator> clazz =
+                        (Class<ServerEndpointConfigurator>) Class.forName(
+                                DEFAULT_IMPL_CLASSNAME);
+                result = clazz.newInstance();
+            } catch (ClassNotFoundException | InstantiationException |
+                    IllegalAccessException e) {
+                // No options left. Just return null.
+            }
+        }
+        return result;
+    }
+
+    public String getNegotiatedSubprotocol(List<String> supported,
+            List<String> requested) {
+        return getDefault().getNegotiatedSubprotocol(supported, requested);
+    }
+
+
+    public List<Extension> getNegotiatedExtensions(List<Extension> installed,
+            List<Extension> requested) {
+        return getDefault().getNegotiatedExtensions(installed, requested);
+    }
+
+
+    public boolean checkOrigin(String originHeaderValue) {
+        return getDefault().checkOrigin(originHeaderValue);
+    }
+
+
+    public boolean matchesURI(String path, URI requestUri,
+            Map<String, String> templateExpansion) {
+        return getDefault().matchesURI(path, requestUri, templateExpansion);
+    }
+
+
+    public void modifyHandshake(ServerEndpointConfiguration sec,
+            HandshakeRequest request, HandshakeResponse response) {
+        getDefault().modifyHandshake(sec, request, response);
+    }
+}

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=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java Wed Feb 27 01:32:26 2013
@@ -95,7 +95,8 @@ public class WsWebSocketContainer
         }
         int port = path.getPort();
         Map<String,List<String>> reqHeaders = createRequestHeaders(host, port);
-        clientEndpointConfiguration.beforeRequest(reqHeaders);
+        clientEndpointConfiguration.getClientEndpointConfigurator().
+                beforeRequest(reqHeaders);
 
         ByteBuffer request = createRequest(path.getRawPath(), reqHeaders);
 
@@ -141,7 +142,8 @@ public class WsWebSocketContainer
 
             HandshakeResponse handshakeResponse =
                     processResponse(response, channel);
-            clientEndpointConfiguration.afterResponse(handshakeResponse);
+            clientEndpointConfiguration.getClientEndpointConfigurator().
+                    afterResponse(handshakeResponse);
 
             // Sub-protocol
             List<String> values = handshakeResponse.getHeaders().get(

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoEndpoint.java?rev=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoEndpoint.java Wed Feb 27 01:32:26 2013
@@ -24,14 +24,20 @@ import javax.websocket.Endpoint;
 import javax.websocket.EndpointConfiguration;
 import javax.websocket.MessageHandler;
 import javax.websocket.Session;
+import javax.websocket.server.ServerEndpointConfiguration;
 
 /**
  * Wrapper class for instances of POJOs annotated with
- * {@link javax.websocket.server.WebSocketEndpoint} so they appear as standard
+ * {@link javax.websocket.server.ServerEndpoint} so they appear as standard
  * {@link Endpoint} instances.
  */
 public class PojoEndpoint extends Endpoint {
 
+    public static final String POJO_PATH_PARAM_KEY =
+            "org.apache.tomcat.websocket.pojo.PojoEndpoint.pathParams";
+    public static final String POJO_METHOD_MAPPING_KEY =
+            "org.apache.tomcat.websocket.pojo.PojoEndpoint.methodMapping";
+
     private Object pojo;
     private Map<String,String> pathParameters;
     private PojoMethodMapping methodMapping;
@@ -40,12 +46,21 @@ public class PojoEndpoint extends Endpoi
     @Override
     public void onOpen(Session session,
             EndpointConfiguration endpointConfiguration) {
-        PojoEndpointConfiguration pec =
-                (PojoEndpointConfiguration) endpointConfiguration;
 
-        pojo = pec.createPojo();
-        pathParameters = pec.getPathParameters();
-        methodMapping = pec.getMethodMapping();
+        ServerEndpointConfiguration sec =
+                (ServerEndpointConfiguration) endpointConfiguration;
+
+        try {
+            pojo = sec.getEndpointClass().newInstance();
+        } catch (InstantiationException | IllegalAccessException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        pathParameters = (Map<String, String>) sec.getUserProperties().get(
+                POJO_PATH_PARAM_KEY);
+        methodMapping = (PojoMethodMapping) sec.getUserProperties().get(
+                POJO_METHOD_MAPPING_KEY);
 
         if (methodMapping.getOnOpen() != null) {
             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=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java Wed Feb 27 01:32:26 2013
@@ -35,7 +35,7 @@ import javax.websocket.server.PathParam;
 
 /**
  * For a POJO class annotated with
- * {@link javax.websocket.server.WebSocketEndpoint}, an instance of this class
+ * {@link javax.websocket.server.ServerEndpoint}, an instance of this class
  * caches the method handlers and the method and parameter information for the
  * onXXX calls.
  */

Added: tomcat/trunk/java/org/apache/tomcat/websocket/server/DefaultServerEndpointConfigurator.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/DefaultServerEndpointConfigurator.java?rev=1450570&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/DefaultServerEndpointConfigurator.java (added)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/DefaultServerEndpointConfigurator.java Wed Feb 27 01:32:26 2013
@@ -0,0 +1,104 @@
+/*
+ * 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.server;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.websocket.Extension;
+import javax.websocket.HandshakeResponse;
+import javax.websocket.server.HandshakeRequest;
+import javax.websocket.server.ServerEndpointConfiguration;
+import javax.websocket.server.ServerEndpointConfigurator;
+
+public class DefaultServerEndpointConfigurator
+        extends ServerEndpointConfigurator {
+
+    @Override
+    public String getNegotiatedSubprotocol(List<String> supported,
+            List<String> requested) {
+
+        for (String request : requested) {
+            if (supported.contains(request)) {
+                return request;
+            }
+        }
+        return "";
+    }
+
+
+    @Override
+    public List<Extension> getNegotiatedExtensions(List<Extension> installed,
+            List<Extension> requested) {
+
+        List<Extension> result = new ArrayList<>();
+        for (Extension request : requested) {
+            if (installed.contains(request)) {
+                result.add(request);
+            }
+        }
+        return result;
+    }
+
+
+    @Override
+    public boolean checkOrigin(String originHeaderValue) {
+        return true;
+    }
+
+    @Override
+    public boolean matchesURI(String path, URI requestUri,
+            Map<String, String> templateExpansion) {
+
+        String requestPath = requestUri.getPath();
+
+        if (path.indexOf('{') == -1) {
+            // Simple case - not a template
+            return requestPath.equals(path);
+        }
+
+        String servletPath = ServerContainerImpl.getServletPath(path);
+        if (!requestPath.startsWith(servletPath)) {
+            return false;
+        }
+
+        Map<String,String> params;
+        try {
+            params = ServerContainerImpl.getServerContainer().getPathParameters(
+                    servletPath, requestPath.substring(servletPath.length()));
+        } catch (IllegalArgumentException iae) {
+            return false;
+        }
+
+        if (params.size() == 0) {
+            return false;
+        }
+
+        templateExpansion.putAll(params);
+
+        return true;
+    }
+
+    @Override
+    public void modifyHandshake(ServerEndpointConfiguration sec,
+            HandshakeRequest request, HandshakeResponse response) {
+        // NO-OP
+    }
+
+}

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/ServerContainerImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/ServerContainerImpl.java?rev=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/ServerContainerImpl.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/ServerContainerImpl.java Wed Feb 27 01:32:26 2013
@@ -16,8 +16,6 @@
  */
 package org.apache.tomcat.websocket.server;
 
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
 import java.util.Collections;
 import java.util.Map;
 import java.util.WeakHashMap;
@@ -26,15 +24,15 @@ import java.util.concurrent.ConcurrentHa
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRegistration;
 import javax.websocket.DeploymentException;
-import javax.websocket.Endpoint;
 import javax.websocket.server.ServerEndpointConfiguration;
+import javax.websocket.server.ServerEndpointConfigurationBuilder;
 
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.res.StringManager;
 import org.apache.tomcat.websocket.WsSession;
 import org.apache.tomcat.websocket.WsWebSocketContainer;
-import org.apache.tomcat.websocket.pojo.PojoEndpointConfiguration;
+import org.apache.tomcat.websocket.pojo.PojoEndpoint;
 import org.apache.tomcat.websocket.pojo.PojoMethodMapping;
 
 /**
@@ -111,35 +109,21 @@ public class ServerContainerImpl extends
      * the specified configuration. {@link #setServletContext(ServletContext)}
      * must be called before calling this method.
      *
-     * @param endpointClass The WebSocket server implementation to publish
-     * @param path          The path to publish the implementation at
-     * @param configClass   The configuration to use when creating endpoint
+     * @param config        The configuration to use when creating endpoint
      *                          instances
      * @throws DeploymentException
      */
-    public void publishServer(Class<? extends Endpoint> endpointClass,
-            String path,
-            Class<? extends ServerEndpointConfiguration> configClass)
+    public void publishServer(ServerEndpointConfiguration sec)
             throws DeploymentException {
         if (servletContext == null) {
             throw new IllegalArgumentException(
                     sm.getString("serverContainer.servletContextMissing"));
         }
-        ServerEndpointConfiguration sec = null;
-        try {
-            Constructor<? extends ServerEndpointConfiguration> c =
-                    configClass.getConstructor(Class.class, String.class);
-            sec = c.newInstance(endpointClass, path);
-        } catch (InstantiationException | IllegalAccessException |
-                NoSuchMethodException | SecurityException |
-                IllegalArgumentException | InvocationTargetException e) {
-            throw new DeploymentException(sm.getString("sci.newInstance.fail",
-                    endpointClass.getName()), e);
-        }
+        String path = sec.getPath();
         String servletPath = getServletPath(path);
         if (log.isDebugEnabled()) {
             log.debug(sm.getString("serverContainer.endpointDeploy",
-                    endpointClass.getName(), path,
+                    sec.getEndpointClass(), path,
                     servletContext.getContextPath()));
         }
 
@@ -221,10 +205,13 @@ public class ServerContainerImpl extends
         if (pojo != null) {
             PojoMethodMapping methodMapping = pojoMethodMap.get(pojo);
             if (methodMapping != null) {
-                PojoEndpointConfiguration pojoSec =
-                        new PojoEndpointConfiguration(pojo, methodMapping,
-                                pathParameters);
-                return pojoSec;
+                sec = ServerEndpointConfigurationBuilder.create(
+                        pojo, methodMapping.getWsPath()).build();
+                sec.getUserProperties().put(
+                        PojoEndpoint.POJO_PATH_PARAM_KEY, pathParameters);
+                sec.getUserProperties().put(
+                        PojoEndpoint.POJO_METHOD_MAPPING_KEY, methodMapping);
+                return sec;
             }
         }
         throw new IllegalStateException(sm.getString(

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsSci.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsSci.java?rev=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsSci.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsSci.java Wed Feb 27 01:32:26 2013
@@ -22,14 +22,14 @@ import javax.servlet.ServletContainerIni
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.annotation.HandlesTypes;
-import javax.websocket.server.WebSocketEndpoint;
+import javax.websocket.server.ServerEndpoint;
 
 /**
  * Registers an interest in any class that is annotated with
- * {@link WebSocketEndpoint} so that Endpoint can be published via the WebSocket
+ * {@link ServerEndpoint} so that Endpoint can be published via the WebSocket
  * server.
  */
-@HandlesTypes({WebSocketEndpoint.class})
+@HandlesTypes({ServerEndpoint.class})
 public class WsSci implements ServletContainerInitializer {
 
     @Override
@@ -44,8 +44,8 @@ public class WsSci implements ServletCon
 
         ServerContainerImpl sc = ServerContainerImpl.getServerContainer();
         for (Class<?> clazz : clazzes) {
-            WebSocketEndpoint annotation =
-                    clazz.getAnnotation(WebSocketEndpoint.class);
+            ServerEndpoint annotation =
+                    clazz.getAnnotation(ServerEndpoint.class);
             sc.publishServer(clazz, ctx, annotation.value());
         }
     }

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServlet.java?rev=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServlet.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsServlet.java Wed Feb 27 01:32:26 2013
@@ -46,6 +46,7 @@ import javax.xml.bind.DatatypeConverter;
 
 import org.apache.tomcat.websocket.Constants;
 import org.apache.tomcat.websocket.WsRequest;
+import org.apache.tomcat.websocket.pojo.PojoEndpoint;
 
 /**
  * Handles the initial HTTP connection for WebSocket connections.
@@ -98,7 +99,7 @@ public class WsServlet extends HttpServl
                 req.getServletPath(), pathParameters);
         // Origin check
         String origin = req.getHeader("Origin");
-        if (!sec.checkOrigin(origin)) {
+        if (!sec.getServerEndpointConfigurator().checkOrigin(origin)) {
             resp.sendError(HttpServletResponse.SC_FORBIDDEN);
             return;
         }
@@ -106,7 +107,9 @@ public class WsServlet extends HttpServl
         List<String> subProtocols = getTokensFromHeader(req,
                 "Sec-WebSocket-Protocol");
         if (!subProtocols.isEmpty()) {
-            subProtocol = sec.getNegotiatedSubprotocol(subProtocols);
+            subProtocol = sec.getServerEndpointConfigurator().
+                    getNegotiatedSubprotocol(
+                            sec.getSubprotocols(), subProtocols);
         }
         // Extensions
         // Currently no extensions are supported by this implementation
@@ -133,7 +136,12 @@ public class WsServlet extends HttpServl
         }
         Endpoint ep;
         try {
-            ep = sec.getEndpointClass().newInstance();
+            Class<?> clazz = sec.getEndpointClass();
+            if (Endpoint.class.isAssignableFrom(clazz)) {
+                ep = (Endpoint) sec.getEndpointClass().newInstance();
+            } else {
+                ep = new PojoEndpoint();
+            }
         } catch (InstantiationException | IllegalAccessException e) {
             throw new ServletException(e);
         }

Added: tomcat/trunk/res/META-INF/tomcat-websocket.jar/services/javax.websocket.server.ServerEndpointConfigurator
URL: http://svn.apache.org/viewvc/tomcat/trunk/res/META-INF/tomcat-websocket.jar/services/javax.websocket.server.ServerEndpointConfigurator?rev=1450570&view=auto
==============================================================================
--- tomcat/trunk/res/META-INF/tomcat-websocket.jar/services/javax.websocket.server.ServerEndpointConfigurator (added)
+++ tomcat/trunk/res/META-INF/tomcat-websocket.jar/services/javax.websocket.server.ServerEndpointConfigurator Wed Feb 27 01:32:26 2013
@@ -0,0 +1 @@
+org.apache.tomcat.websocket.server.DefaultServerEndpointConfigurator
\ No newline at end of file

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=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java Wed Feb 27 01:32:26 2013
@@ -22,8 +22,8 @@ import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
+import javax.websocket.ClientEndpointConfigurationBuilder;
 import javax.websocket.ContainerProvider;
-import javax.websocket.DefaultClientConfiguration;
 import javax.websocket.Session;
 import javax.websocket.WebSocketContainer;
 
@@ -65,8 +65,9 @@ public class TestWsRemoteEndpoint extend
         tomcat.start();
 
         Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
-                new DefaultClientConfiguration(), new URI("http://localhost:" +
-                        getPort() + TesterEchoServer.Config.PATH_ASYNC));
+                ClientEndpointConfigurationBuilder.create().build(),
+                new URI("http://localhost:" + getPort() +
+                        TesterEchoServer.Config.PATH_ASYNC));
 
         CountDownLatch latch = new CountDownLatch(1);
         wsSession.getUserProperties().put("latch", latch);

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=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java Wed Feb 27 01:32:26 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.tomcat.websocket;
 
+import java.net.SocketTimeoutException;
 import java.net.URI;
 import java.nio.ByteBuffer;
 import java.util.List;
@@ -26,8 +27,8 @@ import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
 import javax.servlet.ServletContextEvent;
+import javax.websocket.ClientEndpointConfigurationBuilder;
 import javax.websocket.ContainerProvider;
-import javax.websocket.DefaultClientConfiguration;
 import javax.websocket.DeploymentException;
 import javax.websocket.Endpoint;
 import javax.websocket.EndpointConfiguration;
@@ -35,7 +36,7 @@ import javax.websocket.MessageHandler;
 import javax.websocket.OnMessage;
 import javax.websocket.Session;
 import javax.websocket.WebSocketContainer;
-import javax.websocket.server.DefaultServerConfiguration;
+import javax.websocket.server.ServerEndpointConfigurationBuilder;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -82,8 +83,9 @@ public class TestWsWebSocketContainer ex
         WebSocketContainer wsContainer =
                 ContainerProvider.getWebSocketContainer();
         Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
-                new DefaultClientConfiguration(), new URI("http://localhost:" +
-                        getPort() + TesterEchoServer.Config.PATH_ASYNC));
+                ClientEndpointConfigurationBuilder.create().build(),
+                new URI("http://localhost:" + getPort() +
+                        TesterEchoServer.Config.PATH_ASYNC));
         CountDownLatch latch = new CountDownLatch(1);
         BasicText handler = new BasicText(latch);
         wsSession.addMessageHandler(handler);
@@ -112,8 +114,9 @@ public class TestWsWebSocketContainer ex
         WebSocketContainer wsContainer =
                 ContainerProvider.getWebSocketContainer();
         wsContainer.connectToServer(TesterEndpoint.class,
-                new DefaultClientConfiguration(), new URI("ftp://localhost:" +
-                        getPort() + TesterEchoServer.Config.PATH_ASYNC));
+                ClientEndpointConfigurationBuilder.create().build(),
+                new URI("ftp://localhost:" + getPort() +
+                        TesterEchoServer.Config.PATH_ASYNC));
     }
 
 
@@ -130,7 +133,7 @@ public class TestWsWebSocketContainer ex
         WebSocketContainer wsContainer =
                 ContainerProvider.getWebSocketContainer();
         wsContainer.connectToServer(TesterEndpoint.class,
-                new DefaultClientConfiguration(),
+                ClientEndpointConfigurationBuilder.create().build(),
                 new URI("http://" + TesterEchoServer.Config.PATH_ASYNC));
     }
 
@@ -218,8 +221,9 @@ public class TestWsWebSocketContainer ex
         tomcat.start();
 
         Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
-                new DefaultClientConfiguration(), new URI("http://localhost:" +
-                        getPort() + TesterEchoServer.Config.PATH_BASIC));
+                ClientEndpointConfigurationBuilder.create().build(),
+                        new URI("http://localhost:" + getPort() +
+                                TesterEchoServer.Config.PATH_BASIC));
         BasicHandler<?> handler;
         CountDownLatch latch = new CountDownLatch(1);
         wsSession.getUserProperties().put("latch", latch);
@@ -288,8 +292,8 @@ public class TestWsWebSocketContainer ex
         tomcat.start();
 
         Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
-                new DefaultClientConfiguration(), new URI("http://localhost:" +
-                        getPort() + BlockingConfig.PATH));
+                ClientEndpointConfigurationBuilder.create().build(),
+                new URI("http://localhost:" + getPort() + BlockingConfig.PATH));
 
         if (!setTimeoutOnContainer) {
             wsSession.getAsyncRemote().setSendTimeout(TIMEOUT_MS);
@@ -369,8 +373,9 @@ public class TestWsWebSocketContainer ex
         tomcat.start();
 
         Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
-                new DefaultClientConfiguration(), new URI("http://localhost:" +
-                        getPort() + ConstantTxConfig.PATH));
+                ClientEndpointConfigurationBuilder.create().build(),
+                new URI("http://localhost:" + getPort() +
+                        ConstantTxConfig.PATH));
 
         wsSession.addMessageHandler(new BlockingBinaryHandler());
 
@@ -383,16 +388,19 @@ public class TestWsWebSocketContainer ex
             loops++;
         }
 
-        // Check nothing really bad happened
-        Assert.assertNull(ConstantTxEndpoint.getException());
+        // Check the right exception was thrown
+        Assert.assertNotNull(ConstantTxEndpoint.getException());
+        Assert.assertEquals(ExecutionException.class,
+                ConstantTxEndpoint.getException().getClass());
+        Assert.assertNotNull(ConstantTxEndpoint.getException().getCause());
+        Assert.assertEquals(SocketTimeoutException.class,
+                ConstantTxEndpoint.getException().getCause().getClass());
 
         // Check correct time passed
         Assert.assertTrue(ConstantTxEndpoint.getTimeout() >= TIMEOUT_MS);
 
         // Check the timeout wasn't too long
         Assert.assertTrue(ConstantTxEndpoint.getTimeout() < TIMEOUT_MS*2);
-
-        Assert.assertNotNull(ConstantTxEndpoint.getException());
     }
 
 
@@ -509,8 +517,8 @@ public class TestWsWebSocketContainer ex
             super.contextInitialized(sce);
             ServerContainerImpl sc = ServerContainerImpl.getServerContainer();
             try {
-                sc.publishServer(ConstantTxEndpoint.class, PATH,
-                        DefaultServerConfiguration.class);
+                sc.publishServer(ServerEndpointConfigurationBuilder.create(
+                        ConstantTxEndpoint.class, PATH).build());
                 if (TestWsWebSocketContainer.timoutOnContainer) {
                     sc.setAsyncSendTimeout(TIMEOUT_MS);
                 }
@@ -653,7 +661,7 @@ public class TestWsWebSocketContainer ex
     private Session connectToEchoServerBasic(WebSocketContainer wsContainer,
             Class<? extends Endpoint> clazz) throws Exception {
         return wsContainer.connectToServer(clazz,
-                new DefaultClientConfiguration(),
+                ClientEndpointConfigurationBuilder.create().build(),
                 new URI("http://localhost:" + getPort() +
                         TesterEchoServer.Config.PATH_BASIC));
     }

Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java?rev=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java Wed Feb 27 01:32:26 2013
@@ -25,11 +25,11 @@ import javax.websocket.OnClose;
 import javax.websocket.OnMessage;
 import javax.websocket.OnOpen;
 import javax.websocket.Session;
-import javax.websocket.server.WebSocketEndpoint;
+import javax.websocket.server.ServerEndpoint;
 
 import util.HTMLFilter;
 
-@WebSocketEndpoint(value = "/websocket/chat")
+@ServerEndpoint(value = "/websocket/chat")
 public class ChatAnnotation {
 
     private static final String GUEST_PREFIX = "Guest";

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=1450570&r1=1450569&r2=1450570&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 Wed Feb 27 01:32:26 2013
@@ -22,9 +22,9 @@ import java.nio.ByteBuffer;
 import javax.websocket.OnMessage;
 import javax.websocket.PongMessage;
 import javax.websocket.Session;
-import javax.websocket.server.WebSocketEndpoint;
+import javax.websocket.server.ServerEndpoint;
 
-@WebSocketEndpoint("/websocket/echoAnnotation")
+@ServerEndpoint("/websocket/echoAnnotation")
 public class EchoAnnotation {
 
     @OnMessage

Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/WsConfigListener.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/WsConfigListener.java?rev=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/WsConfigListener.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/WsConfigListener.java Wed Feb 27 01:32:26 2013
@@ -19,7 +19,7 @@ package websocket.echo;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.annotation.WebListener;
 import javax.websocket.DeploymentException;
-import javax.websocket.server.DefaultServerConfiguration;
+import javax.websocket.server.ServerEndpointConfigurationBuilder;
 
 import org.apache.tomcat.websocket.server.ServerContainerImpl;
 import org.apache.tomcat.websocket.server.WsListener;
@@ -32,8 +32,8 @@ public class WsConfigListener extends Ws
         super.contextInitialized(sce);
         ServerContainerImpl sc = ServerContainerImpl.getServerContainer();
         try {
-            sc.publishServer(EchoEndpoint.class, "/websocket/echoProgrammatic",
-                    DefaultServerConfiguration.class);
+            sc.publishServer(ServerEndpointConfigurationBuilder.create(
+                    EchoEndpoint.class, "/websocket/echoProgrammatic").build());
         } catch (DeploymentException e) {
             throw new IllegalStateException(e);
         }

Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java?rev=1450570&r1=1450569&r2=1450570&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java Wed Feb 27 01:32:26 2013
@@ -25,9 +25,9 @@ import javax.websocket.OnClose;
 import javax.websocket.OnMessage;
 import javax.websocket.OnOpen;
 import javax.websocket.Session;
-import javax.websocket.server.WebSocketEndpoint;
+import javax.websocket.server.ServerEndpoint;
 
-@WebSocketEndpoint(value = "/websocket/snake")
+@ServerEndpoint(value = "/websocket/snake")
 public class SnakeAnnotation {
 
     public static final int PLAYFIELD_WIDTH = 640;



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