// fill in the login form and submit it
PostMethod postMethod = new PostMethod(this.testAppBaseURL + "j_security_check");
postMethod.addRequestHeader("Referer", this.testAppBaseURL + "restricted/login.html");
postMethod.addParameter("j_username", "jduke");
postMethod.addParameter("j_password", "theduke");
Header location = null;
try
{
int responseCode = this.httpClient.executeMethod(postMethod.getHostConfiguration(), postMethod, state);
log.debug("responseCode=" + responseCode + ", response=" + postMethod.getStatusText());
// check the response code received and the presence of a location header in the response
assertTrue("Unexpected response code received: " + responseCode,
responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
location = postMethod.getResponseHeader("Location");
assertNotNull("Location header not found in response", location);
}
finally
{
postMethod.releaseConnection();
}
// follow the redirect as defined by the location header
String indexURI = location.getValue();
getMethod = new GetMethod(indexURI);
try
{
int responseCode = this.httpClient.executeMethod(getMethod.getHostConfiguration(), getMethod, state);
log.debug("responseCode=" + responseCode + ", response=" + getMethod.getStatusText());