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>2021-01-26 07:43:22 +0100
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2021-01-28 10:16:25 +0100
commited18ea83def89626ba42cbe3f38d96e50aabd2f6 (patch)
tree7fbfe76c003d8da7f9e4472340555c4ddd2cabf9 /pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java
parentef730fbed8743def93b864800928653a9e330457 (diff)
Add message from VES to PNF simulator response when performing one time event request
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> Change-Id: I0a12263daafacc52643838ff80482e4c7168b7ea Issue-ID: INT-1804
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.java11
1 files changed, 8 insertions, 3 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 5d2a024..4f249b9 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
@@ -48,11 +48,12 @@ public class HttpClientAdapterImpl implements HttpClientAdapter {
private static final String CONTENT_TYPE = "Content-Type";
private static final String APPLICATION_JSON = "application/json";
private static final Marker INVOKE = MarkerFactory.getMarker("INVOKE");
+ private static final HttpApacheResponseAdapterFactory responseFactory = new HttpApacheResponseAdapterFactory();
private final HttpClient client;
private final String targetUrl;
public HttpClientAdapterImpl(String targetUrl, SslAuthenticationHelper sslAuthenticationHelper)
- throws IOException, GeneralSecurityException {
+ throws IOException, GeneralSecurityException {
this.client = HttpClientFactoryFacade.create(targetUrl, sslAuthenticationHelper);
this.targetUrl = targetUrl;
}
@@ -63,14 +64,18 @@ public class HttpClientAdapterImpl implements HttpClientAdapter {
}
@Override
- public void send(String content) {
+ public HttpResponseAdapter send(String content) {
+ HttpResponseAdapter vesResponse;
try {
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());
+ vesResponse = responseFactory.create(response);
+ EntityUtils.consumeQuietly(response.getEntity()); //response has to be fully consumed otherwise apache won't release connection
} catch (IOException e) {
LOGGER.warn("Error sending message to ves: {}", e.getMessage(), e.getCause());
+ vesResponse = new HttpResponseAdapter(421, String.format("Fail to connect with ves: %s", e.getMessage()));
}
+ return vesResponse;
}
private HttpResponse sendAndRetrieve(String content) throws IOException {