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 2014/06/05 15:29:08 UTC

svn commit: r1600651 - in /tomcat/trunk: java/org/apache/tomcat/websocket/server/LocalStrings.properties java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java webapps/docs/changelog.xml

Author: markt
Date: Thu Jun  5 13:29:07 2014
New Revision: 1600651

URL: http://svn.apache.org/r1600651
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56573
Change the value returned by Session.getRequestURI() from the value obtained from HttpServletRequest.getRequestURI() to the value obtained from HttpServletRequest.getRequestURI() with the scheme changed to ws or wss as appropriate. Note that the WebSocket Expert Group is expected to clarify the expected behaviour for Session.getRequestURI() which may result in further changes.

Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
    tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties?rev=1600651&r1=1600650&r2=1600651&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties Thu Jun  5 13:29:07 2014
@@ -29,6 +29,8 @@ uriTemplate.emptySegment=The path [{0}] 
 uriTemplate.invalidPath=The path [{0}] is not valid.
 uriTemplate.invalidSegment=The segment [{0}] is not valid in the provided path [{1}]
 
+wsHandshakeRequest.unknownScheme=The scheme [{0}] is not recognised. [http] or [https] is expected
+
 wsHttpUpgradeHandler.destroyFailed=Failed to close WebConnection while destroying the WebSocket HttpUpgradeHandler
 wsHttpUpgradeHandler.noPreInit=The preInit() method must be called to configure the WebSocket HttpUpgradeHandler before the container calls init(). Usually, this means the Servlet that created the WsHttpUpgradeHandler instance should also call preInit()
 

Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java?rev=1600651&r1=1600650&r2=1600651&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java Thu Jun  5 13:29:07 2014
@@ -30,11 +30,15 @@ import java.util.Map.Entry;
 import javax.servlet.http.HttpServletRequest;
 import javax.websocket.server.HandshakeRequest;
 
+import org.apache.tomcat.util.res.StringManager;
+
 /**
  * Represents the request that this session was opened under.
  */
 public class WsHandshakeRequest implements HandshakeRequest {
 
+    private static final StringManager sm = StringManager.getManager(Constants.PACKAGE_NAME);
+
     private final URI requestUri;
     private final Map<String,List<String>> parameterMap;
     private final String queryString;
@@ -54,11 +58,29 @@ public class WsHandshakeRequest implemen
         httpSession = request.getSession(false);
 
         // URI
-        StringBuilder sb = new StringBuilder(request.getRequestURI());
-        if (queryString != null) {
-            sb.append("?");
-            sb.append(queryString);
+        // Based on request.getRequestURL() implementation
+        StringBuilder sb = new StringBuilder();
+        String scheme = request.getScheme();
+        int port = request.getServerPort();
+        if (port < 0)
+            port = 80; // Work around java.net.URL bug
+
+        if (scheme.equals("http")) {
+            sb.append("ws");
+        } else if (scheme.equals("https")) {
+            sb.append("wss");
+        } else {
+            throw new IllegalArgumentException(
+                    sm.getString("wsHandshakeRequest.unknownScheme", scheme));
+        }
+        sb.append("://");
+        sb.append(request.getServerName());
+        if ((scheme.equals("http") && (port != 80))
+            || (scheme.equals("https") && (port != 443))) {
+            sb.append(':');
+            sb.append(port);
         }
+        sb.append(request.getRequestURI());
         try {
             requestUri = new URI(sb.toString());
         } catch (URISyntaxException e) {

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1600651&r1=1600650&r2=1600651&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Jun  5 13:29:07 2014
@@ -198,6 +198,16 @@
       <fix>
         Add more varied endpoints for echo testing. (remm)
       </fix>
+      <fix>
+        <bug>56573</bug>: Change the value returned by
+        <code>Session.getRequestURI()</code> from the value obtained from
+        <code>HttpServletRequest.getRequestURI()</code> to the value obtained
+        from <code>HttpServletRequest.getRequestURI()</code> with the scheme
+        changed to ws or wss as appropriate. Note that the WebSocket Expert
+        Group is expected to clarify the expected behaviour for
+        <code>Session.getRequestURI()</code> which may result in further
+        changes. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Other">



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