diff options
author | Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> | 2021-01-26 07:43:22 +0100 |
---|---|---|
committer | Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> | 2021-01-28 10:16:25 +0100 |
commit | ed18ea83def89626ba42cbe3f38d96e50aabd2f6 (patch) | |
tree | 7fbfe76c003d8da7f9e4472340555c4ddd2cabf9 /pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpApacheResponseAdapterFactory.java | |
parent | ef730fbed8743def93b864800928653a9e330457 (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/HttpApacheResponseAdapterFactory.java')
-rw-r--r-- | pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpApacheResponseAdapterFactory.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpApacheResponseAdapterFactory.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpApacheResponseAdapterFactory.java new file mode 100644 index 0000000..36ba922 --- /dev/null +++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/HttpApacheResponseAdapterFactory.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2021 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.pnfsimulator.simulator.client; + +import org.apache.http.HttpResponse; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +public class HttpApacheResponseAdapterFactory { + + private static final Logger LOGGER = LoggerFactory.getLogger(HttpApacheResponseAdapterFactory.class); + + public HttpResponseAdapter create(HttpResponse response) { + String message; + try { + message = EntityUtils.toString(response.getEntity()); + } catch (IllegalArgumentException | IOException e) { + LOGGER.warn("Response from VES was empty"); + message = ""; + } + return new HttpResponseAdapter(response.getStatusLine().getStatusCode(), message); + } + +} |