aboutsummaryrefslogtreecommitdiffstats
path: root/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java
diff options
context:
space:
mode:
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-04-09 11:49:18 +0200
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-04-27 14:00:38 +0200
commit85bedddf8340cbbe57f941a919a980540aeeef59 (patch)
tree583203fc8de877736c1e54d8ada304bef4871454 /pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java
parented68a0ba2a4836f8963e9f4973a440f096af19e8 (diff)
Add variables to PNF simulator events and update logging
Issue-ID: INT-1517 Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> Change-Id: I48931c0b4c68cd4de548cfa7dbaa950a24d13545
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.java29
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;
}
-
}