update to latest http-client api

This commit is contained in:
Jan Bartel 2012-10-27 17:56:25 +11:00
parent 1ee6fe4cba
commit 0473a8003b
20 changed files with 102 additions and 135 deletions

View File

@ -103,14 +103,14 @@ public class MaxInactiveMigrationTest
request.header("Cookie", sessionCookie);
Future<ContentResponse> future = request.send();
ContentResponse response = future.get();
assertEquals(HttpServletResponse.SC_OK, response.status());
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
sessionCookie = response.headers().getStringField("Set-Cookie");
sessionCookie = response.getHeaders().getStringField("Set-Cookie");
assertTrue( sessionCookie != null );
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
return response.contentAsString();
return response.getContentAsString();
}

View File

@ -42,7 +42,6 @@ import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.nosql.NoSqlSession;
import org.eclipse.jetty.server.session.AbstractSessionValueSavingTest;
import org.eclipse.jetty.server.session.AbstractTestServer;
import org.junit.Ignore;
import org.junit.Test;
public class SessionSavingValueTest extends AbstractSessionValueSavingTest
@ -112,14 +111,14 @@ public class SessionSavingValueTest extends AbstractSessionValueSavingTest
Request request = client.newRequest("http://localhost:" + port1 + contextPath + servletMapping + "?action=init");
Future<ContentResponse> future = request.send();
ContentResponse response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
String[] sessionTestResponse = response.contentAsString().split("/");
String[] sessionTestResponse = response.getContentAsString().split("/");
assertTrue(Long.parseLong(sessionTestValue[0]) < Long.parseLong(sessionTestResponse[0]));
sessionTestValue = sessionTestResponse;
String sessionCookie = response.headers().getStringField("Set-Cookie");
String sessionCookie = response.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=","$1\\$Path=");
@ -138,16 +137,16 @@ public class SessionSavingValueTest extends AbstractSessionValueSavingTest
Future<ContentResponse> future2 = request2.send();
ContentResponse response2 = future2.get();
assertEquals(HttpServletResponse.SC_OK,response2.status());
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
sessionTestResponse = response2.contentAsString().split("/");
sessionTestResponse = response2.getContentAsString().split("/");
assertTrue(Long.parseLong(sessionTestValue[0]) < Long.parseLong(sessionTestResponse[0]));
assertTrue(Long.parseLong(sessionTestValue[1]) < Long.parseLong(sessionTestResponse[1]));
sessionTestValue = sessionTestResponse;
String setCookie = response2.headers().getStringField("Set-Cookie");
String setCookie = response2.getHeaders().getStringField("Set-Cookie");
if (setCookie != null)
sessionCookie = setCookie.replaceFirst("(\\W)(P|p)ath=","$1\\$Path=");

View File

@ -32,9 +32,7 @@ import javax.servlet.http.HttpSession;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Destination;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.Test;
@ -76,8 +74,8 @@ public abstract class AbstractClientCrossContextSessionTest
Future<ContentResponse> future = client.GET("http://localhost:" + port + contextA + servletMapping);
ContentResponse response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
String sessionCookie = response.headers().getStringField("Set-Cookie");
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
String sessionCookie = response.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -87,7 +85,7 @@ public abstract class AbstractClientCrossContextSessionTest
request.header("Cookie", sessionCookie);
future = request.send();
ContentResponse responseB = future.get();
assertEquals(HttpServletResponse.SC_OK,responseB.status());
assertEquals(HttpServletResponse.SC_OK,responseB.getStatus());
assertEquals(servletA.sessionId, servletB.sessionId);
}
finally

View File

@ -33,9 +33,7 @@ import javax.servlet.http.HttpSession;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Destination;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpCookie;
import org.junit.Test;
@ -67,13 +65,13 @@ public abstract class AbstractImmortalSessionTest
int value = 42;
Future<ContentResponse> future = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=set&value=" + value);
ContentResponse response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
String sessionCookie = response.headers().getStringField("Set-Cookie");
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
String sessionCookie = response.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
String resp = response.contentAsString();
String resp = response.getContentAsString();
assertEquals(resp.trim(),String.valueOf(value));
// Let's wait for the scavenger to run, waiting 2.5 times the scavenger period
@ -84,8 +82,8 @@ public abstract class AbstractImmortalSessionTest
request.header("Cookie", sessionCookie);
future = request.send();
response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
resp = response.contentAsString();
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
resp = response.getContentAsString();
assertEquals(String.valueOf(value),resp.trim());
}
finally

View File

@ -30,7 +30,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
@ -80,8 +79,8 @@ public abstract class AbstractInvalidationSessionTest
Future<ContentResponse> future = client.GET(urls[0] + "?action=init");
ContentResponse response1 = future.get();
assertEquals(HttpServletResponse.SC_OK,response1.status());
String sessionCookie = response1.headers().getStringField("Set-Cookie");
assertEquals(HttpServletResponse.SC_OK,response1.getStatus());
String sessionCookie = response1.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -92,13 +91,13 @@ public abstract class AbstractInvalidationSessionTest
request2.header("Cookie", sessionCookie);
future = request2.send();
ContentResponse response2 = future.get();
assertEquals(HttpServletResponse.SC_OK,response2.status());
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
// Invalidate on node1
Request request1 = client.newRequest(urls[0] + "?action=invalidate");
request1.header("Cookie", sessionCookie);
future = request1.send();
assertEquals(HttpServletResponse.SC_OK, response1.status());
assertEquals(HttpServletResponse.SC_OK, response1.getStatus());
pause();
@ -107,7 +106,7 @@ public abstract class AbstractInvalidationSessionTest
request2.header("Cookie", sessionCookie);
future = request2.send();
response2 = future.get();
assertEquals(HttpServletResponse.SC_OK,response2.status());
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
}
finally
{

View File

@ -84,9 +84,9 @@ public abstract class AbstractLastAccessTimeTest
// Perform one request to server1 to create a session
Future<ContentResponse> future = client.GET("http://localhost:" + port1 + contextPath + servletMapping + "?action=init");
ContentResponse response1 = future.get();
assertEquals(HttpServletResponse.SC_OK, response1.status());
assertEquals("test", response1.contentAsString());
String sessionCookie = response1.headers().getStringField("Set-Cookie");
assertEquals(HttpServletResponse.SC_OK, response1.getStatus());
assertEquals("test", response1.getContentAsString());
String sessionCookie = response1.getHeaders().getStringField("Set-Cookie");
assertTrue( sessionCookie != null );
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -103,10 +103,10 @@ public abstract class AbstractLastAccessTimeTest
request.header("Cookie", sessionCookie);
future = request.send();
ContentResponse response2 = future.get();
assertEquals(HttpServletResponse.SC_OK , response2.status());
assertEquals("test", response2.contentAsString());
assertEquals(HttpServletResponse.SC_OK , response2.getStatus());
assertEquals("test", response2.getContentAsString());
String setCookie = response2.headers().getStringField("Set-Cookie");
String setCookie = response2.getHeaders().getStringField("Set-Cookie");
if (setCookie!=null)
sessionCookie = setCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");

View File

@ -38,9 +38,7 @@ import javax.servlet.http.HttpSession;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Destination;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpCookie;
import org.junit.Test;
@ -83,8 +81,8 @@ public abstract class AbstractLightLoadTest
Future<ContentResponse> future = client.GET( urls[0] + "?action=init" );
ContentResponse response1 = future.get();
assertEquals(HttpServletResponse.SC_OK,response1.status());
String sessionCookie = response1.headers().getStringField( "Set-Cookie" );
assertEquals(HttpServletResponse.SC_OK,response1.getStatus());
String sessionCookie = response1.getHeaders().getStringField( "Set-Cookie" );
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -119,8 +117,8 @@ public abstract class AbstractLightLoadTest
request.header("Cookie", sessionCookie);
future = request.send();
ContentResponse response2 = future.get();
assertEquals(HttpServletResponse.SC_OK,response2.status());
String response = response2.contentAsString();
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
String response = response2.getContentAsString();
System.out.println( "get = " + response );
assertEquals(response.trim(), String.valueOf( clientsCount * requestsCount ) );
}
@ -192,7 +190,7 @@ public abstract class AbstractLightLoadTest
request.header("Cookie", sessionCookie);
Future<ContentResponse> future = request.send();
ContentResponse response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
}
// Wait for all workers to be done

View File

@ -32,8 +32,6 @@ import javax.servlet.http.HttpSession;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Destination;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.SessionManager;
import org.junit.Test;
@ -87,8 +85,8 @@ public abstract class AbstractLocalSessionScavengingTest
// Create the session on node1
Future<ContentResponse> future = client.GET(urls[0] + "?action=init");
ContentResponse response1 = future.get();
assertEquals(HttpServletResponse.SC_OK,response1.status());
String sessionCookie = response1.headers().getStringField("Set-Cookie");
assertEquals(HttpServletResponse.SC_OK,response1.getStatus());
String sessionCookie = response1.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -98,7 +96,7 @@ public abstract class AbstractLocalSessionScavengingTest
request.header("Cookie", sessionCookie);
future = request.send();
ContentResponse response2 = future.get();
assertEquals(HttpServletResponse.SC_OK,response2.status());
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
// Wait for the scavenger to run on node1, waiting 2.5 times the scavenger period
@ -109,7 +107,7 @@ public abstract class AbstractLocalSessionScavengingTest
request.header("Cookie", sessionCookie);
future = request.send();
response1 = future.get();
assertEquals(HttpServletResponse.SC_OK,response1.status());
assertEquals(HttpServletResponse.SC_OK,response1.getStatus());
// Wait for the scavenger to run on node2, waiting 2 times the scavenger period
@ -121,7 +119,7 @@ public abstract class AbstractLocalSessionScavengingTest
request.header("Cookie", sessionCookie);
future = request.send();
response2 = future.get();
assertEquals(HttpServletResponse.SC_OK,response2.status());
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
}
finally
{

View File

@ -32,9 +32,7 @@ import javax.servlet.http.HttpSession;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Destination;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.junit.Test;
@ -76,8 +74,8 @@ public abstract class AbstractNewSessionTest
{
Future<ContentResponse> future = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create");
ContentResponse response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
String sessionCookie = response.headers().getStringField("Set-Cookie");
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
String sessionCookie = response.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -91,7 +89,7 @@ public abstract class AbstractNewSessionTest
request.header("Cookie", sessionCookie);
future = request.send();
response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
}
finally
{

View File

@ -33,9 +33,7 @@ import javax.servlet.http.HttpSession;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Destination;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpCookie;
import org.junit.Test;
/**
@ -77,8 +75,8 @@ public abstract class AbstractOrphanedSessionTest
// Connect to server1 to create a session and get its session cookie
Future<ContentResponse> future = client.GET("http://localhost:" + port1 + contextPath + servletMapping + "?action=init");
ContentResponse response1 = future.get();
assertEquals(HttpServletResponse.SC_OK,response1.status());
String sessionCookie = response1.headers().getStringField("Set-Cookie");
assertEquals(HttpServletResponse.SC_OK,response1.getStatus());
String sessionCookie = response1.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -93,7 +91,7 @@ public abstract class AbstractOrphanedSessionTest
request.header("Cookie", sessionCookie);
future = request.send();
ContentResponse response2 = future.get();
assertEquals(HttpServletResponse.SC_OK,response2.status());
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
}
finally
{

View File

@ -59,7 +59,7 @@ public abstract class AbstractReentrantRequestSessionTest
{
Future<ContentResponse> future = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=reenter&port=" + port + "&path=" + contextPath + servletMapping);
ContentResponse response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
}
finally
{
@ -104,7 +104,7 @@ public abstract class AbstractReentrantRequestSessionTest
{
Future<ContentResponse> future = client.GET("http://localhost:" + port + path + ";jsessionid="+session.getId()+"?action=none");
ContentResponse resp = future.get();
assertEquals(HttpServletResponse.SC_OK,resp.status());
assertEquals(HttpServletResponse.SC_OK,resp.getStatus());
assertEquals("true",session.getAttribute("reentrant"));
}
finally

View File

@ -68,8 +68,8 @@ public abstract class AbstractRemoveSessionTest
{
Future<ContentResponse> future = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create");
ContentResponse response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
String sessionCookie = response.headers().getStringField("Set-Cookie");
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
String sessionCookie = response.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -81,7 +81,7 @@ public abstract class AbstractRemoveSessionTest
request.header("Cookie", sessionCookie);
future = request.send();
response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
//ensure sessionDestroyed listener is called
assertTrue(testListener.isDestroyed());
@ -92,7 +92,7 @@ public abstract class AbstractRemoveSessionTest
request.header("Cookie", sessionCookie);
future = request.send();
response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
}
finally
{

View File

@ -68,7 +68,7 @@ public abstract class AbstractServerCrossContextSessionTest
// Perform a request, on server side a cross context dispatch will be done
Future<ContentResponse> future = client.GET("http://localhost:" + port + contextA + servletMapping);
ContentResponse response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
}
finally
{

View File

@ -82,9 +82,9 @@ public abstract class AbstractSessionCookieTest
Future<ContentResponse> future = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create");
ContentResponse response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
String sessionCookie = response.headers().getStringField("Set-Cookie");
String sessionCookie = response.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
//sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -96,13 +96,13 @@ public abstract class AbstractSessionCookieTest
future = request.send();
response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=null-cookie");
request.header("Cookie", sessionCookie);
future = request.send();
response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
}
finally
{

View File

@ -18,7 +18,11 @@
package org.eclipse.jetty.server.session;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.concurrent.Future;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@ -26,16 +30,11 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.SessionManager;
import org.eclipse.jetty.server.session.AbstractTestServer;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@ -78,18 +77,14 @@ public abstract class AbstractSessionExpiryTest
try
{
HttpClient client = new HttpClient();
client.setConnectorType(HttpClient.CONNECTOR_SOCKET);
client.start();
String url = "http://localhost:" + port1 + contextPath + servletMapping;
//make a request to set up a session on the server
ContentExchange exchange1 = new ContentExchange(true);
exchange1.setMethod(HttpMethods.GET);
exchange1.setURL(url + "?action=init");
client.send(exchange1);
exchange1.waitForDone();
assertEquals(HttpServletResponse.SC_OK,exchange1.getResponseStatus());
String sessionCookie = exchange1.getResponseFields().getStringField("Set-Cookie");
Future<ContentResponse> future = client.GET(url + "?action=init");
ContentResponse response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
String sessionCookie = response.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -102,14 +97,12 @@ public abstract class AbstractSessionExpiryTest
port1 = server1.getPort();
url = "http://localhost:" + port1 + contextPath + servletMapping;
//make another request, the session should not have expired
ContentExchange exchange2 = new ContentExchange(true);
exchange2.setMethod(HttpMethods.GET);
exchange2.setURL(url + "?action=notexpired");
exchange2.getRequestFields().add("Cookie", sessionCookie);
client.send(exchange2);
exchange2.waitForDone();
assertEquals(HttpServletResponse.SC_OK,exchange2.getResponseStatus());
//make another request, the session should not have expired
Request request = client.newRequest(url + "?action=notexpired");
request.getHeaders().add("Cookie", sessionCookie);
future = request.send();
ContentResponse response2 = future.get();
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
}
finally
@ -135,18 +128,14 @@ public abstract class AbstractSessionExpiryTest
try
{
HttpClient client = new HttpClient();
client.setConnectorType(HttpClient.CONNECTOR_SOCKET);
client.start();
String url = "http://localhost:" + port1 + contextPath + servletMapping;
//make a request to set up a session on the server
ContentExchange exchange1 = new ContentExchange(true);
exchange1.setMethod(HttpMethods.GET);
exchange1.setURL(url + "?action=init");
client.send(exchange1);
exchange1.waitForDone();
assertEquals(HttpServletResponse.SC_OK,exchange1.getResponseStatus());
String sessionCookie = exchange1.getResponseFields().getStringField("Set-Cookie");
Future<ContentResponse> future = client.GET(url + "?action=init");
ContentResponse response1 = future.get();
assertEquals(HttpServletResponse.SC_OK,response1.getStatus());
String sessionCookie = response1.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -163,13 +152,11 @@ public abstract class AbstractSessionExpiryTest
url = "http://localhost:" + port1 + contextPath + servletMapping;
//make another request, the session should have expired
ContentExchange exchange2 = new ContentExchange(true);
exchange2.setMethod(HttpMethods.GET);
exchange2.setURL(url + "?action=test");
exchange2.getRequestFields().add("Cookie", sessionCookie);
client.send(exchange2);
exchange2.waitForDone();
assertEquals(HttpServletResponse.SC_OK,exchange2.getResponseStatus());
Request request = client.newRequest(url + "?action=test");
request.getHeaders().add("Cookie", sessionCookie);
future = request.send();
ContentResponse response2 = future.get();
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
}
finally
{

View File

@ -38,9 +38,7 @@ import javax.servlet.http.HttpSessionListener;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Destination;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.Test;
@ -117,8 +115,8 @@ public abstract class AbstractSessionInvalidateAndCreateTest
// Create the session
Future<ContentResponse> future = client.GET(url + "?action=init");
ContentResponse response1 = future.get();
assertEquals(HttpServletResponse.SC_OK,response1.status());
String sessionCookie = response1.headers().getStringField("Set-Cookie");
assertEquals(HttpServletResponse.SC_OK,response1.getStatus());
String sessionCookie = response1.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -129,7 +127,7 @@ public abstract class AbstractSessionInvalidateAndCreateTest
request2.header("Cookie", sessionCookie);
future = request2.send();
ContentResponse response2 = future.get();
assertEquals(HttpServletResponse.SC_OK,response2.status());
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
// Wait for the scavenger to run, waiting 2.5 times the scavenger period
pause(scavengePeriod);

View File

@ -72,8 +72,8 @@ public abstract class AbstractSessionMigrationTest
Request request1 = client.POST("http://localhost:" + port1 + contextPath + servletMapping + "?action=set&value=" + value);
Future<ContentResponse> future = request1.send();
ContentResponse response1 = future.get();
assertEquals(HttpServletResponse.SC_OK,response1.status());
String sessionCookie = response1.headers().getStringField("Set-Cookie");
assertEquals(HttpServletResponse.SC_OK,response1.getStatus());
String sessionCookie = response1.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -84,8 +84,8 @@ public abstract class AbstractSessionMigrationTest
request2.header("Cookie", sessionCookie);
future = request2.send();
ContentResponse response2 = future.get();
assertEquals(HttpServletResponse.SC_OK,response2.status());
String response = response2.contentAsString();
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
String response = response2.getContentAsString();
assertEquals(response.trim(),String.valueOf(value)); }
finally
{

View File

@ -63,9 +63,9 @@ public abstract class AbstractSessionRenewTest
//make a request to create a session
Future<ContentResponse> future = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create");
ContentResponse response = future.get();
assertEquals(HttpServletResponse.SC_OK,response.status());
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
String sessionCookie = response.headers().getStringField("Set-Cookie");
String sessionCookie = response.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
//make a request to change the sessionid
@ -73,8 +73,8 @@ public abstract class AbstractSessionRenewTest
request.header("Cookie", sessionCookie);
future = request.send();
ContentResponse renewResponse = future.get();
assertEquals(HttpServletResponse.SC_OK,renewResponse.status());
String renewSessionCookie = renewResponse.headers().getStringField("Set-Cookie");
assertEquals(HttpServletResponse.SC_OK,renewResponse.getStatus());
String renewSessionCookie = renewResponse.getHeaders().getStringField("Set-Cookie");
assertNotNull(renewSessionCookie);
assertNotSame(sessionCookie, renewSessionCookie);
}

View File

@ -33,9 +33,7 @@ import javax.servlet.http.HttpSession;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Destination;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpCookie;
import org.junit.Test;
@ -70,12 +68,12 @@ public abstract class AbstractSessionValueSavingTest
Future<ContentResponse> future = client.GET("http://localhost:" + port1 + contextPath + servletMapping + "?action=init");
ContentResponse response1 = future.get();
assertEquals(HttpServletResponse.SC_OK, response1.status());
assertTrue(sessionTestValue < Long.parseLong(response1.contentAsString()));
assertEquals(HttpServletResponse.SC_OK, response1.getStatus());
assertTrue(sessionTestValue < Long.parseLong(response1.getContentAsString()));
sessionTestValue = Long.parseLong(response1.contentAsString());
sessionTestValue = Long.parseLong(response1.getContentAsString());
String sessionCookie = response1.headers().getStringField("Set-Cookie");
String sessionCookie = response1.getHeaders().getStringField("Set-Cookie");
assertTrue( sessionCookie != null );
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -95,11 +93,11 @@ public abstract class AbstractSessionValueSavingTest
future = request2.send();
ContentResponse response2 = future.get();
assertEquals(HttpServletResponse.SC_OK , response2.status());
assertTrue(sessionTestValue < Long.parseLong(response2.contentAsString()));
sessionTestValue = Long.parseLong(response2.contentAsString());
assertEquals(HttpServletResponse.SC_OK , response2.getStatus());
assertTrue(sessionTestValue < Long.parseLong(response2.getContentAsString()));
sessionTestValue = Long.parseLong(response2.getContentAsString());
String setCookie = response1.headers().getStringField("Set-Cookie");
String setCookie = response1.getHeaders().getStringField("Set-Cookie");
if (setCookie!=null)
sessionCookie = setCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");

View File

@ -30,9 +30,7 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Destination;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.resource.Resource;
@ -119,8 +117,8 @@ public abstract class AbstractWebAppObjectInSessionTest
Future<ContentResponse> future = request.send();
ContentResponse response = future.get();
assertEquals( HttpServletResponse.SC_OK, response.status());
String sessionCookie = response.headers().getStringField("Set-Cookie");
assertEquals( HttpServletResponse.SC_OK, response.getStatus());
String sessionCookie = response.getHeaders().getStringField("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -132,7 +130,7 @@ public abstract class AbstractWebAppObjectInSessionTest
future = request2.send();
ContentResponse response2 = future.get();
assertEquals(HttpServletResponse.SC_OK,response2.status());
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
}
finally
{