tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1417683 - in /tomcat/trunk/java/org/apache/tomcat/websocket: ClientContainerImpl.java PojoServerEndpointConfiguration.java ServerContainerImpl.java WsEndpointPojo.java WsFrame.java WsServlet.java WsSession.java
Date Wed, 05 Dec 2012 22:52:22 GMT
Author: markt
Date: Wed Dec  5 22:52:21 2012
New Revision: 1417683

URL: http://svn.apache.org/viewvc?rev=1417683&view=rev
Log:
Update implementation for API changes

Added:
    tomcat/trunk/java/org/apache/tomcat/websocket/PojoServerEndpointConfiguration.java   (with
props)
Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/ClientContainerImpl.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/WsFrame.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/ClientContainerImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/ClientContainerImpl.java?rev=1417683&r1=1417682&r2=1417683&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/ClientContainerImpl.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/ClientContainerImpl.java Wed Dec  5 22:52:21
2012
@@ -20,20 +20,30 @@ 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.Session;
 
 public class ClientContainerImpl implements ClientContainer {
 
     @Override
-    public void connectToServer(Object endpoint, URI path)
+    public Session connectToServer(Object endpoint, URI path)
             throws DeploymentException {
         // TODO Auto-generated method stub
+        return null;
+    }
 
+    @Override
+    public Session connectToServer(Endpoint endpoint,
+            ClientEndpointConfiguration clientEndpointConfiguration, URI path)
+            throws DeploymentException {
+        // TODO Auto-generated method stub
+        return null;
     }
 
     @Override
-    public Set<Session> getActiveSessions() {
+    public Set<Session> getOpenSessions() {
         // TODO Auto-generated method stub
         return null;
     }

Added: tomcat/trunk/java/org/apache/tomcat/websocket/PojoServerEndpointConfiguration.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/PojoServerEndpointConfiguration.java?rev=1417683&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/PojoServerEndpointConfiguration.java (added)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/PojoServerEndpointConfiguration.java Wed
Dec  5 22:52:21 2012
@@ -0,0 +1,78 @@
+/*
+ *  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;
+
+import javax.websocket.DefaultServerConfiguration;
+import javax.websocket.Endpoint;
+import javax.websocket.EndpointFactory;
+
+public class PojoServerEndpointConfiguration extends
+        DefaultServerConfiguration<Endpoint> {
+
+    @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);
+        this.servletPath = servletPath;
+    }
+
+
+    @Override
+    public EndpointFactory<Endpoint> getEndpointFactory() {
+        return endpointFactory;
+    }
+
+    @Override
+    public String getPath() {
+        return servletPath;
+    }
+
+    private static class PojoEndpointFactory
+            implements EndpointFactory<Endpoint> {
+
+        private final Class<?> pojo;
+        private final PojoMethodMapping methodMapping;
+        private final String pathInfo;
+
+        public PojoEndpointFactory(Class<?> pojo,
+                PojoMethodMapping methodMapping, String pathInfo) {
+            this.pojo = pojo;
+            this.methodMapping = methodMapping;
+            this.pathInfo = pathInfo;
+        }
+
+        @Override
+        public Endpoint createEndpoint() {
+            Endpoint ep;
+            try {
+                ep = new WsEndpointPojo(pojo, methodMapping, pathInfo);
+            } catch (InstantiationException | IllegalAccessException e) {
+                throw new IllegalArgumentException(e);
+            }
+            return ep;
+        }
+    }
+}

Propchange: tomcat/trunk/java/org/apache/tomcat/websocket/PojoServerEndpointConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1417683&r1=1417682&r2=1417683&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/ServerContainerImpl.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/ServerContainerImpl.java Wed Dec  5 22:52:21
2012
@@ -23,7 +23,6 @@ import java.util.concurrent.ConcurrentHa
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRegistration;
 import javax.websocket.DeploymentException;
-import javax.websocket.Endpoint;
 import javax.websocket.ServerContainer;
 import javax.websocket.ServerEndpointConfiguration;
 
@@ -73,7 +72,7 @@ public class ServerContainerImpl extends
 
     private volatile ServletContext servletContext = null;
 
-    private Map<String, Class<? extends Endpoint>> endpointMap =
+    private Map<String, ServerEndpointConfiguration<?>> configMap =
             new ConcurrentHashMap<>();
 
     private Map<String, Class<?>> pojoMap = new ConcurrentHashMap<>();
@@ -93,7 +92,7 @@ public class ServerContainerImpl extends
 
 
     @Override
-    public void publishServer(Class<? extends Endpoint> clazz)
+    public void publishServer(Class<? extends ServerEndpointConfiguration<?>>
clazz)
             throws DeploymentException {
 
         if (servletContext == null) {
@@ -101,17 +100,15 @@ public class ServerContainerImpl extends
                     sm.getString("serverContainer.servletContextMissing"));
         }
 
-        Endpoint ep = null;
+        ServerEndpointConfiguration<?> sec = null;
         try {
-            ep = clazz.newInstance();
+            sec = clazz.newInstance();
         } catch (InstantiationException | IllegalAccessException e) {
             throw new DeploymentException(
                     sm.getString("sci.newInstance.fail", clazz.getName()), e);
         }
 
-        ServerEndpointConfiguration config =
-                (ServerEndpointConfiguration) ep.getEndpointConfiguration();
-        String path = config.getPath();
+        String path = sec.getPath();
         String mappingPath = Util.getServletMappingPath(path);
 
         if (log.isDebugEnabled()) {
@@ -119,8 +116,7 @@ public class ServerContainerImpl extends
                     clazz.getName(), path, servletContext.getContextPath()));
         }
 
-        endpointMap.put(
-                mappingPath.substring(0, mappingPath.length() - 2), clazz);
+        configMap.put(mappingPath.substring(0, mappingPath.length() - 2), sec);
         addWsServletMapping(mappingPath);
     }
 
@@ -175,22 +171,22 @@ public class ServerContainerImpl extends
     }
 
 
-    public Endpoint getEndpoint(String servletPath, String pathInfo)
-            throws InstantiationException, IllegalAccessException {
-        Class<? extends Endpoint> clazzEndpoint = endpointMap.get(servletPath);
-        if (clazzEndpoint != null) {
-            Endpoint ep = clazzEndpoint.newInstance();
-            return ep;
+    public ServerEndpointConfiguration<?> getServerEndpointConfiguration(
+            String servletPath, String pathInfo) {
+
+        ServerEndpointConfiguration<?> sec = configMap.get(servletPath);
+        if (sec != null) {
+            return sec;
         }
 
-        // TODO Need to cache the pojoMethodMapping too
-        Class<?> clazzPojo = pojoMap.get(servletPath);
-        if (clazzPojo != null) {
-            PojoMethodMapping mapping = pojoMethodMap.get(clazzPojo);
+        Class<?> pojo = pojoMap.get(servletPath);
+        if (pojo != null) {
+            PojoMethodMapping mapping = pojoMethodMap.get(pojo);
             if (mapping != null) {
-                Endpoint ep = new WsEndpointPojo(clazzPojo,
-                        mapping, servletPath, pathInfo);
-                return ep;
+                PojoServerEndpointConfiguration pojoSec =
+                        new PojoServerEndpointConfiguration(pojo, mapping,
+                                servletPath, pathInfo);
+                return pojoSec;
             }
         }
 

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=1417683&r1=1417682&r2=1417683&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsEndpointPojo.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsEndpointPojo.java Wed Dec  5 22:52:21
2012
@@ -19,9 +19,7 @@ package org.apache.tomcat.websocket;
 import java.lang.reflect.InvocationTargetException;
 
 import javax.websocket.CloseReason;
-import javax.websocket.DefaultServerConfiguration;
 import javax.websocket.Endpoint;
-import javax.websocket.EndpointConfiguration;
 import javax.websocket.Session;
 
 /**
@@ -32,33 +30,20 @@ import javax.websocket.Session;
 public class WsEndpointPojo extends Endpoint {
 
     private final Object pojo;
-    private final EndpointConfiguration config;
     private final String pathInfo;
     private final PojoMethodMapping methodMapping;
     private Session session = null;
 
     public WsEndpointPojo(Class<?> clazzPojo, PojoMethodMapping methodMapping,
-            String ServletPath, String pathInfo)
+            String pathInfo)
             throws InstantiationException, IllegalAccessException {
+        // TODO Use factory from annotation if present
         this.pojo = clazzPojo.newInstance();
-        this.config = new DefaultServerConfiguration(ServletPath) {
-
-            @Override
-            public boolean checkOrigin(String originHeaderValue) {
-                return true;
-            }
-        };
-
         this.methodMapping = methodMapping;
         this.pathInfo = pathInfo;
     }
 
     @Override
-    public EndpointConfiguration getEndpointConfiguration() {
-        return config;
-    }
-
-    @Override
     public void onOpen(Session session) {
         this.session = session;
 

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java?rev=1417683&r1=1417682&r2=1417683&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsFrame.java Wed Dec  5 22:52:21 2012
@@ -105,7 +105,7 @@ public class WsFrame {
         b = inputBuffer[1];
         // Client data must be masked
         if ((b & 0x80) == 0) {
-            throw new IOException(sm.getString("wsFrame.notMasked.notMasked"));
+            throw new IOException(sm.getString("wsFrame.notMasked"));
         }
 
         payloadLength = b & 0x7F;

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=1417683&r1=1417682&r2=1417683&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsServlet.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsServlet.java Wed Dec  5 22:52:21 2012
@@ -90,20 +90,12 @@ public class WsServlet extends HttpServl
 
         // Need an Endpoint instance to progress this further
         ServerContainerImpl cp = ServerContainerImpl.getServerContainer();
-        Endpoint ep = null;
-        try {
-             ep = cp.getEndpoint(req.getServletPath(), req.getPathInfo());
-        } catch (InstantiationException | IllegalAccessException e) {
-            // This will trigger an error response
-            throw new ServletException(e);
-        }
-
-        ServerEndpointConfiguration epConfig =
-                (ServerEndpointConfiguration) ep.getEndpointConfiguration();
+        ServerEndpointConfiguration<?> sec = cp.getServerEndpointConfiguration(
+                req.getServletPath(), req.getPathInfo());
 
         // Origin check
         String origin = req.getHeader("Origin");
-        if (!epConfig.checkOrigin(origin)) {
+        if (!sec.checkOrigin(origin)) {
             resp.sendError(HttpServletResponse.SC_FORBIDDEN);
             return;
         }
@@ -112,14 +104,14 @@ public class WsServlet extends HttpServl
         List<String> subProtocols =
                 getTokensFromHeader(req, "Sec-WebSocket-Protocol");
         if (!subProtocols.isEmpty()) {
-            subProtocol = epConfig.getNegotiatedSubprotocol(subProtocols);
+            subProtocol = sec.getNegotiatedSubprotocol(subProtocols);
         }
 
         // Extensions
         List<String> requestedExtensions =
                 getTokensFromHeader(req, "Sec-WebSocket-Extensions");
         if (!extensions.isEmpty()) {
-            extensions = epConfig.getNegotiatedExtensions(requestedExtensions);
+            extensions = sec.getNegotiatedExtensions(requestedExtensions);
         }
 
         // If we got this far, all is good. Accept the connection.
@@ -141,6 +133,7 @@ public class WsServlet extends HttpServl
             resp.setHeader("Sec-WebSocket-Extensions", sb.toString());
         }
 
+        Endpoint ep = (Endpoint) sec.getEndpointFactory().createEndpoint();
         ProtocolHandler wsHandler = new WsProtocolHandler(ep);
 
         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=1417683&r1=1417682&r2=1417683&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Wed Dec  5 22:52:21 2012
@@ -26,7 +26,6 @@ import java.util.Set;
 import javax.websocket.ClientContainer;
 import javax.websocket.CloseReason;
 import javax.websocket.CloseReason.CloseCodes;
-import javax.websocket.Encoder;
 import javax.websocket.MessageHandler;
 import javax.websocket.RemoteEndpoint;
 import javax.websocket.Session;
@@ -42,12 +41,6 @@ public class WsSession implements Sessio
     }
 
     @Override
-    public void setEncoders(List<Encoder> encoders) {
-        // TODO Auto-generated method stub
-
-    }
-
-    @Override
     public void addMessageHandler(MessageHandler listener) {
         messageHandlers.add(listener);
     }
@@ -93,7 +86,7 @@ public class WsSession implements Sessio
     }
 
     @Override
-    public boolean isActive() {
+    public boolean isOpen() {
         // TODO Auto-generated method stub
         return false;
     }
@@ -163,4 +156,9 @@ public class WsSession implements Sessio
         return null;
     }
 
+    @Override
+    public Map<String, Object> getUserProperties() {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }



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


Mime
View raw message