// Path: zap-utils/src/main/java/br/com/softplan/security/zap/commons/exception/ZapInitializationTimeoutException.java
// public class ZapInitializationTimeoutException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -5283245793671447701L;
// 
// 	public ZapInitializationTimeoutException(String message) {
// 		super(message);
// 	}
// 	
// 	public ZapInitializationTimeoutException(Throwable e) {
// 		super(e);
// 	}
// 	
// 	public ZapInitializationTimeoutException(String message, Throwable e) {
// 		super(message, e);
// 	}
// 	
// }


import java.io.File;
import java.io.IOException;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import br.com.softplan.security.zap.commons.exception.ZapInitializationTimeoutException;
	static int getResponseFromZap(String host, int port) {
		if (host == null) {
			return -1;
		}
		
		String url = "http://" + host + ":" + port;
		
		int responseCode = -1;
		try {
			HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
			conn.setRequestMethod(HEAD);
			responseCode = conn.getResponseCode();
		} catch (ConnectException e) {
			LOGGER.debug("ZAP could not be reached at {}:{}.", host, port);
		} catch (IOException e) {
			LOGGER.error("Error trying to get a response from ZAP.", e);
		}
		return responseCode;
	}
	
	static void waitForZapInitialization(int port, long timeoutInMillis) {
		waitForZapInitialization("localhost", port, timeoutInMillis);
	}
	
	static void waitForZapInitialization(String host, int port, long timeoutInMillis) {
		long startUpTime = System.currentTimeMillis();
		do {
			if (System.currentTimeMillis() - startUpTime > timeoutInMillis) {
				String message = "ZAP did not start before the timeout (" + timeoutInMillis + " ms).";
				LOGGER.error(message);
// Path: zap-utils/src/main/java/br/com/softplan/security/zap/commons/exception/ZapInitializationTimeoutException.java
// public class ZapInitializationTimeoutException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -5283245793671447701L;
// 
// 	public ZapInitializationTimeoutException(String message) {
// 		super(message);
// 	}
// 	
// 	public ZapInitializationTimeoutException(Throwable e) {
// 		super(e);
// 	}
// 	
// 	public ZapInitializationTimeoutException(String message, Throwable e) {
// 		super(message, e);
// 	}
// 	
// }


// Path: zap-utils/src/main/java/br/com/softplan/security/zap/commons/boot/AbstractZapBoot.java
import java.io.File;
import java.io.IOException;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import br.com.softplan.security.zap.commons.exception.ZapInitializationTimeoutException;

	static int getResponseFromZap(String host, int port) {
		if (host == null) {
			return -1;
		}
		
		String url = "http://" + host + ":" + port;
		
		int responseCode = -1;
		try {
			HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
			conn.setRequestMethod(HEAD);
			responseCode = conn.getResponseCode();
		} catch (ConnectException e) {
			LOGGER.debug("ZAP could not be reached at {}:{}.", host, port);
		} catch (IOException e) {
			LOGGER.error("Error trying to get a response from ZAP.", e);
		}
		return responseCode;
	}
	
	static void waitForZapInitialization(int port, long timeoutInMillis) {
		waitForZapInitialization("localhost", port, timeoutInMillis);
	}
	
	static void waitForZapInitialization(String host, int port, long timeoutInMillis) {
		long startUpTime = System.currentTimeMillis();
		do {
			if (System.currentTimeMillis() - startUpTime > timeoutInMillis) {
				String message = "ZAP did not start before the timeout (" + timeoutInMillis + " ms).";
				LOGGER.error(message);
				throw new ZapInitializationTimeoutException(message);