410386 - WebSocket Session.getUpgradeRequest().getRequestURI() returns bad URI on server side

+ Prior commit fixed this
 + Adding test to prevent regression in the future
This commit is contained in:
Joakim Erdfelt 2013-06-10 14:20:14 -07:00
parent e61c161ebd
commit ae9a776d06
2 changed files with 41 additions and 7 deletions

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.server;
import static org.hamcrest.Matchers.*;
import java.net.URI;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@ -69,8 +70,6 @@ public class WebSocketOverSSLTest
// wait for connect
Session session = fut.get(1,TimeUnit.SECONDS);
// Ask server socket
// Generate text frame
String msg = "this is an echo ... cho ... ho ... o";
session.getRemote().sendString(msg);
@ -107,8 +106,6 @@ public class WebSocketOverSSLTest
// wait for connect
Session session = fut.get(1,TimeUnit.SECONDS);
// Ask server socket
// Generate text frame
session.getRemote().sendString("session.isSecure");
@ -125,4 +122,41 @@ public class WebSocketOverSSLTest
client.stop();
}
}
/**
* Test that server session.upgradeRequest.requestURI reports correctly
*/
@Test
public void testServerSessionRequestURI() throws Exception
{
Assert.assertThat("server scheme",server.getServerUri().getScheme(),is("wss"));
WebSocketClient client = new WebSocketClient(server.getSslContextFactory());
try
{
client.start();
CaptureSocket clientSocket = new CaptureSocket();
URI requestUri = server.getServerUri().resolve("/deep?a=b");
Future<Session> fut = client.connect(clientSocket,requestUri);
// wait for connect
Session session = fut.get(1,TimeUnit.SECONDS);
// Generate text frame
session.getRemote().sendString("session.upgradeRequest.requestURI");
// Read frame (hopefully text frame)
clientSocket.messages.awaitEventCount(1,500,TimeUnit.MILLISECONDS);
EventQueue<String> captured = clientSocket.messages;
String expected = String.format("session.upgradeRequest.requestURI=%s",requestUri.toASCIIString());
Assert.assertThat("session.upgradeRequest.requestURI",captured.poll(),is(expected));
// Shutdown the socket
clientSocket.close();
}
finally
{
client.stop();
}
}
}

View File

@ -88,10 +88,10 @@ public class SessionSocket
return;
}
if ("getRequestURI".equals(message))
if ("session.upgradeRequest.requestURI".equals(message))
{
String requestURI = session.getUpgradeRequest().getRequestURI().toASCIIString();
session.getRemote().sendStringByFuture(requestURI);
String response = String.format("session.upgradeRequest.requestURI=%s",session.getUpgradeRequest().getRequestURI().toASCIIString());
session.getRemote().sendStringByFuture(response);
return;
}