Author: markt Date: Mon Sep 15 09:51:52 2014 New Revision: 1624984 URL: http://svn.apache.org/r1624984 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56982 Return the actual negotiated extensions rather than an empty list for Session.getNegotiatedExtensions()
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java tomcat/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java tomcat/trunk/webapps/docs/changelog.xml 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=1624984&r1=1624983&r2=1624984&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Mon Sep 15 09:51:52 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; @@ -105,6 +106,7 @@ public class WsSession implements Sessio * * @param localEndpoint * @param wsRemoteEndpoint + * @param negotiatedExtensions * @throws DeploymentException */ public WsSession(Endpoint localEndpoint, @@ -112,7 +114,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; @@ -138,6 +140,7 @@ public class WsSession implements Sessio this.queryString = queryString; this.userPrincipal = userPrincipal; this.httpSessionId = httpSessionId; + this.negotiatedExtensions = negotiatedExtensions; if (subProtocol == null) { this.subProtocol = ""; } else { @@ -302,7 +305,7 @@ public class WsSession implements Sessio @Override public List<Extension> getNegotiatedExtensions() { checkState(); - return Collections.emptyList(); + return negotiatedExtensions; } 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=1624984&r1=1624983&r2=1624984&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java Mon Sep 15 09:51:52 2014 @@ -326,8 +326,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/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java?rev=1624984&r1=1624983&r2=1624984&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/server/UpgradeUtil.java Mon Sep 15 09:51:52 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; @@ -122,11 +123,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<>(transformations.size()); + for (Transformation t : transformations) { + negotiatedExtensionsPhase2.add(t.getExtensionResponse()); + } + } // Build the transformation pipeline Transformation transformation = null; @@ -199,7 +216,8 @@ public class UpgradeUtil { WsHttpUpgradeHandler wsHandler = req.upgrade(WsHttpUpgradeHandler.class); wsHandler.preInit(ep, perSessionServerEndpointConfig, sc, wsRequest, - subProtocol, transformation, pathParams, req.isSecure()); + negotiatedExtensionsPhase2, subProtocol, transformation, pathParams, + req.isSecure()); } Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java?rev=1624984&r1=1624983&r2=1624984&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHttpUpgradeHandler.java Mon Sep 15 09:51:52 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.ReadListener; @@ -32,6 +33,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.juli.logging.Log; import org.apache.juli.logging.LogFactory; @@ -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/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1624984&r1=1624983&r2=1624984&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Mon Sep 15 09:51:52 2014 @@ -189,6 +189,10 @@ <bug>56907</bug>: Ensure that client IO threads are stopped if a secure WebSocket client connection fails. (markt) </fix> + <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-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org