479584 - WS Session does not contain UpgradeRequest information in WebSocketAdapter.onWebSocketConnect callback

+ Adding missing testcase
+ Adding missing request information
This commit is contained in:
Joakim Erdfelt 2015-10-12 11:19:50 -07:00
parent ccbd626cb2
commit e6ffa35b2c
3 changed files with 27 additions and 0 deletions

View File

@ -315,6 +315,7 @@ public class UpgradeConnection extends AbstractConnection implements Connection.
SessionFactory sessionFactory = connectPromise.getClient().getSessionFactory();
WebSocketSession session = sessionFactory.createSession(request.getRequestURI(),websocket,connection);
session.setPolicy(policy);
session.setUpgradeRequest(request);
session.setUpgradeResponse(response);
connection.addListener(session);
connectPromise.setSession(session);

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.websocket.client;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.io.IOException;
import java.net.ConnectException;
@ -110,6 +111,25 @@ public class ClientConnectTest
server.stop();
}
@Test
public void testUpgradeRequest() throws Exception
{
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(wsocket,wsUri);
IBlockheadServerConnection connection = server.accept();
connection.upgrade();
Session sess = future.get(500,TimeUnit.MILLISECONDS);
sess.close();
assertThat("Connect.UpgradeRequest", wsocket.connectUpgradeRequest, notNullValue());
assertThat("Connect.UpgradeResponse", wsocket.connectUpgradeResponse, notNullValue());
}
@Test
public void testBadHandshake() throws Exception
{

View File

@ -30,6 +30,8 @@ import org.eclipse.jetty.toolchain.test.EventQueue;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.junit.Assert;
@ -42,6 +44,8 @@ public class JettyTrackingSocket extends WebSocketAdapter
public int closeCode = -1;
public Exchanger<String> messageExchanger;
public UpgradeRequest connectUpgradeRequest;
public UpgradeResponse connectUpgradeResponse;
public StringBuilder closeMessage = new StringBuilder();
public CountDownLatch openLatch = new CountDownLatch(1);
public CountDownLatch closeLatch = new CountDownLatch(1);
@ -124,6 +128,8 @@ public class JettyTrackingSocket extends WebSocketAdapter
public void onWebSocketConnect(Session session)
{
super.onWebSocketConnect(session);
connectUpgradeRequest = session.getUpgradeRequest();
connectUpgradeResponse = session.getUpgradeResponse();
openLatch.countDown();
}