Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 package org.crazybob.rss; 2 3 import java.io.*; 4 import java.util.*; 5 import java.net.*; 6 7 import org.apache.commons.httpclient.*; 8 import org.apache.commons.httpclient.methods.*; 9 10 15 public class UrlLoader { 16 17 private static final int TIMEOUT = 15000; 18 19 22 public Response load(String urlString, String lastModified) 23 throws IOException { 24 HttpClient client = new HttpClient(); 25 client.setConnectionTimeout(TIMEOUT); 26 client.setTimeout(TIMEOUT); 27 GetMethod getMethod = new GetMethod(urlString); 28 if (lastModified != null) 29 getMethod.setRequestHeader( 30 new Header("If-Modified-Since", lastModified)); 31 client.executeMethod(getMethod); 32 if (getMethod.getStatusCode() == 304) { 33 Log.debug("Not modified. Skipping."); 34 return null; 35 } 36 37 Response response = new Response(); 38 response.setBody(getMethod.getResponseBodyAsString()); 39 Header lastModifiedHeader = 40 getMethod.getResponseHeader("Last-Modified"); 41 if (lastModifiedHeader != null) 42 response.setLastModified(lastModifiedHeader.getValue()); 43 return response; 44 } 45 46 public static class Response { 47 48 private String body; 49 private String lastModified; 50 51 56 public String getBody() { 57 return body; 58 } 59 60 65 public void setBody(String body) { 66 this.body = body; 67 } 68 69 74 public String getLastModified() { 75 return lastModified; 76 } 77 78 83 public void setLastModified(String lastModified) { 84 this.lastModified = lastModified; 85 } 86 } 87 } 88
| Popular Tags
|