1 package org.jahia.clipbuilder.html.web.http; 2 3 import org.org.apache.commons.httpclient.methods.*; 4 import org.org.apache.commons.httpclient.params.*; 5 import org.org.apache.commons.httpclient.*; 6 import java.io.*; 7 8 13 public abstract class SimpleHttpSecureClient { 14 private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(SimpleHttpSecureClient.class); 15 16 17 24 public static String getContentAsString(String url) throws Exception { 25 HttpClient client = new HttpClient(); 26 27 GetMethod method = new GetMethod(url); 29 30 method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); 32 String content = ""; 33 34 int statusCode = client.executeMethod(method); 36 37 if (statusCode != HttpStatus.SC_OK) { 38 logger.error("[ Method failed: " + method.getStatusLine() + " ]"); 39 } 40 41 byte[] responseBody = method.getResponseBody(); 43 44 content = new String (responseBody); 47 48 method.releaseConnection(); 50 return content; 51 } 52 53 } 54 | Popular Tags |