// Path: src/main/java/com/citysearch/webwidget/exception/CitysearchException.java
// public class CitysearchException extends Exception {
//     private static final long serialVersionUID = 1L;
//     private String className;
//     private String methodName;
// 
//     public CitysearchException(String className, String methodName) {
//         super();
//         this.className = className;
//         this.methodName = methodName;
//     }
// 
//     public CitysearchException(String className, String methodName, String message) {
//         super(message);
//         this.className = className;
//         this.methodName = methodName;
//     }
// 
//     public CitysearchException(String className, String methodName, String message, Throwable cause) {
//         super(message, cause);
//         this.className = className;
//         this.methodName = methodName;
//     }
// 
//     public CitysearchException(String className, String methodName, Throwable cause) {
//         super(cause);
//         this.className = className;
//         this.methodName = methodName;
//     }
// 
//     public String getClassName() {
//         return className;
//     }
// 
//     public void setClassName(String className) {
//         this.className = className;
//     }
// 
//     public String getMethodName() {
//         return methodName;
//     }
// 
//     public void setMethodName(String methodName) {
//         this.methodName = methodName;
//     }
// 
//     public static long getSerialversionuid() {
//         return serialVersionUID;
//     }
// }


import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import org.apache.log4j.Logger;
import com.citysearch.webwidget.exception.CitysearchException;
package com.citysearch.webwidget.util;




/**
 * This class contains the functionality related to Http connection like getting
 * the connecton and closing the connection
 * 
 * @author Aspert Benjamin
 * 
 */
public class HttpConnection {
	private static Logger log = Logger.getLogger(HttpConnection.class);
	private static final String reqMethod = "GET";
	private static final int resWaitTime = 10000;
	private static final String error = "connection.error";

	/**
	 * Gets the connection object for the given url Exception thrown if there is
	 * a connection failure
	 * 
	 * @param urlString
	 * @param headers
	 *            Map for HTTP Headers
	 * @return
	 * @throws CitysearchException
	 */
	public static HttpURLConnection getConnection(String urlString,
			Map<String, String> headers) throws CitysearchException {
		HttpURLConnection connection = null;
		try {
			URL url = new URL(urlString);
			connection = (HttpURLConnection) url.openConnection();
			// Set HTTP headers if passed.
			if (headers != null && !headers.isEmpty()) {
				for (String key : headers.keySet()) {
					connection.setRequestProperty(key, headers.get(key));
				}
			}
			connection.setRequestMethod(reqMethod);
			connection.setDoOutput(true);
			connection.setReadTimeout(resWaitTime);
			connection.connect();
			if (connection == null) {
				throw new CitysearchException("HttpConnection",
						"getConnection", "Error Connecting to the URL");
			}
		} catch (IOException e) {
// Path: src/main/java/com/citysearch/webwidget/exception/CitysearchException.java
// public class CitysearchException extends Exception {
//     private static final long serialVersionUID = 1L;
//     private String className;
//     private String methodName;
// 
//     public CitysearchException(String className, String methodName) {
//         super();
//         this.className = className;
//         this.methodName = methodName;
//     }
// 
//     public CitysearchException(String className, String methodName, String message) {
//         super(message);
//         this.className = className;
//         this.methodName = methodName;
//     }
// 
//     public CitysearchException(String className, String methodName, String message, Throwable cause) {
//         super(message, cause);
//         this.className = className;
//         this.methodName = methodName;
//     }
// 
//     public CitysearchException(String className, String methodName, Throwable cause) {
//         super(cause);
//         this.className = className;
//         this.methodName = methodName;
//     }
// 
//     public String getClassName() {
//         return className;
//     }
// 
//     public void setClassName(String className) {
//         this.className = className;
//     }
// 
//     public String getMethodName() {
//         return methodName;
//     }
// 
//     public void setMethodName(String methodName) {
//         this.methodName = methodName;
//     }
// 
//     public static long getSerialversionuid() {
//         return serialVersionUID;
//     }
// }


// Path: src/main/java/com/citysearch/webwidget/util/HttpConnection.java
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import org.apache.log4j.Logger;
import com.citysearch.webwidget.exception.CitysearchException;

package com.citysearch.webwidget.util;




/**
 * This class contains the functionality related to Http connection like getting
 * the connecton and closing the connection
 * 
 * @author Aspert Benjamin
 * 
 */
public class HttpConnection {
	private static Logger log = Logger.getLogger(HttpConnection.class);
	private static final String reqMethod = "GET";
	private static final int resWaitTime = 10000;
	private static final String error = "connection.error";

	/**
	 * Gets the connection object for the given url Exception thrown if there is
	 * a connection failure
	 * 
	 * @param urlString
	 * @param headers
	 *            Map for HTTP Headers
	 * @return
	 * @throws CitysearchException
	 */
	public static HttpURLConnection getConnection(String urlString,
			Map<String, String> headers) throws CitysearchException {
		HttpURLConnection connection = null;
		try {
			URL url = new URL(urlString);
			connection = (HttpURLConnection) url.openConnection();
			// Set HTTP headers if passed.
			if (headers != null && !headers.isEmpty()) {
				for (String key : headers.keySet()) {
					connection.setRequestProperty(key, headers.get(key));
				}
			}
			connection.setRequestMethod(reqMethod);
			connection.setDoOutput(true);
			connection.setReadTimeout(resWaitTime);
			connection.connect();
			if (connection == null) {
				throw new CitysearchException("HttpConnection",
						"getConnection", "Error Connecting to the URL");
			}
		} catch (IOException e) {
			throw new CitysearchException("HttpConnection", "getConnection", e);