You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by vi...@apache.org on 2014/09/18 04:14:10 UTC

svn commit: r1625878 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/tomcat/websocket/ java/org/apache/tomcat/websocket/server/ webapps/docs/

Author: violetagg
Date: Thu Sep 18 02:14:10 2014
New Revision: 1625878

URL: http://svn.apache.org/r1625878
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56982
Merged revision(s) 1624984 from tomcat/trunk:
Return the actual negotiated extensions rather than an empty list for Session.getNegotiatedExtensions()

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsSession.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1624984

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsSession.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsSession.java?rev=1625878&r1=1625877&r2=1625878&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsSession.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsSession.java Thu Sep 18 02:14:10 2014
@@ -75,6 +75,7 @@ public class WsSession implements Sessio
     private final Principal userPrincipal;
     private final EndpointConfig endpointConfig;
 
+    private final List<Extension> negotiatedExtensions;
     private final String subProtocol;
     private final Map<String,String> pathParameters;
     private final boolean secure;
@@ -106,6 +107,7 @@ public class WsSession implements Sessio
      *
      * @param localEndpoint
      * @param wsRemoteEndpoint
+     * @param negotiatedExtensions
      * @throws DeploymentException
      */
     public WsSession(Endpoint localEndpoint,
@@ -113,7 +115,7 @@ public class WsSession implements Sessio
             WsWebSocketContainer wsWebSocketContainer,
             URI requestUri, Map<String,List<String>> requestParameterMap,
             String queryString, Principal userPrincipal, String httpSessionId,
-            String subProtocol, Map<String,String> pathParameters,
+            List<Extension> negotiatedExtensions, String subProtocol, Map<String,String> pathParameters,
             boolean secure, EndpointConfig endpointConfig) throws DeploymentException {
         this.localEndpoint = localEndpoint;
         this.wsRemoteEndpoint = wsRemoteEndpoint;
@@ -139,6 +141,7 @@ public class WsSession implements Sessio
         this.queryString = queryString;
         this.userPrincipal = userPrincipal;
         this.httpSessionId = httpSessionId;
+        this.negotiatedExtensions = negotiatedExtensions;
         if (subProtocol == null) {
             this.subProtocol = "";
         } else {
@@ -303,7 +306,7 @@ public class WsSession implements Sessio
     @Override
     public List<Extension> getNegotiatedExtensions() {
         checkState();
-        return Collections.emptyList();
+        return negotiatedExtensions;
     }
 
 

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java?rev=1625878&r1=1625877&r2=1625878&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java Thu Sep 18 02:14:10 2014
@@ -348,8 +348,8 @@ public class WsWebSocketContainer
         WsRemoteEndpointImplClient wsRemoteEndpointClient = new WsRemoteEndpointImplClient(channel);
 
         WsSession wsSession = new WsSession(endpoint, wsRemoteEndpointClient,
-                this, null, null, null, null, null, subProtocol,
-                Collections.<String,String>emptyMap(), secure,
+                this, null, null, null, null, null, Collections.<Extension>emptyList(),
+                subProtocol, Collections.<String,String>emptyMap(), secure,
                 clientEndpointConfiguration);
 
         WsFrameClient wsFrameClient = new WsFrameClient(response, channel,

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java?rev=1625878&r1=1625877&r2=1625878&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java Thu Sep 18 02:14:10 2014
@@ -19,6 +19,7 @@ package org.apache.tomcat.websocket.serv
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -124,11 +125,27 @@ public class UpgradeUtil {
         while (extHeaders.hasMoreElements()) {
             Util.parseExtensionHeader(extensionsRequested, extHeaders.nextElement());
         }
-        List<Extension> negotiatedExtensions = sec.getConfigurator().getNegotiatedExtensions(
+        // Negotiation phase 1. By default this simply filters out the
+        // extensions that the server does not support but applications could
+        // use a custom configurator to do more than this.
+        List<Extension> negotiatedExtensionsPhase1 = sec.getConfigurator().getNegotiatedExtensions(
                 Constants.INSTALLED_EXTENSIONS, extensionsRequested);
 
-        // Create the Transformations that will be applied to this connection
-        List<Transformation> transformations = createTransformations(negotiatedExtensions);
+        // Negotiation phase 2. Create the Transformations that will be applied
+        // to this connection. Note than an extension may be dropped at this
+        // point if the client has requested a configuration that the server is
+        // unable to support.
+        List<Transformation> transformations = createTransformations(negotiatedExtensionsPhase1);
+
+        List<Extension> negotiatedExtensionsPhase2;
+        if (transformations.isEmpty()) {
+            negotiatedExtensionsPhase2 = Collections.emptyList();
+        } else {
+            negotiatedExtensionsPhase2 = new ArrayList<Extension>(transformations.size());
+            for (Transformation t : transformations) {
+                negotiatedExtensionsPhase2.add(t.getExtensionResponse());
+            }
+        }
 
         // Build the transformation pipeline
         Transformation transformation = null;
@@ -208,7 +225,8 @@ public class UpgradeUtil {
             WsHttpUpgradeHandler wsHandler =
                     ((RequestFacade) inner).upgrade(WsHttpUpgradeHandler.class);
             wsHandler.preInit(ep, perSessionServerEndpointConfig, sc, wsRequest,
-                    subProtocol, transformation, pathParams, req.isSecure());
+                    negotiatedExtensionsPhase2, subProtocol, transformation, pathParams,
+                    req.isSecure());
         } else {
             throw new ServletException("Upgrade failed");
         }

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java?rev=1625878&r1=1625877&r2=1625878&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java Thu Sep 18 02:14:10 2014
@@ -18,6 +18,7 @@ package org.apache.tomcat.websocket.serv
 
 import java.io.EOFException;
 import java.io.IOException;
+import java.util.List;
 import java.util.Map;
 
 import javax.servlet.http.HttpSession;
@@ -26,6 +27,7 @@ import javax.websocket.CloseReason.Close
 import javax.websocket.DeploymentException;
 import javax.websocket.Endpoint;
 import javax.websocket.EndpointConfig;
+import javax.websocket.Extension;
 
 import org.apache.coyote.http11.upgrade.AbstractServletInputStream;
 import org.apache.coyote.http11.upgrade.AbstractServletOutputStream;
@@ -56,6 +58,7 @@ public class WsHttpUpgradeHandler implem
     private EndpointConfig endpointConfig;
     private WsServerContainer webSocketContainer;
     private WsHandshakeRequest handshakeRequest;
+    private List<Extension> negotiatedExtensions;
     private String subProtocol;
     private Transformation transformation;
     private Map<String,String> pathParameters;
@@ -72,12 +75,14 @@ public class WsHttpUpgradeHandler implem
 
     public void preInit(Endpoint ep, EndpointConfig endpointConfig,
             WsServerContainer wsc, WsHandshakeRequest handshakeRequest,
-            String subProtocol, Transformation transformation,
-            Map<String,String> pathParameters, boolean secure) {
+            List<Extension> negotiatedExtensionsPhase2, String subProtocol,
+            Transformation transformation, Map<String,String> pathParameters,
+            boolean secure) {
         this.ep = ep;
         this.endpointConfig = endpointConfig;
         this.webSocketContainer = wsc;
         this.handshakeRequest = handshakeRequest;
+        this.negotiatedExtensions = negotiatedExtensionsPhase2;
         this.subProtocol = subProtocol;
         this.transformation = transformation;
         this.pathParameters = pathParameters;
@@ -123,7 +128,8 @@ public class WsHttpUpgradeHandler implem
                     handshakeRequest.getParameterMap(),
                     handshakeRequest.getQueryString(),
                     handshakeRequest.getUserPrincipal(), httpSessionId,
-                    subProtocol, pathParameters, secure, endpointConfig);
+                    negotiatedExtensions, subProtocol, pathParameters, secure,
+                    endpointConfig);
             WsFrameServer wsFrame = new WsFrameServer(sis, wsSession, transformation);
             sos.setWriteListener(new WsWriteListener(this, wsRemoteEndpointServer));
             // WsFrame adds the necessary final transformations. Copy the

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1625878&r1=1625877&r2=1625878&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Sep 18 02:14:10 2014
@@ -255,6 +255,10 @@
         Extend support for the <code>permessage-deflate</code> extension to
         compression of outgoing messages on the server side. (markt)
       </add>
+      <fix>
+        <bug>56982</bug>: Return the actual negotiated extensions rather than an
+        empty list for <code>Session.getNegotiatedExtensions()</code>. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Web applications">



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