| .. | .. |
|---|
| 19 | 19 | import org.apache.http.client.methods.HttpPost; |
|---|
| 20 | 20 | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
|---|
| 21 | 21 | import org.apache.http.entity.StringEntity; |
|---|
| 22 | | -import org.apache.http.impl.client.CloseableHttpClient; |
|---|
| 23 | 22 | import org.apache.http.impl.client.HttpClientBuilder; |
|---|
| 24 | 23 | import org.apache.http.ssl.SSLContextBuilder; |
|---|
| 25 | 24 | import org.apache.http.ssl.TrustStrategy; |
|---|
| .. | .. |
|---|
| 42 | 41 | private static ConnectionManager singleton; |
|---|
| 43 | 42 | |
|---|
| 44 | 43 | private final String serverUrl; |
|---|
| 45 | | - private final CloseableHttpClient httpClient; |
|---|
| 44 | + private final HttpClientBuilder httpClientBuilder; |
|---|
| 46 | 45 | |
|---|
| 47 | 46 | private ConnectionManager() throws SeCurisException { |
|---|
| 48 | 47 | String aux = Params.get(Params.KEYS.LICENSE_SERVER_URL, Params.DEFAUT_SERVER_URL); |
|---|
| .. | .. |
|---|
| 51 | 50 | } else { |
|---|
| 52 | 51 | serverUrl = aux; |
|---|
| 53 | 52 | } |
|---|
| 54 | | - httpClient = createHttpClient(); |
|---|
| 53 | + httpClientBuilder = createHttpClientBuilder(); |
|---|
| 55 | 54 | } |
|---|
| 56 | 55 | |
|---|
| 57 | | - private CloseableHttpClient createHttpClient() throws SeCurisException { |
|---|
| 56 | + private HttpClientBuilder createHttpClientBuilder() throws SeCurisException { |
|---|
| 58 | 57 | SSLContextBuilder builder = new SSLContextBuilder(); |
|---|
| 59 | 58 | SSLConnectionSocketFactory sslsf = null; |
|---|
| 60 | 59 | try { |
|---|
| .. | .. |
|---|
| 69 | 68 | LOG.error(e1); |
|---|
| 70 | 69 | throw new SeCurisException("Error creating SSL socket factory"); |
|---|
| 71 | 70 | } |
|---|
| 72 | | - return HttpClientBuilder.create().setSSLSocketFactory(sslsf).build(); |
|---|
| 71 | + return HttpClientBuilder.create().setSSLSocketFactory(sslsf); |
|---|
| 73 | 72 | } |
|---|
| 74 | 73 | |
|---|
| 75 | 74 | public synchronized static ConnectionManager getInstance() throws SeCurisException { |
|---|
| .. | .. |
|---|
| 91 | 90 | } |
|---|
| 92 | 91 | HttpResponse response; |
|---|
| 93 | 92 | try { |
|---|
| 94 | | - response = httpClient.execute(postRequest); |
|---|
| 93 | + response = httpClientBuilder.build().execute(postRequest); |
|---|
| 95 | 94 | |
|---|
| 96 | 95 | checkErrors(command, response); |
|---|
| 97 | 96 | |
|---|
| .. | .. |
|---|
| 103 | 102 | |
|---|
| 104 | 103 | return responseBean; |
|---|
| 105 | 104 | } 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); |
|---|
| 108 | 107 | } |
|---|
| 109 | 108 | } |
|---|
| 110 | 109 | |
|---|
| .. | .. |
|---|
| 116 | 115 | throw new SeCurisException(String.format("[%s] - %s", errorCode, errorMsg)); |
|---|
| 117 | 116 | } |
|---|
| 118 | 117 | 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")); |
|---|
| 120 | 120 | } |
|---|
| 121 | 121 | |
|---|
| 122 | 122 | } |
|---|
| .. | .. |
|---|
| 127 | 127 | |
|---|
| 128 | 128 | HttpResponse response; |
|---|
| 129 | 129 | try { |
|---|
| 130 | | - response = httpClient.execute(getRequest); |
|---|
| 130 | + response = httpClientBuilder.build().execute(getRequest); |
|---|
| 131 | 131 | if (response.getStatusLine().getStatusCode() != 200) { |
|---|
| 132 | 132 | throw new SeCurisException("Error executing command " + command + ", status: " + response.getStatusLine().getStatusCode()); |
|---|
| 133 | 133 | } |
|---|