// Path: src/main/java/com/taskadapter/redmineapi/RedmineException.java
// public class RedmineException extends Exception {
// 	private static final long serialVersionUID = -1592189045756043062L;
// 
// 	public RedmineException() {
//     }
// 
//     public RedmineException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public RedmineException(String message) {
//         super(message);
//     }
// 
//     public RedmineException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: src/main/java/com/taskadapter/redmineapi/RedmineFormatException.java
// public class RedmineFormatException extends RedmineCommunicationException {
// 	private static final long serialVersionUID = 4024202727798727085L;
// 
// 	public RedmineFormatException(String message) {
// 		super(message);
// 	}
// 
// 	public RedmineFormatException(Throwable cause) {
//         super(cause);
//     }
// 
// 	public RedmineFormatException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// }
// 
// Path: src/main/java/com/taskadapter/redmineapi/RedmineTransportException.java
// public class RedmineTransportException extends RedmineCommunicationException {
// 	private static final long serialVersionUID = 3463778589975943695L;
// 
// 	public RedmineTransportException(Throwable cause) {
//         super(cause);
//     }
// 
// 	public RedmineTransportException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public RedmineTransportException(String message) {
// 		super(message);
// 	}
// 
// }


import com.taskadapter.redmineapi.RedmineException;
import com.taskadapter.redmineapi.RedmineFormatException;
import com.taskadapter.redmineapi.RedmineTransportException;
import org.apache.http.*;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
package com.taskadapter.redmineapi.internal.comm;



public class BaseCommunicator implements Communicator<HttpResponse> {
	private final Logger logger = LoggerFactory.getLogger(BaseCommunicator.class);

	private final HttpClient client;

    public BaseCommunicator(HttpClient client) {
        this.client = client;
    }

	// TODO lots of usages process 404 code themselves, but some don't.
	// check if we can process 404 code in this method instead of forcing
	// clients to deal with it.

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.taskadapter.redmineapi.internal.comm.Communicator#sendRequest(org.apache.http
	 * .HttpRequest)
	 */
	@Override
	public <R> R sendRequest(HttpRequest request,
			ContentHandler<HttpResponse, R> handler) throws RedmineException {
		logger.debug(request.getRequestLine().toString());

		request.addHeader("Accept-Encoding", "gzip");
		try {
			final HttpResponse httpResponse = client
					.execute((HttpUriRequest) request);
			try {
				return handler.processContent(httpResponse);
			} finally {
				EntityUtils.consume(httpResponse.getEntity());
			}
		} catch (ClientProtocolException e1) {
			throw new RedmineFormatException(e1);
		} catch (IOException e1) {
			throw new RedmineTransportException("Cannot fetch data from "
					+ getMessageURI(request) + " : "
// Path: src/main/java/com/taskadapter/redmineapi/RedmineException.java
// public class RedmineException extends Exception {
// 	private static final long serialVersionUID = -1592189045756043062L;
// 
// 	public RedmineException() {
//     }
// 
//     public RedmineException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public RedmineException(String message) {
//         super(message);
//     }
// 
//     public RedmineException(Throwable cause) {
//         super(cause);
//     }
// }
// 
// Path: src/main/java/com/taskadapter/redmineapi/RedmineFormatException.java
// public class RedmineFormatException extends RedmineCommunicationException {
// 	private static final long serialVersionUID = 4024202727798727085L;
// 
// 	public RedmineFormatException(String message) {
// 		super(message);
// 	}
// 
// 	public RedmineFormatException(Throwable cause) {
//         super(cause);
//     }
// 
// 	public RedmineFormatException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// }
// 
// Path: src/main/java/com/taskadapter/redmineapi/RedmineTransportException.java
// public class RedmineTransportException extends RedmineCommunicationException {
// 	private static final long serialVersionUID = 3463778589975943695L;
// 
// 	public RedmineTransportException(Throwable cause) {
//         super(cause);
//     }
// 
// 	public RedmineTransportException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public RedmineTransportException(String message) {
// 		super(message);
// 	}
// 
// }


// Path: src/main/java/com/taskadapter/redmineapi/internal/comm/BaseCommunicator.java
import com.taskadapter.redmineapi.RedmineException;
import com.taskadapter.redmineapi.RedmineFormatException;
import com.taskadapter.redmineapi.RedmineTransportException;
import org.apache.http.*;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;

package com.taskadapter.redmineapi.internal.comm;



public class BaseCommunicator implements Communicator<HttpResponse> {
	private final Logger logger = LoggerFactory.getLogger(BaseCommunicator.class);

	private final HttpClient client;

    public BaseCommunicator(HttpClient client) {
        this.client = client;
    }

	// TODO lots of usages process 404 code themselves, but some don't.
	// check if we can process 404 code in this method instead of forcing
	// clients to deal with it.

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.taskadapter.redmineapi.internal.comm.Communicator#sendRequest(org.apache.http
	 * .HttpRequest)
	 */
	@Override
	public <R> R sendRequest(HttpRequest request,
			ContentHandler<HttpResponse, R> handler) throws RedmineException {
		logger.debug(request.getRequestLine().toString());

		request.addHeader("Accept-Encoding", "gzip");
		try {
			final HttpResponse httpResponse = client
					.execute((HttpUriRequest) request);
			try {
				return handler.processContent(httpResponse);
			} finally {
				EntityUtils.consume(httpResponse.getEntity());
			}
		} catch (ClientProtocolException e1) {
			throw new RedmineFormatException(e1);
		} catch (IOException e1) {
			throw new RedmineTransportException("Cannot fetch data from "
					+ getMessageURI(request) + " : "
							+ e1.toString(), e1);