Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
grada84 committed Nov 4, 2024
1 parent 8ee383c commit 63214ed
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/main/java/net/lacnic/portal/auth/client/PortalHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import java.security.KeyStore;

import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreConnectionPNames;
Expand All @@ -21,7 +22,38 @@
@SuppressWarnings("deprecation")
public class PortalHttpClient {

public static HttpClient getNewHttpClient() {
// public static HttpClient getNewHttpClient2() {
// try {
// KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
// trustStore.load(null, null);
//
// MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
// sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
//
// HttpParams params = new BasicHttpParams();
// HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
// HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
//
// SchemeRegistry registry = new SchemeRegistry();
// registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
// registry.register(new Scheme("https", sf, 443));
//
// ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
//
// DefaultHttpClient httpClient = new DefaultHttpClient(ccm, params);
//
// int timeout = 40; // seconds
// HttpParams httpParams = httpClient.getParams();
// httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout * 1000);
// httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout * 1000);
// httpParams.setParameter(ClientPNames.CONN_MANAGER_TIMEOUT, new Long(timeout * 1000));
// return httpClient;
// } catch (Exception e) {
// return new DefaultHttpClient();
// }
// }

public static CloseableHttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
Expand All @@ -39,16 +71,17 @@ public static HttpClient getNewHttpClient() {

ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

DefaultHttpClient httpClient = new DefaultHttpClient(ccm, params);
CloseableHttpClient httpClient = new DefaultHttpClient(ccm, params);

int timeout = 40; // seconds
HttpParams httpParams = httpClient.getParams();
httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout * 1000);
httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout * 1000);
httpParams.setParameter(ClientPNames.CONN_MANAGER_TIMEOUT, new Long(timeout * 1000));
httpParams.setParameter(ClientPNames.CONN_MANAGER_TIMEOUT, (long) timeout * 1000);

return httpClient;
} catch (Exception e) {
return new DefaultHttpClient();
return HttpClients.createDefault(); // Returns a default CloseableHttpClient instance
}
}
}

0 comments on commit 63214ed

Please sign in to comment.