Methods Summary |
---|
public static void | main(java.lang.String[] args)
// Configure Logging
System.setProperty("org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime",
"true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire",
"debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient",
"debug");
ConditionalGetExample example = new ConditionalGetExample();
example.start();
|
private void | processResults(org.apache.commons.httpclient.HttpMethod method)
if(method.getStatusCode() == HttpStatus.SC_NOT_MODIFIED ) {
System.out.println( "Content not modified since last request" );
} else {
System.out.println( "Get Method retrieved content." );
entityTag = retrieveHeader( method, "ETag" );
lastModified = retrieveHeader( method, "Last-Modified" );
System.out.println( "Entity Tag: " + entityTag );
System.out.println( "Last Modified: " + lastModified );
}
|
private java.lang.String | retrieveHeader(org.apache.commons.httpclient.HttpMethod method, java.lang.String name)
HeaderElement[] header = method.getResponseHeader(name).getElements();
String value = "";
if(header.length > 0) {
value = header[0].getName();
}
return value;
|
private void | setHeaders(org.apache.commons.httpclient.HttpMethod method)
method.setRequestHeader(new Header("If-None-Match", entityTag ) );
method.setRequestHeader(new Header("If-Modified-Since", lastModified ) );
|
public void | start()
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod("http://www.apache.org");
for( int i = 0; i < 3; i++ ) {
setHeaders(method);
client.executeMethod(method);
processResults(method);
method.releaseConnection();
method.recycle();
}
|