package at.ac.tuwien.dst.mms.jira.rest;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.List;

/**
 * A simple HTTP client for sending REST requests.
 */
public class RestClient {
	private static Logger LOG = LoggerFactory.getLogger(RestClient.class);

	/**
	 * Sends a GET request.
	 *
	 * @param uri the URL for the request to be sent to
	 * @return
	 * @throws IOException
	 */
	public static InputStream sendGet(URI uri) throws IOException {
		HttpClient client = HttpClientBuilder.create().build();
		HttpGet request = new HttpGet(uri);
		HttpResponse response = client.execute(request);

		return response.getEntity().getContent();
	}

	/**
	 * Sends a POST request for a generic list.
	 *
	 * @param uri
	 * @param requestEntity
	 * @param <T>
	 * @throws IOException
	 */
	public static <T> void sendPost(URI uri, List<T> requestEntity) throws IOException {
		Client c = Client.create();
		WebResource resource = c.resource(uri);

		resource.post(requestEntity);
	}

	/**
	 * Sends a POST request for a generic iterable.
	 *
	 * @param uri
	 * @param requestEntity
	 * @param <T>
	 * @throws IOException
	 */
	public static <T> void sendPost(URI uri, Iterable<T> requestEntity) throws IOException {
		Client c = Client.create();
		WebResource resource = c.resource(uri);

		resource.post(requestEntity);
	}
}

@@ -415,16 +415,53 @@
 Stream;%0A
+import java.io.UncheckedIOException;%0A
 import j
@@ -758,32 +758,41 @@
 urn%0A%09 * @throws 
+Unchecked
 IOException%0A%09 */
@@ -836,37 +836,27 @@
 RI uri) 
-throws IOException
+%7B%0A%09%09try
  %7B%0A
+%09
 %09%09HttpCl
@@ -903,24 +903,25 @@
 .build();%0A%09%09
+%09
 HttpGet requ
@@ -948,33 +948,26 @@
 i);%0A
-%09%09HttpResponse response =
+            return
  cli
@@ -990,28 +990,8 @@
 est)
-;%0A%0A%09%09return response
 .get
@@ -1013,16 +1013,90 @@
 tent();%0A
+%09%09%7D catch ( IOException e ) %7B%0A%09%09%09throw new UncheckedIOException( e );%0A%09%09%7D%0A
 %09%7D%0A%0A%09/**
@@ -1204,32 +1204,8 @@
 %3CT%3E%0A
-%09 * @throws IOException%0A
 %09 */
@@ -1269,35 +1269,16 @@
 tEntity)
- throws IOException
  %7B%0A%09%09Cli
@@ -1498,32 +1498,8 @@
 %3CT%3E%0A
-%09 * @throws IOException%0A
 %09 */
@@ -1571,27 +1571,8 @@
 ity)
- throws IOException
  %7B%0A%09

Modify exception handling.