Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2013-09-06 20:47:49 +0000
committerJoakim Erdfelt2013-09-06 20:47:49 +0000
commiteeb8a51c889b2e8b1d948a4e1ac91cf46f862db8 (patch)
tree0c63505288e4710385db81cb57c01ba79d3a74d0
parent50d98ab52773f5f1a060a811f9f6ac540d61ac16 (diff)
downloadorg.eclipse.jetty.project-eeb8a51c889b2e8b1d948a4e1ac91cf46f862db8.tar.gz
org.eclipse.jetty.project-eeb8a51c889b2e8b1d948a4e1ac91cf46f862db8.tar.xz
org.eclipse.jetty.project-eeb8a51c889b2e8b1d948a4e1ac91cf46f862db8.zip
416764 - WebSocket / Jsr Session.getRequestURI() is missing scheme + host + port + query parameters
+ Adding test cases to verify behavior.
-rw-r--r--jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionInfoSocket.java17
-rw-r--r--jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionTest.java35
2 files changed, 45 insertions, 7 deletions
diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionInfoSocket.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionInfoSocket.java
index cb73a0687e..3ad75a55f2 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionInfoSocket.java
+++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionInfoSocket.java
@@ -18,6 +18,7 @@
package org.eclipse.jetty.websocket.jsr356.server;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -60,6 +61,22 @@ public class SessionInfoSocket
return ret.toString();
}
+ if ("requestUri".equalsIgnoreCase(message))
+ {
+ StringBuilder ret = new StringBuilder();
+ ret.append("requestUri=");
+ URI uri = session.getRequestURI();
+ if (uri == null)
+ {
+ ret.append("=<null>");
+ }
+ else
+ {
+ ret.append(uri.toASCIIString());
+ }
+ return ret.toString();
+ }
+
// simple echo
return "echo:'" + message + "'";
}
diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionTest.java
index ba67a6eb47..b084d16a20 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionTest.java
+++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/SessionTest.java
@@ -59,7 +59,7 @@ public class SessionTest
server.stop();
}
- private void assertPathParams(String requestPath, String expectedResponse) throws Exception
+ private void assertResponse(String requestPath, String requestMessage, String expectedResponse) throws Exception
{
WebSocketClient client = new WebSocketClient();
try
@@ -69,7 +69,7 @@ public class SessionTest
Future<Session> future = client.connect(clientEcho,serverUri.resolve(requestPath));
// wait for connect
future.get(1,TimeUnit.SECONDS);
- clientEcho.sendMessage("pathParams");
+ clientEcho.sendMessage(requestMessage);
Queue<String> msgs = clientEcho.awaitMessages(1);
Assert.assertThat("Expected message",msgs.poll(),is(expectedResponse));
}
@@ -82,24 +82,45 @@ public class SessionTest
@Test
public void testPathParams_Empty() throws Exception
{
- assertPathParams("info/","pathParams[0]");
+ assertResponse("info/","pathParams","pathParams[0]");
}
@Test
public void testPathParams_Single() throws Exception
{
- assertPathParams("info/apple/","pathParams[1]: 'a'=apple");
+ assertResponse("info/apple/","pathParams","pathParams[1]: 'a'=apple");
}
@Test
public void testPathParams_Double() throws Exception
{
- assertPathParams("info/apple/pear/","pathParams[2]: 'a'=apple: 'b'=pear");
+ assertResponse("info/apple/pear/","pathParams","pathParams[2]: 'a'=apple: 'b'=pear");
}
-
+
@Test
public void testPathParams_Triple() throws Exception
{
- assertPathParams("info/apple/pear/cherry/","pathParams[3]: 'a'=apple: 'b'=pear: 'c'=cherry");
+ assertResponse("info/apple/pear/cherry/","pathParams","pathParams[3]: 'a'=apple: 'b'=pear: 'c'=cherry");
+ }
+
+ @Test
+ public void testRequestUri_Basic() throws Exception
+ {
+ URI expectedUri = serverUri.resolve("info/");
+ assertResponse("info/","requestUri","requestUri=" + expectedUri.toASCIIString());
+ }
+
+ @Test
+ public void testRequestUri_WithPathParam() throws Exception
+ {
+ URI expectedUri = serverUri.resolve("info/apple/banana/");
+ assertResponse("info/apple/banana/","requestUri","requestUri=" + expectedUri.toASCIIString());
+ }
+
+ @Test
+ public void testRequestUri_WithPathParam_WithQuery() throws Exception
+ {
+ URI expectedUri = serverUri.resolve("info/apple/banana/?fruit=fresh&store=grandmasfarm");
+ assertResponse("info/apple/banana/?fruit=fresh&store=grandmasfarm","requestUri","requestUri=" + expectedUri.toASCIIString());
}
}

Back to the top