@@ -0,0 +1,2168 @@
+package test.template.utils;%0D%0A%0D%0Aimport java.security.SecureRandom;%0D%0Aimport java.security.cert.X509Certificate;%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.http.HttpResponse;%0D%0Aimport org.apache.http.client.methods.HttpGet;%0D%0Aimport org.apache.http.client.methods.HttpPost;%0D%0Aimport org.apache.http.client.methods.HttpRequestBase;%0D%0Aimport org.apache.http.entity.StringEntity;%0D%0Aimport org.apache.http.impl.client.CloseableHttpClient;%0D%0Aimport org.apache.http.impl.client.HttpClients;%0D%0Aimport org.apache.http.util.EntityUtils;%0D%0A%0D%0Apublic class HttpSession %7B%0D%0A%09private static SSLContext sc;%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%09sc = 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%09%0D%0A%09private CloseableHttpClient client = HttpClients.custom().setSSLContext(sc).build();%0D%0A%09%0D%0A%09private String execute(HttpRequestBase req) throws Exception %7B%0D%0A%09%09HttpResponse resp = client.execute(req);%0D%0A%09%09return EntityUtils.toString(resp.getEntity());%0D%0A%09%7D%0D%0A%0D%0A%09public String get(String url) throws Exception %7B%0D%0A%09%09return execute(new HttpGet(url));%0D%0A%09%7D%0D%0A%09%0D%0A%09public String post(String url, String data) throws Exception %7B%0D%0A%09%09HttpPost request = new HttpPost(url);%0D%0A%09%09request.setEntity(new StringEntity(data));%0D%0A%09%09return execute(request);%0D%0A%09%7D%0D%0A%7D%0D%0A

Add HttpSession based on HttpClient