// Path: src/com/textrazor/AnalysisException.java
// public class AnalysisException extends Exception {
// 	private static final long serialVersionUID = 9063173251339905559L;
// 	
// 	private int responseCode;
//     private String responseBody;
// 
//     public AnalysisException(int responseCode, String responseBody) {
//         this.responseBody = responseBody;
//         this.responseCode = responseCode;
//     }
// 
//     @Override
//     public String getMessage() {
//         return String.format("TextRazor returned HTTP Code %d with response: %s", responseCode, responseBody);
//     }
// 
//     public String getResponseBody() {
//         return responseBody;
//     }
//     
//     public int getResponseCode() {
//         return responseCode;
//     }
// }
// 
// Path: src/com/textrazor/NetworkException.java
// public class NetworkException extends IOException {
//     
// 	private static final long serialVersionUID = -821976320048704953L;
// 
// 	public NetworkException(String message, Throwable cause) {
//         super(message);
//         initCause(cause);
//     }
// }


import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
import java.net.URLEncoder;
import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.textrazor.AnalysisException;
import com.textrazor.NetworkException;
			
			// Note - removing this is handy for debugging holes in the library, but for production
			// use we don't want to fail on new properties to allow forward compatibility.
			mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
			
			try {
				return mapper.readValue(sbuff.toString(), responseClass);
			} catch (IOException e) {
				 e.printStackTrace();
				throw new RuntimeException("Unable to decode TextRazor response: ");
			}
		}
		catch (IOException e) {
			throw new NetworkException("Network Error when connecting to TextRazor", e);
		}
	}
	
	protected <RequestType, ResponseType> ResponseType sendRequest(
			String path, 
			RequestType requestBody,
			ContentType contentType,
			String method, 
			Class<ResponseType> responseClass) throws AnalysisException, NetworkException {
		ObjectMapper mapper = new ObjectMapper();

		// Optional params are represented by "null" in the build objects.
		// We don't need to actually send a null to the server.
		mapper.setSerializationInclusion(Include.NON_NULL);
		
		try {
// Path: src/com/textrazor/AnalysisException.java
// public class AnalysisException extends Exception {
// 	private static final long serialVersionUID = 9063173251339905559L;
// 	
// 	private int responseCode;
//     private String responseBody;
// 
//     public AnalysisException(int responseCode, String responseBody) {
//         this.responseBody = responseBody;
//         this.responseCode = responseCode;
//     }
// 
//     @Override
//     public String getMessage() {
//         return String.format("TextRazor returned HTTP Code %d with response: %s", responseCode, responseBody);
//     }
// 
//     public String getResponseBody() {
//         return responseBody;
//     }
//     
//     public int getResponseCode() {
//         return responseCode;
//     }
// }
// 
// Path: src/com/textrazor/NetworkException.java
// public class NetworkException extends IOException {
//     
// 	private static final long serialVersionUID = -821976320048704953L;
// 
// 	public NetworkException(String message, Throwable cause) {
//         super(message);
//         initCause(cause);
//     }
// }


// Path: src/com/textrazor/net/TextRazorConnection.java
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
import java.net.URLEncoder;
import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.textrazor.AnalysisException;
import com.textrazor.NetworkException;

			
			// Note - removing this is handy for debugging holes in the library, but for production
			// use we don't want to fail on new properties to allow forward compatibility.
			mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
			
			try {
				return mapper.readValue(sbuff.toString(), responseClass);
			} catch (IOException e) {
				 e.printStackTrace();
				throw new RuntimeException("Unable to decode TextRazor response: ");
			}
		}
		catch (IOException e) {
			throw new NetworkException("Network Error when connecting to TextRazor", e);
		}
	}
	
	protected <RequestType, ResponseType> ResponseType sendRequest(
			String path, 
			RequestType requestBody,
			ContentType contentType,
			String method, 
			Class<ResponseType> responseClass) throws AnalysisException, NetworkException {
		ObjectMapper mapper = new ObjectMapper();

		// Optional params are represented by "null" in the build objects.
		// We don't need to actually send a null to the server.
		mapper.setSerializationInclusion(Include.NON_NULL);
		
		try {
			String jsonString = mapper.writeValueAsString(requestBody);