From 61b78a7d5f1eb8f1c5955d6d1439ce9225a39b46 Mon Sep 17 00:00:00 2001 From: Michal Kabaj Date: Mon, 17 Dec 2018 17:10:24 +0100 Subject: HttpClientFactory to create HttpClient instances -Replace constructor calls with existing factory -Add create methods to factory for each required Media Type Change-Id: Ibd03c10230c87a0413c0ec529e0ea9ac800444f9 Issue-ID: SO-1344 Signed-off-by: Michal Kabaj --- .../org/onap/so/openstack/utils/MsoMulticloudUtils.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'adapters/mso-adapter-utils/src/main/java/org/onap') diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java index 829f6c1445..c9b70610d1 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java @@ -21,16 +21,17 @@ package org.onap.so.openstack.utils; import java.net.MalformedURLException; +import java.net.URL; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; -import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilderException; import javax.ws.rs.core.Response; +import org.onap.so.client.HttpClientFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.onap.so.adapters.vdu.CloudInfo; @@ -48,7 +49,6 @@ import org.onap.so.openstack.beans.StackInfo; import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound; import org.onap.so.openstack.exceptions.MsoException; import org.onap.so.openstack.exceptions.MsoOpenstackException; -import org.onap.so.client.HttpClient; import org.onap.so.client.RestClient; import org.onap.so.db.catalog.beans.CloudSite; import org.onap.so.logger.MessageEnum; @@ -56,13 +56,8 @@ import org.onap.so.logger.MsoLogger; import org.onap.so.utils.TargetEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; import org.springframework.stereotype.Component; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.woorea.openstack.heat.model.CreateStackParam; @@ -80,11 +75,11 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ private static final Logger logger = LoggerFactory.getLogger(MsoMulticloudUtils.class); private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); + private final HttpClientFactory httpClientFactory = new HttpClientFactory(); @Autowired private Environment environment; - /****************************************************************************** * * Methods (and associated utilities) to implement the VduPlugin interface @@ -603,8 +598,9 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ private RestClient getMulticloudClient(String endpoint) { RestClient client = null; try { - client = new HttpClient(UriBuilder.fromUri(endpoint).build().toURL(), - MediaType.APPLICATION_JSON.toString(), TargetEntity.MULTICLOUD); + client = httpClientFactory.newJsonClient( + new URL(endpoint), + TargetEntity.MULTICLOUD); } catch (MalformedURLException e) { logger.debug(String.format("Encountered malformed URL error getting multicloud rest client %s", e.getMessage())); } catch (IllegalArgumentException e) { -- cgit 1.2.3-korg