rsanchez
2014-12-12 cb60d030f49ec48fb2021480919cb364d5ff442d
src/main/java/net/curisit/securis/ConnectionManager.java
....@@ -19,7 +19,6 @@
1919 import org.apache.http.client.methods.HttpPost;
2020 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
2121 import org.apache.http.entity.StringEntity;
22
-import org.apache.http.impl.client.CloseableHttpClient;
2322 import org.apache.http.impl.client.HttpClientBuilder;
2423 import org.apache.http.ssl.SSLContextBuilder;
2524 import org.apache.http.ssl.TrustStrategy;
....@@ -42,7 +41,7 @@
4241 private static ConnectionManager singleton;
4342
4443 private final String serverUrl;
45
- private final CloseableHttpClient httpClient;
44
+ private final HttpClientBuilder httpClientBuilder;
4645
4746 private ConnectionManager() throws SeCurisException {
4847 String aux = Params.get(Params.KEYS.LICENSE_SERVER_URL, Params.DEFAUT_SERVER_URL);
....@@ -51,10 +50,10 @@
5150 } else {
5251 serverUrl = aux;
5352 }
54
- httpClient = createHttpClient();
53
+ httpClientBuilder = createHttpClientBuilder();
5554 }
5655
57
- private CloseableHttpClient createHttpClient() throws SeCurisException {
56
+ private HttpClientBuilder createHttpClientBuilder() throws SeCurisException {
5857 SSLContextBuilder builder = new SSLContextBuilder();
5958 SSLConnectionSocketFactory sslsf = null;
6059 try {
....@@ -69,7 +68,7 @@
6968 LOG.error(e1);
7069 throw new SeCurisException("Error creating SSL socket factory");
7170 }
72
- return HttpClientBuilder.create().setSSLSocketFactory(sslsf).build();
71
+ return HttpClientBuilder.create().setSSLSocketFactory(sslsf);
7372 }
7473
7574 public synchronized static ConnectionManager getInstance() throws SeCurisException {
....@@ -91,7 +90,7 @@
9190 }
9291 HttpResponse response;
9392 try {
94
- response = httpClient.execute(postRequest);
93
+ response = httpClientBuilder.build().execute(postRequest);
9594
9695 checkErrors(command, response);
9796
....@@ -103,8 +102,8 @@
103102
104103 return responseBean;
105104 } catch (IOException e) {
106
- LOG.error("Error accessing SeCuris server", e);
107
- throw new SeCurisException("Error accessing SeCuris server", e);
105
+ LOG.error("Error accessing SeCuris server with command: " + command, e);
106
+ throw new SeCurisException("Error accessing SeCuris server with command: " + command, e);
108107 }
109108 }
110109
....@@ -116,7 +115,8 @@
116115 throw new SeCurisException(String.format("[%s] - %s", errorCode, errorMsg));
117116 }
118117 LOG.error("Unexpected error executing {}, Reason: {}", command, response.getStatusLine().getReasonPhrase());
119
- throw new SeCurisException("Error executing command " + command + ", status: " + response.getStatusLine().getStatusCode());
118
+ throw new SeCurisException("Error executing command " + command + ", status: " + response.getStatusLine().getStatusCode(),
119
+ new IOException("Unexpected server error"));
120120 }
121121
122122 }
....@@ -127,7 +127,7 @@
127127
128128 HttpResponse response;
129129 try {
130
- response = httpClient.execute(getRequest);
130
+ response = httpClientBuilder.build().execute(getRequest);
131131 if (response.getStatusLine().getStatusCode() != 200) {
132132 throw new SeCurisException("Error executing command " + command + ", status: " + response.getStatusLine().getStatusCode());
133133 }