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:58:00 UTC

svn commit: r1600663 - in /tomcat/trunk: java/org/apache/tomcat/websocket/server/ test/org/apache/tomcat/websocket/server/ webapps/docs/

Author: markt
Date: Thu Jun  5 13:58:00 2014
New Revision: 1600663

URL: http://svn.apache.org/r1600663
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56573
Restore query string.
Add test cases.

Added:
    tomcat/trunk/test/org/apache/tomcat/websocket/server/TestWsHandshakeRequest.java   (with props)
    tomcat/trunk/test/org/apache/tomcat/websocket/server/TesterUriServer.java   (with props)
Modified:
    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/WsHandshakeRequest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java?rev=1600663&r1=1600662&r2=1600663&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:58:00 2014
@@ -81,6 +81,11 @@ public class WsHandshakeRequest implemen
             sb.append(port);
         }
         sb.append(request.getRequestURI());
+        if (queryString != null) {
+            sb.append('?');
+            sb.append(queryString);
+        }
+
         try {
             requestUri = new URI(sb.toString());
         } catch (URISyntaxException e) {

Added: tomcat/trunk/test/org/apache/tomcat/websocket/server/TestWsHandshakeRequest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/server/TestWsHandshakeRequest.java?rev=1600663&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/server/TestWsHandshakeRequest.java (added)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/server/TestWsHandshakeRequest.java Thu Jun  5 13:58:00 2014
@@ -0,0 +1,89 @@
+/*
+ * 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.server;
+
+import java.net.URI;
+import java.util.Queue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.websocket.ClientEndpointConfig;
+import javax.websocket.ContainerProvider;
+import javax.websocket.Session;
+import javax.websocket.WebSocketContainer;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.servlets.DefaultServlet;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.websocket.TesterMessageCountClient.BasicText;
+import org.apache.tomcat.websocket.TesterMessageCountClient.TesterProgrammaticEndpoint;
+
+public class TestWsHandshakeRequest extends TomcatBaseTest {
+
+    @Test
+    public void doTestgetRequestUriWithQueryString() throws Exception {
+        doTestgetRequestUri(true);
+    }
+
+    @Test
+    public void doTestgetRequestUriWithoutQueryString() throws Exception {
+        doTestgetRequestUri(false);
+    }
+
+    public void doTestgetRequestUri(boolean withQueryString) throws Exception {
+
+        Tomcat tomcat = getTomcatInstance();
+        // Must have a real docBase - just use temp
+        Context ctx = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
+        ctx.addApplicationListener(TesterUriServer.Config.class.getName());
+        Tomcat.addServlet(ctx, "default", new DefaultServlet());
+        ctx.addServletMapping("/", "default");
+
+        tomcat.start();
+
+        WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer();
+        ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build();
+        String target = "ws://localhost:" + getPort() + TesterUriServer.PATH;
+        if (withQueryString) {
+            target += "?a=b";
+        }
+        URI uri = new URI(target);
+        Session wsSession = wsContainer.connectToServer(TesterProgrammaticEndpoint.class,
+                clientEndpointConfig, uri);
+
+        CountDownLatch latch = new CountDownLatch(1);
+        BasicText handler = new BasicText(latch);
+        wsSession.addMessageHandler(handler);
+        wsSession.getBasicRemote().sendText("Hello");
+
+        System.out.println("Sent Hello message, waiting for data");
+
+        // Ignore the latch result as the message count test below will tell us
+        // if the right number of messages arrived
+        handler.getLatch().await(60, TimeUnit.SECONDS);
+
+        Queue<String> messages = handler.getMessages();
+        Assert.assertEquals(1, messages.size());
+        for (String message : messages) {
+            Assert.assertEquals(uri.toString(), message);
+        }
+    }
+}

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

Added: tomcat/trunk/test/org/apache/tomcat/websocket/server/TesterUriServer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/server/TesterUriServer.java?rev=1600663&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/server/TesterUriServer.java (added)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/server/TesterUriServer.java Thu Jun  5 13:58:00 2014
@@ -0,0 +1,64 @@
+/*
+ * 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.server;
+
+import java.io.IOException;
+
+import javax.servlet.ServletContextEvent;
+import javax.websocket.DeploymentException;
+import javax.websocket.OnMessage;
+import javax.websocket.Session;
+import javax.websocket.server.ServerContainer;
+import javax.websocket.server.ServerEndpoint;
+
+public class TesterUriServer {
+
+    public static final String PATH = "/uri";
+
+    public static class Config extends WsContextListener {
+
+        @Override
+        public void contextInitialized(ServletContextEvent sce) {
+            super.contextInitialized(sce);
+            ServerContainer sc =
+                    (ServerContainer) sce.getServletContext().getAttribute(
+                            Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
+            try {
+                sc.addEndpoint(Uri.class);
+            } catch (DeploymentException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+    }
+
+    @ServerEndpoint(PATH)
+    public static class Uri {
+
+        @OnMessage
+        public void sendUri(Session session, @SuppressWarnings("unused") String message) {
+            try {
+                session.getBasicRemote().sendText(session.getRequestURI().toString());
+            } catch (IOException e) {
+                try {
+                    session.close();
+                } catch (IOException e1) {
+                    // Ignore
+                }
+            }
+        }
+    }
+}

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

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1600663&r1=1600662&r2=1600663&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Jun  5 13:58:00 2014
@@ -201,12 +201,12 @@
       <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)
+        <code>HttpServletRequest.getRequestURI()</code> plus query string to the
+        value obtained from <code>HttpServletRequest.getRequestURI()</code> plus
+        query string 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>



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