From cb60d030f49ec48fb2021480919cb364d5ff442d Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Fri, 12 Dec 2014 11:34:08 +0000
Subject: [PATCH] #2140 feature - fix - Added load of config file from ENV variable and changes on Http client connections
---
src/main/java/net/curisit/securis/ConnectionManager.java | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/main/java/net/curisit/securis/ConnectionManager.java b/src/main/java/net/curisit/securis/ConnectionManager.java
index c8140f1..c46ebe9 100644
--- a/src/main/java/net/curisit/securis/ConnectionManager.java
+++ b/src/main/java/net/curisit/securis/ConnectionManager.java
@@ -19,7 +19,6 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
@@ -42,7 +41,7 @@
private static ConnectionManager singleton;
private final String serverUrl;
- private final CloseableHttpClient httpClient;
+ private final HttpClientBuilder httpClientBuilder;
private ConnectionManager() throws SeCurisException {
String aux = Params.get(Params.KEYS.LICENSE_SERVER_URL, Params.DEFAUT_SERVER_URL);
@@ -51,10 +50,10 @@
} else {
serverUrl = aux;
}
- httpClient = createHttpClient();
+ httpClientBuilder = createHttpClientBuilder();
}
- private CloseableHttpClient createHttpClient() throws SeCurisException {
+ private HttpClientBuilder createHttpClientBuilder() throws SeCurisException {
SSLContextBuilder builder = new SSLContextBuilder();
SSLConnectionSocketFactory sslsf = null;
try {
@@ -69,7 +68,7 @@
LOG.error(e1);
throw new SeCurisException("Error creating SSL socket factory");
}
- return HttpClientBuilder.create().setSSLSocketFactory(sslsf).build();
+ return HttpClientBuilder.create().setSSLSocketFactory(sslsf);
}
public synchronized static ConnectionManager getInstance() throws SeCurisException {
@@ -91,7 +90,7 @@
}
HttpResponse response;
try {
- response = httpClient.execute(postRequest);
+ response = httpClientBuilder.build().execute(postRequest);
checkErrors(command, response);
@@ -103,8 +102,8 @@
return responseBean;
} catch (IOException e) {
- LOG.error("Error accessing SeCuris server", e);
- throw new SeCurisException("Error accessing SeCuris server", e);
+ LOG.error("Error accessing SeCuris server with command: " + command, e);
+ throw new SeCurisException("Error accessing SeCuris server with command: " + command, e);
}
}
@@ -116,7 +115,8 @@
throw new SeCurisException(String.format("[%s] - %s", errorCode, errorMsg));
}
LOG.error("Unexpected error executing {}, Reason: {}", command, response.getStatusLine().getReasonPhrase());
- throw new SeCurisException("Error executing command " + command + ", status: " + response.getStatusLine().getStatusCode());
+ throw new SeCurisException("Error executing command " + command + ", status: " + response.getStatusLine().getStatusCode(),
+ new IOException("Unexpected server error"));
}
}
@@ -127,7 +127,7 @@
HttpResponse response;
try {
- response = httpClient.execute(getRequest);
+ response = httpClientBuilder.build().execute(getRequest);
if (response.getStatusLine().getStatusCode() != 200) {
throw new SeCurisException("Error executing command " + command + ", status: " + response.getStatusLine().getStatusCode());
}
--
Gitblit v1.3.2