}
public static HttpMethodBase accessURL(URL url, String realm,
int expectedHttpCode, Header[] hdrs, int type)
throws Exception
{
HttpClient httpConn = new HttpClient();
HttpMethodBase request = createMethod(url, type);
int hdrCount = hdrs != null ? hdrs.length : 0;
for(int n = 0; n < hdrCount; n ++)
request.addRequestHeader(hdrs[n]);
try
{
log.debug("Connecting to: "+url);
String userInfo = url.getUserInfo();
if( userInfo != null )
{
UsernamePasswordCredentials auth = new UsernamePasswordCredentials(userInfo);
httpConn.getState().setCredentials(realm, url.getHost(), auth);
}
log.debug("RequestURI: "+request.getURI());
int responseCode = httpConn.executeMethod(request);
String response = request.getStatusText();
log.debug("responseCode="+responseCode+", response="+response);
String content = request.getResponseBodyAsString();
log.debug(content);
// Validate that we are seeing the requested response code