ConnectionHelperFactory.getConnectionHelper(resource,
theConfiguration);
// Make the connection using a default web request.
HttpURLConnection connection = helper.connect(
new WebRequest((WebConfiguration) theConfiguration),
theConfiguration);
// Clean any existing session ID.
sessionId = null;
// Check (possible multiple) cookies for a JSESSIONID.
int i = 1;
String key = connection.getHeaderFieldKey(i);
while (key != null)
{
if (key.equalsIgnoreCase("set-cookie"))
{
// Cookie is in the form:
// "NAME=VALUE; expires=DATE; path=PATH;
// domain=DOMAIN_NAME; secure"
// The only thing we care about is finding a cookie with
// the name "JSESSIONID" and caching the value.
String cookiestr = connection.getHeaderField(i);
String nameValue = cookiestr.substring(0,
cookiestr.indexOf(";"));
int equalsChar = nameValue.indexOf("=");
String name = nameValue.substring(0, equalsChar);
if (name.equalsIgnoreCase("JSESSIONID"))
{
// We must set a cookie with the exact same name as the
// one given to us, so to preserve any capitalization
// issues, cache the exact cookie name.
sessionIdCookieName = name;
sessionId = nameValue.substring(equalsChar + 1);
break;
}
}
key = connection.getHeaderFieldKey(++i);
}
// Create a helper that will connect to the security check URL.
helper = ConnectionHelperFactory.getConnectionHelper(
getSecurityCheckURL(theConfiguration).toString(),
(WebConfiguration) theConfiguration);
// Configure a web request with the JSESSIONID cookie,
// the username and the password.
WebRequest request = getSecurityRequest();
request.setConfiguration(theConfiguration);
request.addCookie(sessionIdCookieName, sessionId);
request.addParameter("j_username", getName(),
WebRequest.POST_METHOD);
request.addParameter("j_password", getPassword(),
WebRequest.POST_METHOD);
// Make the connection using the configured web request.
connection = helper.connect(request, theConfiguration);