package test.template.utils;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;


public class HttpUtils {
	public static final byte[] get(String url, Map<String, String> headers) {
		try {
			URLConnection conn = new URL(url).openConnection();
			if (headers != null) {
				for (Map.Entry<String, String> entry : headers.entrySet()) {
					conn.setRequestProperty(entry.getKey(), entry.getValue());
				}
			}
			InputStream is = conn.getInputStream();
			byte[] result = IOUtils.toByteArray(is);
			is.close();
			List<String> header = conn.getHeaderFields().get("Content-Disposition");
			if (header != null && header.size() > 0) {
				headers.put("Content-Disposition", header.get(0));
			}
			return result;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	public static final byte[] post(String url, String data, Map<String, String> headers) {
		try {
			URLConnection conn = new URL(url).openConnection();
			conn.setDoOutput(true);
			
			if (headers != null) {
				for (Map.Entry<String, String> entry : headers.entrySet()) {
					conn.setRequestProperty(entry.getKey(), entry.getValue());
				}
			}
			OutputStream os = conn.getOutputStream();
			OutputStreamWriter wr = new OutputStreamWriter(os);
			wr.write(data);
			wr.flush();
			wr.close();
			os.close();
			System.out.println("HTTP Response headers: " + conn.getHeaderFields());
			List<String> header = conn.getHeaderFields().get("Content-Disposition");
			if (header != null && header.size() > 0) {
				headers.put("Content-Disposition", header.get(0));
			}
			header = conn.getHeaderFields().get("Content-Type");
			if (header != null && header.size() > 0) {
				headers.put("Content-Type", header.get(0));
			}
			InputStream is = conn.getInputStream();
			byte[] result = IOUtils.toByteArray(is);
			is.close();
			return result;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}

@@ -190,112 +190,1271 @@
 ava.
-util.List;%0D%0Aimport java.util.Map;%0D%0A%0D%0Aimport org.apache.commons.io.IOUtils;%0D%0A%0D%0A%0D%0Apublic class HttpUtils %7B
+security.SecureRandom;%0D%0Aimport java.security.cert.X509Certificate;%0D%0Aimport java.util.List;%0D%0Aimport java.util.Map;%0D%0A%0D%0Aimport javax.net.ssl.HostnameVerifier;%0D%0Aimport javax.net.ssl.HttpsURLConnection;%0D%0Aimport javax.net.ssl.SSLContext;%0D%0Aimport javax.net.ssl.SSLSession;%0D%0Aimport javax.net.ssl.TrustManager;%0D%0Aimport javax.net.ssl.X509TrustManager;%0D%0A%0D%0Aimport org.apache.commons.io.IOUtils;%0D%0A%0D%0Apublic class HttpUtils %7B%0D%0A%09static %7B%0D%0A%09%09TrustManager%5B%5D trustAllCerts = new TrustManager%5B%5D %7B new X509TrustManager() %7B%0D%0A%09%09%09public java.security.cert.X509Certificate%5B%5D getAcceptedIssuers() %7B%0D%0A%09%09%09%09return new X509Certificate%5B%5D %7B%7D;%0D%0A%09%09%09%7D%0D%0A%0D%0A%09%09%09public void checkClientTrusted(X509Certificate%5B%5D chain, String authType) %7B%0D%0A%09%09%09%7D%0D%0A%0D%0A%09%09%09public void checkServerTrusted(X509Certificate%5B%5D chain, String authType) %7B%0D%0A%09%09%09%7D%0D%0A%09%09%7D %7D;%0D%0A%0D%0A%09%09HostnameVerifier hostnameVerifier = new HostnameVerifier() %7B%0D%0A%09%09%09@Override%0D%0A%09%09%09public boolean verify(String arg0, SSLSession arg1) %7B%0D%0A%09%09%09%09return true;%0D%0A%09%09%09%7D%0D%0A%09%09%7D;%0D%0A%0D%0A%09%09try %7B%0D%0A%09%09%09SSLContext sc = SSLContext.getInstance(%22TLS%22);%0D%0A%09%09%09sc.init(null, trustAllCerts, new SecureRandom());%0D%0A%09%09%09HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());%0D%0A%09%09%09HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);%0D%0A%09%09%7D catch (Exception e) %7B%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A
 %0D%0A%09p
@@ -2144,17 +2144,16 @@
 %09%7D%0D%0A%09%7D%0D%0A
-%09
 %0D%0A%09publi
@@ -2329,19 +2329,16 @@
 true);%0D%0A
-%09%09%09
 %0D%0A%09%09%09if 

Update HttpUtils to skip SSL cert validation