client.start();
try
{
// Perform one request to server1 to create a session
int value = 1;
ContentExchange exchange1 = new ContentExchange(true);
exchange1.setMethod(HttpMethods.POST);
exchange1.setURL("http://localhost:" + port1 + contextPath + servletMapping + "?action=set&value=" + value);
client.send(exchange1);
exchange1.waitForDone();
assert exchange1.getResponseStatus() == HttpServletResponse.SC_OK : exchange1.getResponseStatus();
String sessionCookie = exchange1.getResponseFields().getStringField("Set-Cookie");
System.out.println("sessionCookie = " + sessionCookie);
// Perform a request to server2 using the session cookie from the previous request
// This should migrate the session from server1 to server2.
ContentExchange exchange2 = new ContentExchange(true);
exchange2.setMethod(HttpMethods.GET);
exchange2.setURL("http://localhost:" + port2 + contextPath + servletMapping + "?action=get");
exchange2.getRequestFields().add("Cookie", sessionCookie);
client.send(exchange2);
exchange2.waitForDone();
assert exchange2.getResponseStatus() == HttpServletResponse.SC_OK;
String response = exchange2.getResponseContent();
assert response.trim().equals(String.valueOf(value));
}
finally
{
client.stop();