Author: markt
Date: Thu Jun  5 13:34:39 2014
New Revision: 1600653

URL: http://svn.apache.org/r1600653
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/tc7.0.x/trunk/   (props changed)
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

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

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties?rev=1600653&r1=1600652&r2=1600653&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
 Thu Jun  5 13:34:39 2014
@@ -31,6 +31,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/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java?rev=1600653&r1=1600652&r2=1600653&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java
 Thu Jun  5 13:34:39 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/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1600653&r1=1600652&r2=1600653&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Jun  5 13:34:39 2014
@@ -106,6 +106,20 @@
       </fix>
     </changelog>
   </subsection>
+  <subsection name="WebSocket">
+    <changelog>
+      <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>
 </section>
 <section name="Tomcat 7.0.54 (violetagg)" rtext="released 2014-05-22">
   <subsection name="Catalina">



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

Reply via email to