Author: markt
Date: Sat Dec 22 22:11:42 2012
New Revision: 1425354

URL: http://svn.apache.org/viewvc?rev=1425354&view=rev
Log:
WebSocket 1.0 implementation part 18 of many
Sync the implementation to the latest draft of the spec API

Added:
    tomcat/trunk/java/org/apache/tomcat/websocket/PojoEndpointConfiguration.java
      - copied, changed from r1424725, 
tomcat/trunk/java/org/apache/tomcat/websocket/PojoServerEndpointConfiguration.java
    tomcat/trunk/java/org/apache/tomcat/websocket/WebSocketContainerImpl.java
      - copied, changed from r1424725, 
tomcat/trunk/java/org/apache/tomcat/websocket/ClientContainerImpl.java
Removed:
    tomcat/trunk/java/org/apache/tomcat/websocket/ClientContainerImpl.java
    
tomcat/trunk/java/org/apache/tomcat/websocket/PojoServerEndpointConfiguration.java
Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/PathParam.java
    tomcat/trunk/java/org/apache/tomcat/websocket/PojoMethodMapping.java
    tomcat/trunk/java/org/apache/tomcat/websocket/ServerContainerImpl.java
    tomcat/trunk/java/org/apache/tomcat/websocket/WsEndpointPojo.java
    tomcat/trunk/java/org/apache/tomcat/websocket/WsProtocolHandler.java
    tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/websocket/WsSci.java
    tomcat/trunk/java/org/apache/tomcat/websocket/WsServlet.java
    tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/PathParam.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/PathParam.java?rev=1425354&r1=1425353&r2=1425354&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/PathParam.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/PathParam.java Sat Dec 22 
22:11:42 2012
@@ -19,9 +19,10 @@ package org.apache.tomcat.websocket;
 /**
  * Stores the parameter type and name for a parameter that needs to be passed 
to
  * an onXxx method of {@link javax.websocket.Endpoint}. The name is only 
present
- * for parameters annotated with {@link javax.websocket.WebSocketPathParam}. 
For
- * the {@link javax.websocket.Session} and {@link java.lang.Throwable}
- * parameters, {@link #getName()} will always return <code>null</code>.
+ * for parameters annotated with
+ * {@link javax.websocket.server.WebSocketPathParam}. For the
+ * {@link javax.websocket.Session} and {@link java.lang.Throwable} parameters,
+ * {@link #getName()} will always return <code>null</code>.
  */
 public class PathParam {
 

Copied: 
tomcat/trunk/java/org/apache/tomcat/websocket/PojoEndpointConfiguration.java 
(from r1424725, 
tomcat/trunk/java/org/apache/tomcat/websocket/PojoServerEndpointConfiguration.java)
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/PojoEndpointConfiguration.java?p2=tomcat/trunk/java/org/apache/tomcat/websocket/PojoEndpointConfiguration.java&p1=tomcat/trunk/java/org/apache/tomcat/websocket/PojoServerEndpointConfiguration.java&r1=1424725&r2=1425354&rev=1425354&view=diff
==============================================================================
--- 
tomcat/trunk/java/org/apache/tomcat/websocket/PojoServerEndpointConfiguration.java
 (original)
+++ 
tomcat/trunk/java/org/apache/tomcat/websocket/PojoEndpointConfiguration.java 
Sat Dec 22 22:11:42 2012
@@ -16,33 +16,31 @@
  */
 package org.apache.tomcat.websocket;
 
-import javax.websocket.DefaultServerConfiguration;
-import javax.websocket.Endpoint;
-import javax.websocket.EndpointFactory;
+import javax.websocket.server.DefaultServerConfiguration;
 
-public class PojoServerEndpointConfiguration extends
-        DefaultServerConfiguration<Endpoint> {
+public class PojoEndpointConfiguration extends
+        DefaultServerConfiguration {
+
+    private final Class<?> pojoClass;
+    private final PojoMethodMapping methodMapping;
+    private final String servletPath;
+    private final String pathInfo;
 
     @Override
     public boolean checkOrigin(String originHeaderValue) {
         // Allow all
         return true;
     }
-    private final EndpointFactory<Endpoint> endpointFactory;
-    private final String servletPath;
 
 
-    PojoServerEndpointConfiguration(Class<?> pojo,
-            PojoMethodMapping methodMapping, String servletPath, String 
pathInfo) {
-        this.endpointFactory = new PojoEndpointFactory(pojo, methodMapping,
-                pathInfo);
+    PojoEndpointConfiguration(Class<?> pojoClass,
+            PojoMethodMapping methodMapping, String servletPath,
+            String pathInfo) {
+        super(WsEndpointPojo.class, methodMapping.getMappingPath());
+        this.pojoClass = pojoClass;
+        this.methodMapping = methodMapping;
         this.servletPath = servletPath;
-    }
-
-
-    @Override
-    public EndpointFactory<Endpoint> getEndpointFactory() {
-        return endpointFactory;
+        this.pathInfo = pathInfo;
     }
 
 
@@ -51,31 +49,23 @@ public class PojoServerEndpointConfigura
         return servletPath;
     }
 
-    private static class PojoEndpointFactory implements
-            EndpointFactory<Endpoint> {
-
-        private final Class<?> pojo;
-        private final PojoMethodMapping methodMapping;
-        private final String pathInfo;
+    public Object getPojo() {
+        try {
+            return pojoClass.newInstance();
+        } catch (InstantiationException | IllegalAccessException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+            throw new IllegalArgumentException(e);
+        }
+    }
 
 
-        public PojoEndpointFactory(Class<?> pojo,
-                PojoMethodMapping methodMapping, String pathInfo) {
-            this.pojo = pojo;
-            this.methodMapping = methodMapping;
-            this.pathInfo = pathInfo;
-        }
+    public String getPathInfo() {
+        return pathInfo;
+    }
 
 
-        @Override
-        public Endpoint createEndpoint() {
-            Endpoint ep;
-            try {
-                ep = new WsEndpointPojo(pojo, methodMapping, pathInfo);
-            } catch (InstantiationException | IllegalAccessException e) {
-                throw new IllegalArgumentException(e);
-            }
-            return ep;
-        }
+    public PojoMethodMapping getMethodMapping() {
+        return methodMapping;
     }
 }

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/PojoMethodMapping.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/PojoMethodMapping.java?rev=1425354&r1=1425353&r2=1425354&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/PojoMethodMapping.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/PojoMethodMapping.java Sat 
Dec 22 22:11:42 2012
@@ -32,12 +32,12 @@ import javax.websocket.WebSocketClose;
 import javax.websocket.WebSocketError;
 import javax.websocket.WebSocketMessage;
 import javax.websocket.WebSocketOpen;
-import javax.websocket.WebSocketPathParam;
+import javax.websocket.server.WebSocketPathParam;
 
 /**
- * For a POJO class annotated with {@link javax.websocket.WebSocketEndpoint}, 
an
- * instance of this class caches the method and parameter information for the
- * onXXX calls.
+ * For a POJO class annotated with
+ * {@link javax.websocket.server.WebSocketEndpoint}, an instance of this class
+ * caches the method and parameter information for the onXXX calls.
  */
 public class PojoMethodMapping {
 
@@ -48,10 +48,12 @@ public class PojoMethodMapping {
     private final PathParam[] onCloseParams;
     private final PathParam[] onErrorParams;
     private final Set<MessageMethod> onMessage = new HashSet<>();
+    private final String mappingPath;
     private final UriTemplate template;
 
 
     public PojoMethodMapping(Class<?> clazzPojo, String path, String 
mappingPath) {
+        this.mappingPath = mappingPath;
         Method open = null;
         Method close = null;
         Method error = null;
@@ -83,6 +85,11 @@ public class PojoMethodMapping {
     }
 
 
+    public String getMappingPath() {
+        return mappingPath;
+    }
+
+
     public Method getOnOpen() {
         return onOpen;
     }

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/ServerContainerImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/ServerContainerImpl.java?rev=1425354&r1=1425353&r2=1425354&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/ServerContainerImpl.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/ServerContainerImpl.java Sat 
Dec 22 22:11:42 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.tomcat.websocket;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.util.Map;
 import java.util.WeakHashMap;
 import java.util.concurrent.ConcurrentHashMap;
@@ -23,8 +25,8 @@ import java.util.concurrent.ConcurrentHa
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRegistration;
 import javax.websocket.DeploymentException;
-import javax.websocket.ServerContainer;
-import javax.websocket.ServerEndpointConfiguration;
+import javax.websocket.Endpoint;
+import javax.websocket.server.ServerEndpointConfiguration;
 
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
@@ -32,10 +34,9 @@ import org.apache.tomcat.util.res.String
 
 /**
  * Provides a per class loader (i.e. per web application) instance of a
- * {@link ServerContainer}.
+ * ServerContainer.
  */
-public class ServerContainerImpl extends ClientContainerImpl implements
-        ServerContainer {
+public class ServerContainerImpl extends WebSocketContainerImpl {
 
     // Needs to be a WeakHashMap to prevent memory leaks when a context is
     // stopped
@@ -45,11 +46,6 @@ public class ServerContainerImpl extends
     protected Log log = LogFactory.getLog(ServerContainerImpl.class);
 
 
-    /**
-     * Intended to be used by implementations of
-     * {@link javax.websocket.ContainerProvider#getServerContainer()} to obtain
-     * the correct {@link ServerContainer} instance.
-     */
     public static ServerContainerImpl getServerContainer() {
         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
         ServerContainerImpl result = null;
@@ -63,7 +59,7 @@ public class ServerContainerImpl extends
         return result;
     }
     private volatile ServletContext servletContext = null;
-    private Map<String,ServerEndpointConfiguration<?>> configMap = new 
ConcurrentHashMap<>();
+    private Map<String,ServerEndpointConfiguration> configMap = new 
ConcurrentHashMap<>();
     private Map<String,Class<?>> pojoMap = new ConcurrentHashMap<>();
     private Map<Class<?>,PojoMethodMapping> pojoMethodMap = new 
ConcurrentHashMap<>();
 
@@ -78,26 +74,29 @@ public class ServerContainerImpl extends
     }
 
 
-    @Override
-    public void publishServer(
-            Class<? extends ServerEndpointConfiguration<?>> clazz)
+    public void publishServer(Class<? extends Endpoint> endpointClass,
+            String path,
+            Class<? extends ServerEndpointConfiguration> configClass)
             throws DeploymentException {
         if (servletContext == null) {
             throw new IllegalArgumentException(
                     sm.getString("serverContainer.servletContextMissing"));
         }
-        ServerEndpointConfiguration<?> sec = null;
+        ServerEndpointConfiguration sec = null;
         try {
-            sec = clazz.newInstance();
-        } catch (InstantiationException | IllegalAccessException e) {
+            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",
-                    clazz.getName()), e);
+                    endpointClass.getName()), e);
         }
-        String path = sec.getPath();
         String mappingPath = Util.getServletMappingPath(path);
         if (log.isDebugEnabled()) {
             log.debug(sm.getString("serverContainer.endpointDeploy",
-                    clazz.getName(), path, servletContext.getContextPath()));
+                    endpointClass.getName(), path, 
servletContext.getContextPath()));
         }
         configMap.put(mappingPath.substring(0, mappingPath.length() - 2), sec);
         addWsServletMapping(mappingPath);
@@ -105,9 +104,9 @@ public class ServerContainerImpl extends
 
 
     /**
-     * Provides the equivalent of {@link #publishServer(Class)} for publishing
-     * plain old java objects (POJOs) that have been annotated as WebSocket
-     * endpoints.
+     * Provides the equivalent of {@link #publishServer(Class,String,Class)} 
for
+     * publishing plain old java objects (POJOs) that have been annotated as
+     * WebSocket endpoints.
      *
      * @param pojo The annotated POJO
      * @param ctxt The ServletContext the endpoint is to be published in
@@ -148,9 +147,9 @@ public class ServerContainerImpl extends
     }
 
 
-    public ServerEndpointConfiguration<?> getServerEndpointConfiguration(
+    public ServerEndpointConfiguration getServerEndpointConfiguration(
             String servletPath, String pathInfo) {
-        ServerEndpointConfiguration<?> sec = configMap.get(servletPath);
+        ServerEndpointConfiguration sec = configMap.get(servletPath);
         if (sec != null) {
             return sec;
         }
@@ -158,7 +157,7 @@ public class ServerContainerImpl extends
         if (pojo != null) {
             PojoMethodMapping mapping = pojoMethodMap.get(pojo);
             if (mapping != null) {
-                PojoServerEndpointConfiguration pojoSec = new 
PojoServerEndpointConfiguration(
+                PojoEndpointConfiguration pojoSec = new 
PojoEndpointConfiguration(
                         pojo, mapping, servletPath, pathInfo);
                 return pojoSec;
             }

Copied: 
tomcat/trunk/java/org/apache/tomcat/websocket/WebSocketContainerImpl.java (from 
r1424725, 
tomcat/trunk/java/org/apache/tomcat/websocket/ClientContainerImpl.java)
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WebSocketContainerImpl.java?p2=tomcat/trunk/java/org/apache/tomcat/websocket/WebSocketContainerImpl.java&p1=tomcat/trunk/java/org/apache/tomcat/websocket/ClientContainerImpl.java&r1=1424725&r2=1425354&rev=1425354&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/ClientContainerImpl.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WebSocketContainerImpl.java 
Sat Dec 22 22:11:42 2012
@@ -19,16 +19,17 @@ package org.apache.tomcat.websocket;
 import java.net.URI;
 import java.util.Set;
 
-import javax.websocket.ClientContainer;
 import javax.websocket.ClientEndpointConfiguration;
 import javax.websocket.DeploymentException;
 import javax.websocket.Endpoint;
+import javax.websocket.Extension;
 import javax.websocket.Session;
+import javax.websocket.WebSocketContainer;
 
-public class ClientContainerImpl implements ClientContainer {
+public class WebSocketContainerImpl implements WebSocketContainer {
 
     @Override
-    public Session connectToServer(Object endpoint, URI path)
+    public Session connectToServer(Class<?> annotatedEndpointClass, URI path)
             throws DeploymentException {
         // TODO Auto-generated method stub
         return null;
@@ -36,7 +37,7 @@ public class ClientContainerImpl impleme
 
 
     @Override
-    public Session connectToServer(Endpoint endpoint,
+    public Session connectToServer(Class<? extends Endpoint> endpoint,
             ClientEndpointConfiguration clientEndpointConfiguration, URI path)
             throws DeploymentException {
         // TODO Auto-generated method stub
@@ -91,8 +92,22 @@ public class ClientContainerImpl impleme
 
 
     @Override
-    public Set<String> getInstalledExtensions() {
+    public Set<Extension> getInstalledExtensions() {
         // TODO Auto-generated method stub
         return null;
     }
+
+
+    @Override
+    public long getDefaultAsyncSendTimeout() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    @Override
+    public void setAsyncSendTimeout(long timeout) {
+        // TODO Auto-generated method stub
+
+    }
 }

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsEndpointPojo.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsEndpointPojo.java?rev=1425354&r1=1425353&r2=1425354&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsEndpointPojo.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsEndpointPojo.java Sat Dec 
22 22:11:42 2012
@@ -21,35 +21,32 @@ import java.lang.reflect.InvocationTarge
 
 import javax.websocket.CloseReason;
 import javax.websocket.Endpoint;
+import javax.websocket.EndpointConfiguration;
 import javax.websocket.MessageHandler;
 import javax.websocket.Session;
 
 /**
  * Wrapper class for instances of POJOs annotated with
- * {@link javax.websocket.WebSocketEndpoint} so they appear as standard
+ * {@link javax.websocket.server.WebSocketEndpoint} so they appear as standard
  * {@link Endpoint} instances.
  */
 public class WsEndpointPojo extends Endpoint {
 
-    private final Object pojo;
-    private final String pathInfo;
-    private final PojoMethodMapping methodMapping;
-    private Session session = null;
-
-
-    public WsEndpointPojo(Class<?> clazzPojo, PojoMethodMapping methodMapping,
-            String pathInfo) throws InstantiationException,
-            IllegalAccessException {
-        // TODO Use factory from annotation if present
-        this.pojo = clazzPojo.newInstance();
-        this.methodMapping = methodMapping;
-        this.pathInfo = pathInfo;
-    }
+    private Object pojo;
+    private String pathInfo;
+    private PojoMethodMapping methodMapping;
 
 
     @Override
-    public void onOpen(Session session) {
-        this.session = session;
+    public void onOpen(Session session,
+            EndpointConfiguration endpointConfiguration) {
+        PojoEndpointConfiguration pec =
+                (PojoEndpointConfiguration) endpointConfiguration;
+
+        pojo = pec.getPojo();
+        pathInfo = pec.getPathInfo();
+        methodMapping = pec.getMethodMapping();
+
         if (methodMapping.getOnOpen() != null) {
             try {
                 methodMapping.getOnOpen().invoke(pojo,
@@ -68,7 +65,7 @@ public class WsEndpointPojo extends Endp
 
 
     @Override
-    public void onClose(CloseReason closeReason) {
+    public void onClose(Session session, CloseReason closeReason) {
         if (methodMapping.getOnClose() == null) {
             // If the POJO doesn't handle the close, close the connection
             try {
@@ -91,7 +88,7 @@ public class WsEndpointPojo extends Endp
 
 
     @Override
-    public void onError(Throwable throwable) {
+    public void onError(Session session, Throwable throwable) {
         if (methodMapping.getOnError() != null) {
             try {
                 methodMapping.getOnError().invoke(

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsProtocolHandler.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsProtocolHandler.java?rev=1425354&r1=1425353&r2=1425354&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsProtocolHandler.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsProtocolHandler.java Sat 
Dec 22 22:11:42 2012
@@ -28,6 +28,7 @@ import javax.servlet.http.WebConnection;
 import javax.websocket.CloseReason;
 import javax.websocket.CloseReason.CloseCodes;
 import javax.websocket.Endpoint;
+import javax.websocket.EndpointConfiguration;
 
 /**
  * Servlet 3.1 HTTP upgrade handler for WebSocket connections.
@@ -35,12 +36,14 @@ import javax.websocket.Endpoint;
 public class WsProtocolHandler implements ProtocolHandler {
 
     private final Endpoint ep;
+    private final EndpointConfiguration endpointConfig;
     private final ClassLoader applicationClassLoader;
     private final WsSession wsSession;
 
 
-    public WsProtocolHandler(Endpoint ep) {
+    public WsProtocolHandler(Endpoint ep, EndpointConfiguration 
endpointConfig) {
         this.ep = ep;
+        this.endpointConfig = endpointConfig;
         applicationClassLoader = 
Thread.currentThread().getContextClassLoader();
         wsSession = new WsSession(ep);
     }
@@ -68,7 +71,7 @@ public class WsProtocolHandler implement
         ClassLoader cl = t.getContextClassLoader();
         t.setContextClassLoader(applicationClassLoader);
         try {
-            ep.onOpen(wsSession);
+            ep.onOpen(wsSession, endpointConfig);
         } finally {
             t.setContextClassLoader(cl);
         }
@@ -81,7 +84,7 @@ public class WsProtocolHandler implement
         ClassLoader cl = t.getContextClassLoader();
         t.setContextClassLoader(applicationClassLoader);
         try {
-            ep.onError(throwable);
+            ep.onError(wsSession, throwable);
         } finally {
             t.setContextClassLoader(cl);
         }

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpoint.java?rev=1425354&r1=1425353&r2=1425354&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpoint.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpoint.java Sat Dec 
22 22:11:42 2012
@@ -269,13 +269,48 @@ public class WsRemoteEndpoint implements
             try {
                 writeBarrier.await();
             } catch (InterruptedException | BrokenBarrierException e) {
-                wsSession.getLocalEndpoint().onError(e);
+                wsSession.getLocalEndpoint().onError(wsSession, e);
             }
         }
         try {
             sos.write(data.array(), data.arrayOffset(), data.limit());
         } catch (IOException e) {
-            wsSession.getLocalEndpoint().onError(e);
+            wsSession.getLocalEndpoint().onError(wsSession, e);
         }
     }
+
+
+    @Override
+    public void setBatchingAllowed(boolean batchingAllowed) {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public boolean getBatchingAllowed() {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+
+    @Override
+    public void flushBatch() {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public long getAsyncSendTimeout() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    @Override
+    public void setAsyncSendTimeout(long timeout) {
+        // TODO Auto-generated method stub
+
+    }
 }

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsSci.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsSci.java?rev=1425354&r1=1425353&r2=1425354&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsSci.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSci.java Sat Dec 22 
22:11:42 2012
@@ -22,7 +22,7 @@ import javax.servlet.ServletContainerIni
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.annotation.HandlesTypes;
-import javax.websocket.WebSocketEndpoint;
+import javax.websocket.server.WebSocketEndpoint;
 
 /**
  * Registers an interest in any class that is annotated with

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsServlet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsServlet.java?rev=1425354&r1=1425353&r2=1425354&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsServlet.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsServlet.java Sat Dec 22 
22:11:42 2012
@@ -34,7 +34,8 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.ProtocolHandler;
 import javax.websocket.Endpoint;
-import javax.websocket.ServerEndpointConfiguration;
+import javax.websocket.Extension;
+import javax.websocket.server.ServerEndpointConfiguration;
 import javax.xml.bind.DatatypeConverter;
 
 /**
@@ -57,7 +58,7 @@ public class WsServlet extends HttpServl
         // Information required to send the server handshake message
         String key;
         String subProtocol = null;
-        List<String> extensions = Collections.emptyList();
+        List<Extension> extensions = Collections.emptyList();
         if (!headerContainsToken(req, "upgrade", "websocket")) {
             resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
             return;
@@ -78,7 +79,7 @@ public class WsServlet extends HttpServl
         }
         // Need an Endpoint instance to progress this further
         ServerContainerImpl cp = ServerContainerImpl.getServerContainer();
-        ServerEndpointConfiguration<?> sec = cp.getServerEndpointConfiguration(
+        ServerEndpointConfiguration sec = cp.getServerEndpointConfiguration(
                 req.getServletPath(), req.getPathInfo());
         // Origin check
         String origin = req.getHeader("Origin");
@@ -95,8 +96,9 @@ public class WsServlet extends HttpServl
         // Extensions
         List<String> requestedExtensions = getTokensFromHeader(req,
                 "Sec-WebSocket-Extensions");
-        if (!extensions.isEmpty()) {
-            extensions = sec.getNegotiatedExtensions(requestedExtensions);
+        if (!requestedExtensions.isEmpty()) {
+            // TODO
+            // extensions = sec.getNegotiatedExtensions(requestedExtensions);
         }
         // If we got this far, all is good. Accept the connection.
         resp.setHeader("Upgrade", "websocket");
@@ -107,17 +109,22 @@ public class WsServlet extends HttpServl
         }
         if (!extensions.isEmpty()) {
             StringBuilder sb = new StringBuilder();
-            Iterator<String> iter = extensions.iterator();
+            Iterator<Extension> iter = extensions.iterator();
             // There must be at least one
             sb.append(iter.next());
             while (iter.hasNext()) {
                 sb.append(',');
-                sb.append(iter.next());
+                sb.append(iter.next().getName());
             }
             resp.setHeader("Sec-WebSocket-Extensions", sb.toString());
         }
-        Endpoint ep = (Endpoint) sec.getEndpointFactory().createEndpoint();
-        ProtocolHandler wsHandler = new WsProtocolHandler(ep);
+        Endpoint ep;
+        try {
+            ep = sec.getEndpointClass().newInstance();
+        } catch (InstantiationException | IllegalAccessException e) {
+            throw new ServletException(e);
+        }
+        ProtocolHandler wsHandler = new WsProtocolHandler(ep, sec);
         req.upgrade(wsHandler);
     }
 

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=1425354&r1=1425353&r2=1425354&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Sat Dec 22 
22:11:42 2012
@@ -23,12 +23,12 @@ import java.lang.reflect.TypeVariable;
 import java.net.URI;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
+import java.security.Principal;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import javax.websocket.ClientContainer;
 import javax.websocket.CloseReason;
 import javax.websocket.CloseReason.CloseCodes;
 import javax.websocket.Endpoint;
@@ -36,6 +36,7 @@ import javax.websocket.MessageHandler;
 import javax.websocket.PongMessage;
 import javax.websocket.RemoteEndpoint;
 import javax.websocket.Session;
+import javax.websocket.WebSocketContainer;
 
 public class WsSession implements Session {
 
@@ -54,7 +55,7 @@ public class WsSession implements Sessio
 
 
     @Override
-    public ClientContainer getContainer() {
+    public WebSocketContainer getContainer() {
         // TODO Auto-generated method stub
         return null;
     }
@@ -156,13 +157,6 @@ public class WsSession implements Sessio
 
 
     @Override
-    public long getInactiveTime() {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-
-    @Override
     public boolean isOpen() {
         // TODO Auto-generated method stub
         return false;
@@ -230,7 +224,7 @@ public class WsSession implements Sessio
 
 
     @Override
-    public Map<String,String[]> getRequestParameterMap() {
+    public Map<String,List<String>> getRequestParameterMap() {
         // TODO Auto-generated method stub
         return null;
     }
@@ -277,7 +271,7 @@ public class WsSession implements Sessio
     }
 
     protected void onClose(CloseReason closeReason) {
-        localEndpoint.onClose(closeReason);
+        localEndpoint.onClose(this, closeReason);
     }
 
 
@@ -377,4 +371,18 @@ public class WsSession implements Sessio
             }
         }
     }
+
+
+    @Override
+    public String getId() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    @Override
+    public Principal getUserPrincipal() {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to