diff options
Diffstat (limited to 'pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java')
-rw-r--r-- | pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java index 7ddef86..a881698 100644 --- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java @@ -50,20 +50,20 @@ public class HttpClientAdapterImpl implements HttpClientAdapter { private static final String CONTENT_TYPE = "Content-Type"; private static final String APPLICATION_JSON = "application/json"; private static final RequestConfig CONFIG = RequestConfig.custom() - .setConnectTimeout(CONNECTION_TIMEOUT) - .setConnectionRequestTimeout(CONNECTION_TIMEOUT) - .setSocketTimeout(CONNECTION_TIMEOUT) - .build(); + .setConnectTimeout(CONNECTION_TIMEOUT) + .setConnectionRequestTimeout(CONNECTION_TIMEOUT) + .setSocketTimeout(CONNECTION_TIMEOUT) + .build(); private static final Marker INVOKE = MarkerFactory.getMarker("INVOKE"); private SslSupportLevel sslSupportLevel; private HttpClient client; private final String targetUrl; public HttpClientAdapterImpl(String targetUrl, SslAuthenticationHelper sslAuthenticationHelper) - throws IOException, GeneralSecurityException { + throws IOException, GeneralSecurityException { this.sslSupportLevel = sslAuthenticationHelper.isClientCertificateEnabled() - ? SslSupportLevel.CLIENT_CERT_AUTH - : SslSupportLevel.getSupportLevelBasedOnProtocol(targetUrl); + ? SslSupportLevel.CLIENT_CERT_AUTH + : SslSupportLevel.getSupportLevelBasedOnProtocol(targetUrl); this.client = sslSupportLevel.getClient(CONFIG, sslAuthenticationHelper); this.targetUrl = targetUrl; } @@ -76,11 +76,8 @@ public class HttpClientAdapterImpl implements HttpClientAdapter { @Override public void send(String content) { try { - HttpPost request = createRequest(content); - HttpResponse response = client.execute(request); - - //response has to be fully consumed otherwise apache won't release connection - EntityUtils.consumeQuietly(response.getEntity()); + HttpResponse response = sendAndRetrieve(content); + EntityUtils.consumeQuietly(response.getEntity()); //response has to be fully consumed otherwise apache won't release connection LOGGER.info(INVOKE, "Message sent, ves response code: {}", response.getStatusLine()); } catch (IOException e) { LOGGER.warn("Error sending message to ves: {}", e.getMessage(), e.getCause()); @@ -91,6 +88,13 @@ public class HttpClientAdapterImpl implements HttpClientAdapter { return sslSupportLevel; } + private HttpResponse sendAndRetrieve(String content) throws IOException { + HttpPost request = createRequest(content); + HttpResponse httpResponse = client.execute(request); + request.releaseConnection(); + return httpResponse; + } + private HttpPost createRequest(String content) throws UnsupportedEncodingException { HttpPost request = new HttpPost(this.targetUrl); StringEntity stringEntity = new StringEntity(content); @@ -101,5 +105,4 @@ public class HttpClientAdapterImpl implements HttpClientAdapter { return request; } - } |