diff --git a/src/java/main/br/ufpe/cin/groundhog/http/ParamBuilder.java b/src/java/main/br/ufpe/cin/groundhog/http/ParamBuilder.java index a063b24..f3f826b 100644 --- a/src/java/main/br/ufpe/cin/groundhog/http/ParamBuilder.java +++ b/src/java/main/br/ufpe/cin/groundhog/http/ParamBuilder.java @@ -7,19 +7,24 @@ import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.message.BasicNameValuePair; +/** + * The URL parameter builder class + * @author fjsj + * + */ public class ParamBuilder { private List params; public ParamBuilder() { - params = new ArrayList(); + this.params = new ArrayList(); } public ParamBuilder add(String name, String value) { - params.add(new BasicNameValuePair(name, value)); + this.params.add(new BasicNameValuePair(name, value)); return this; } public String build() { - return URLEncodedUtils.format(params, "UTF-8"); + return URLEncodedUtils.format(this.params, "UTF-8"); } } \ No newline at end of file diff --git a/src/java/main/br/ufpe/cin/groundhog/http/Requests.java b/src/java/main/br/ufpe/cin/groundhog/http/Requests.java index ec92674..e500fde 100644 --- a/src/java/main/br/ufpe/cin/groundhog/http/Requests.java +++ b/src/java/main/br/ufpe/cin/groundhog/http/Requests.java @@ -12,16 +12,21 @@ import com.ning.http.client.ListenableFuture; public class Requests { - private AsyncHttpClient asyncClient; public Requests() { - asyncClient = new AsyncHttpClient(); + this.asyncClient = new AsyncHttpClient(); } + /** + * Gets the response body of the given URL + * @param urlStr + * @return + * @throws IOException + */ public String get(String urlStr) throws IOException { try { - return asyncClient.prepareGet(urlStr).execute().get().getResponseBody(); + return this.asyncClient.prepareGet(urlStr).execute().get().getResponseBody(); } catch (InterruptedException e) { e.printStackTrace(); throw new HttpException(e); @@ -31,9 +36,15 @@ public String get(String urlStr) throws IOException { } } + /** + * Downloads the response body of the given URL + * @param urlStr an URL of a page whose body will be downloaded + * @return + * @throws IOException + */ public InputStream download(String urlStr) throws IOException { try { - return asyncClient.prepareGet(urlStr).setFollowRedirects(true).execute().get().getResponseBodyAsStream(); + return this.asyncClient.prepareGet(urlStr).setFollowRedirects(true).execute().get().getResponseBodyAsStream(); } catch (InterruptedException e) { e.printStackTrace(); throw new HttpException(e); @@ -59,7 +70,7 @@ public String encodeURL(String s) { /** * * @param s a String representing an URL - * @return an UTF-8 decoded String derivated from the given URL + * @return an UTF-8 decoded String derived from the given URL */ public String decodeURL(String s) { try { @@ -69,9 +80,11 @@ public String decodeURL(String s) { throw new HttpException(e); } } - + + /** + * Closes the connection + */ public void close() { - asyncClient.close(); + this.asyncClient.close(); } - } \ No newline at end of file