HttpClientFactory to create HttpClient instances 28/74728/4
authorMichal Kabaj <michal.kabaj@nokia.com>
Mon, 17 Dec 2018 16:10:24 +0000 (17:10 +0100)
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Fri, 4 Jan 2019 12:02:36 +0000 (12:02 +0000)
-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 <michal.kabaj@nokia.com>
36 files changed:
adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtils.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/GenerateVfModuleName.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterRestV1.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SniroHomingV1.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1.groovy
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java
bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CatalogDbUtilsTest.groovy
bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtilTest.groovy
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterAsyncTransformer.java
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterMockTransformer.java
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterNetworkTopologyMockTransformer.java
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterAsyncTransformer.java
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterCreateMockTransformer.java
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterDeleteMockTransformer.java
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterQueryMockTransformer.java
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterRollbackMockTransformer.java
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterUpdateMockTransformer.java
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateVFCNSResource.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateNetworkInstanceRollback.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVFCNetworkServiceInstance.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModule.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteNetworkInstance.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVFCNetworkServiceInstance.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoScaleVFCNetworkServiceInstance.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateVnfAndModules.groovy
common/src/main/java/org/onap/so/client/HttpClient.java
common/src/main/java/org/onap/so/client/HttpClientFactory.java
common/src/test/java/org/onap/so/client/HttpClientTest.java
common/src/test/java/org/onap/so/client/RestClientTest.java
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java

index 829f6c1..c9b7061 100644 (file)
 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) {
index 8cc232c..8a8e412 100644 (file)
@@ -19,6 +19,9 @@
  */
 
 package org.onap.so.bpmn.common.scripts
+
+import org.onap.so.client.HttpClientFactory
+
 import java.util.regex.Matcher
 import java.util.regex.Pattern
 
@@ -88,7 +91,7 @@ class AaiUtil {
                String regionId = ""
                try{
                        URL Url = new URL(url)
-                       HttpClient client = new HttpClient(Url, MediaType.APPLICATION_XML, TargetEntity.AAI)
+                       HttpClient client = new HttpClientFactory().newXmlClient(Url, TargetEntity.AAI)
                        client.addBasicAuthHeader(UrnPropertiesReader.getVariable("aai.auth", execution), UrnPropertiesReader.getVariable("mso.msoKey", execution))
                        client.addAdditionalHeader("X-FromAppId", "MSO")
                        client.addAdditionalHeader("X-TransactionId", utils.getRequestID())
index 22b5de2..df0dfae 100644 (file)
@@ -418,7 +418,7 @@ class CatalogDbUtils {
                        String catalogDbEndpoint = UrnPropertiesReader.getVariable("mso.catalog.db.endpoint",execution)
                        String queryEndpoint = catalogDbEndpoint + "/" + defaultDbAdapterVersion + endPoint
                        def responseData = ''
-                       HttpClient client = httpClientFactory.create(new URL(queryEndpoint), MediaType.APPLICATION_JSON, TargetEntity.CATALOG_DB)
+                       HttpClient client = httpClientFactory.newJsonClient(new URL(queryEndpoint), TargetEntity.CATALOG_DB)
                        client.addAdditionalHeader(ONAPLogConstants.Headers.REQUEST_ID, UUID.randomUUID().toString())
                        client.addAdditionalHeader('X-FromAppId', "BPMN")
                        client.addAdditionalHeader('Accept', MediaType.APPLICATION_JSON)
index 250cdda..94c82f5 100644 (file)
@@ -141,7 +141,7 @@ class ExternalAPIUtil {
                        msoLogger.debug( "Generated uuid is: " + uuid)
                        msoLogger.debug( "URL to be used is: " + url)
 
-                       HttpClient client = httpClientFactory.create(new URL(url), MediaType.APPLICATION_JSON, TargetEntity.EXTERNAL)
+                       HttpClient client = httpClientFactory.newJsonClient(new URL(url), TargetEntity.EXTERNAL)
                        client.addBasicAuthHeader(execution.getVariable("URN_externalapi_auth"), execution.getVariable("URN_mso_msoKey"))
                        client.addAdditionalHeader("X-FromAppId", "MSO")
                        client.addAdditionalHeader(ONAPLogConstants.Headers.REQUEST_ID, uuid)
@@ -177,7 +177,7 @@ class ExternalAPIUtil {
                        msoLogger.debug( "Generated uuid is: " + uuid)
                        msoLogger.debug( "URL to be used is: " + url)
 
-                       HttpClient httpClient = httpClientFactory.create(new URL(url), MediaType.APPLICATION_JSON, TargetEntity.AAI)
+                       HttpClient httpClient = httpClientFactory.newJsonClient(new URL(url), TargetEntity.AAI)
                        httpClient.addBasicAuthHeader(execution.getVariable("URN_externalapi_auth"), execution.getVariable("URN_mso_msoKey"))
                        httpClient.addAdditionalHeader("X-FromAppId", "MSO")
                        httpClient.addAdditionalHeader("X-TransactionId", uuid)
index c961dd0..1be24c4 100644 (file)
@@ -21,6 +21,7 @@
 package org.onap.so.bpmn.common.scripts
 
 import org.onap.so.bpmn.core.UrnPropertiesReader
+import org.onap.so.client.HttpClientFactory
 
 import java.io.Serializable;
 
@@ -86,7 +87,8 @@ public class GenerateVfModuleName extends AbstractServiceTaskProcessor{
                        msoLogger.debug("AAI endPoint: " + endPoint)
 
                        try {
-                               HttpClient client = new HttpClient(new URL(endPoint), MediaType.APPLICATION_XML, TargetEntity.AAI)
+                               HttpClient client = new HttpClientFactory().newXmlClient(new URL(endPoint), TargetEntity.AAI)
+
                                client.addAdditionalHeader('X-TransactionId', UUID.randomUUID().toString())
                                client.addAdditionalHeader('X-FromAppId', 'MSO')
                                client.addAdditionalHeader('Content-Type', 'application/xml')
index ee93f3a..5659c7a 100644 (file)
@@ -31,6 +31,7 @@ import org.onap.so.bpmn.core.domain.Subscriber
 import org.onap.so.bpmn.core.domain.VnfResource
 import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
 import org.onap.so.logger.MsoLogger
 import org.onap.so.db.catalog.beans.CloudIdentity
 import org.onap.so.db.catalog.beans.CloudSite
@@ -159,8 +160,8 @@ class OofHoming extends AbstractServiceTaskProcessor {
 
 
                                URL url = new URL(urlString);
-                               HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.SNIRO)
-                               httpClient.addAdditionalHeader("Authorization", authHeader)
+                HttpClient httpClient = new HttpClientFactory().newJsonClient(url, TargetEntity.SNIRO)
+                httpClient.addAdditionalHeader("Authorization", authHeader)
                                Response httpResponse = httpClient.post(oofRequest)
 
                                int responseCode = httpResponse.getStatus()
index 46ecc7b..c0da888 100644 (file)
@@ -34,6 +34,7 @@ import org.onap.so.bpmn.core.domain.Subscriber
 import org.onap.so.bpmn.core.domain.VnfResource
 import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
 import org.onap.so.db.catalog.beans.CloudSite
 import org.onap.so.utils.TargetEntity
 import org.springframework.http.HttpEntity
@@ -507,10 +508,10 @@ class OofUtils {
         String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution)
         String uri = "/cloudSite"
 
-       URL url = new URL(endpoint + uri)
-       HttpClient client = new HttpClient(url, MediaType.APPLICATION_JSON, TargetEntity.EXTERNAL)
-       client.addAdditionalHeader(HttpHeaders.AUTHORIZATION, auth)
-       client.addAdditionalHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
+           URL url = new URL(endpoint + uri)
+        HttpClient client = new HttpClientFactory().newJsonClient(url, TargetEntity.EXTERNAL)
+        client.addAdditionalHeader(HttpHeaders.AUTHORIZATION, auth)
+           client.addAdditionalHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
 
         Response response = client.post(request.getBody().toString())
 
index 0cefae5..9f1570e 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.onap.so.bpmn.common.scripts
 
+import org.onap.so.client.HttpClientFactory
+
 import java.text.SimpleDateFormat
 import javax.ws.rs.core.Response
 import java.net.URLEncoder
@@ -207,7 +209,7 @@ class SDNCAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                        URL url = new URL(sdncAdapterUrl);
 
-                       HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.SDNC_ADAPTER)                      
+                       HttpClient httpClient = new HttpClientFactory().newJsonClient(url, TargetEntity.SDNC_ADAPTER)
                        httpClient.addAdditionalHeader("X-ONAP-RequestID", execution.getVariable("mso-request-id"))
                        httpClient.addAdditionalHeader("X-ONAP-InvocationID", UUID.randomUUID().toString())
                        httpClient.addAdditionalHeader("X-ONAP-PartnerName", "SO-SDNCAdapter")
index 401cac9..9556ae7 100644 (file)
@@ -34,6 +34,7 @@ import org.onap.so.bpmn.core.domain.Subscriber
 import org.onap.so.bpmn.core.domain.VnfResource
 import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
 import org.onap.so.utils.TargetEntity
 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 
@@ -133,7 +134,7 @@ class SniroHomingV1 extends AbstractServiceTaskProcessor{
                                msoLogger.debug("Sniro Url is: " + urlString)
 
                                URL url = new URL(urlString);
-                               HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.SNIRO)
+                               HttpClient httpClient = new HttpClientFactory().newJsonClient(url, TargetEntity.SNIRO)
                                httpClient.addAdditionalHeader("Authorization", authHeader)
                                Response httpResponse = httpClient.post(sniroRequest)
 
index 1452a9a..8aff0f7 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.onap.so.bpmn.common.scripts
 
+import org.onap.so.client.HttpClientFactory
+
 import javax.ws.rs.core.Response
 import org.apache.commons.lang3.*
 import org.camunda.bpm.engine.delegate.BpmnError
@@ -311,7 +313,7 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                        URL url = new URL(vnfAdapterUrl);
 
-                       HttpClient httpClient = new HttpClient(url, "application/xml", TargetEntity.VNF_ADAPTER)
+                       HttpClient httpClient = new HttpClientFactory().newXmlClient(url, TargetEntity.VNF_ADAPTER)
                        httpClient.addAdditionalHeader("Authorization", execution.getVariable(prefix + "basicAuthHeaderValue"))
                        
                        httpClient.addAdditionalHeader("X-ONAP-RequestID", execution.getVariable("mso-request-id"))
index 7df9c7b..12a4b2a 100644 (file)
@@ -46,7 +46,7 @@ import org.onap.sdc.toscaparser.api.parameters.Input;
 import org.onap.so.bpmn.core.UrnPropertiesReader;
 import org.onap.so.bpmn.core.json.JsonUtils;
 import org.onap.so.client.HttpClient;
-import org.onap.so.logger.MessageEnum;
+import org.onap.so.client.HttpClientFactory;
 import org.onap.so.logger.MsoLogger;
 import org.onap.so.utils.TargetEntity;
 
@@ -260,7 +260,9 @@ public class ResourceRequestBuilder {
 
     private static String getCsarFromUuid(String uuid) throws Exception {
                String catalogEndPoint = UrnPropertiesReader.getVariable("mso.catalog.db.endpoint");
-       HttpClient client = new HttpClient(UriBuilder.fromUri(catalogEndPoint).path(SERVICE_URL_TOSCA_CSAR).queryParam("serviceModelUuid", uuid).build().toURL(), "application/json", TargetEntity.CATALOG_DB);
+       HttpClient client = new HttpClientFactory().newJsonClient(
+           UriBuilder.fromUri(catalogEndPoint).path(SERVICE_URL_TOSCA_CSAR).queryParam("serviceModelUuid", uuid).build().toURL(),
+            TargetEntity.CATALOG_DB);
        
        client.addAdditionalHeader("Accept", "application/json");
 //     client.addBasicAuthHeader (UrnPropertiesReader.getVariable("mso.adapters.db.auth"), UrnPropertiesReader.getVariable("mso.msoKey"));
index 723fb9e..d6a7cf0 100644 (file)
@@ -127,7 +127,7 @@ class CatalogDbUtilsTest {
     private void mockGetResponseFromCatalogDb(String queryEndpoint) {
         Environment environmentMock = createEnvironmentMock()
         when(environmentMock.getProperty("mso.catalog.db.endpoint")).thenReturn("http://testUrl")
-        when(httpClientFactoryMock.create(new URL(queryEndpoint), MediaType.APPLICATION_JSON, TargetEntity.CATALOG_DB)).thenReturn(httpClientMock)
+        when(httpClientFactoryMock.newJsonClient(new URL(queryEndpoint), TargetEntity.CATALOG_DB)).thenReturn(httpClientMock)
 
         Response responseMock = mock(Response.class)
         when(httpClientMock.get()).thenReturn(responseMock)
index 5f428f1..db11cb6 100644 (file)
@@ -53,7 +53,7 @@ class ExternalAPIUtilTest {
         HttpClient httpClient = mock(HttpClient.class)
         given(httpClient.get()).willReturn(expectedResponse)
         HttpClientFactory httpClientFactory = mock(HttpClientFactory.class)
-        given(httpClientFactory.create(new URL(URL), MediaType.APPLICATION_JSON, TargetEntity.EXTERNAL)).willReturn(httpClient)
+        given(httpClientFactory.newJsonClient(new URL(URL), TargetEntity.EXTERNAL)).willReturn(httpClient)
 
         // WHEN
         ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(httpClientFactory, new DummyMsoUtils(UUID_STR), new ExceptionUtil())
@@ -75,13 +75,14 @@ class ExternalAPIUtilTest {
         HttpClient httpClient = mock(HttpClient.class)
         willThrow(new RuntimeException("error occurred")).given(httpClient).get()
         HttpClientFactory httpClientFactory = mock(HttpClientFactory.class)
-        given(httpClientFactory.create(new URL(URL), MediaType.APPLICATION_JSON, TargetEntity.EXTERNAL)).willReturn(httpClient)
+        given(httpClientFactory.newJsonClient(new URL(URL), TargetEntity.EXTERNAL)).willReturn(httpClient)
         DelegateExecution delegateExecution = createDelegateExecution()
         DummyExceptionUtil exceptionUtil = new DummyExceptionUtil()
 
         // WHEN
         ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(httpClientFactory, new DummyMsoUtils(UUID_STR), exceptionUtil)
-        BpmnError bpmnError = catchThrowableOfType({ -> externalAPIUtil.executeExternalAPIGetCall(delegateExecution, URL)
+        BpmnError bpmnError = catchThrowableOfType({ ->
+            externalAPIUtil.executeExternalAPIGetCall(delegateExecution, URL)
         }, BpmnError.class)
 
         // THEN
@@ -96,7 +97,7 @@ class ExternalAPIUtilTest {
         HttpClient httpClient = mock(HttpClient.class)
         willThrow(new RuntimeException("error occurred")).given(httpClient).post(BODY_PAYLOAD)
         HttpClientFactory httpClientFactory = mock(HttpClientFactory.class)
-        given(httpClientFactory.create(new URL(URL), MediaType.APPLICATION_JSON, TargetEntity.AAI)).willReturn(httpClient)
+        given(httpClientFactory.newJsonClient(new URL(URL), TargetEntity.AAI)).willReturn(httpClient)
         DelegateExecution delegateExecution = createDelegateExecution()
         DummyExceptionUtil exceptionUtil = new DummyExceptionUtil()
 
@@ -119,7 +120,7 @@ class ExternalAPIUtilTest {
         HttpClient httpClient = mock(HttpClient.class)
         given(httpClient.post(BODY_PAYLOAD)).willReturn(expectedResponse)
         HttpClientFactory httpClientFactory = mock(HttpClientFactory.class)
-        given(httpClientFactory.create(new URL(URL), MediaType.APPLICATION_JSON, TargetEntity.AAI)).willReturn(httpClient)
+        given(httpClientFactory.newJsonClient(new URL(URL), TargetEntity.AAI)).willReturn(httpClient)
 
         // WHEN
         ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(httpClientFactory, new DummyMsoUtils(UUID_STR), new ExceptionUtil())
index 9b5bb33..8515307 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.so.bpmn.mock;
 import javax.ws.rs.core.UriBuilder;
 
 import org.onap.so.client.HttpClient;
+import org.onap.so.client.HttpClientFactory;
 import org.onap.so.utils.TargetEntity;
 
 import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
@@ -141,7 +142,9 @@ public class SDNCAdapterAsyncTransformer extends ResponseDefinitionTransformer {
                                e1.printStackTrace();
                        }
                        try {
-                               HttpClient client = new HttpClient(UriBuilder.fromUri(callbackUrl).build().toURL(), "text/xml", TargetEntity.SDNC_ADAPTER);
+                               HttpClient client = new HttpClientFactory().newTextXmlClient(
+                                       UriBuilder.fromUri(callbackUrl).build().toURL(),
+                                       TargetEntity.SDNC_ADAPTER);
                                client.post(payLoad);
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
index 8c34b65..f129164 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.so.bpmn.mock;
 import javax.ws.rs.core.UriBuilder;
 
 import org.onap.so.client.HttpClient;
+import org.onap.so.client.HttpClientFactory;
 import org.onap.so.logger.MsoLogger;
 import org.onap.so.utils.TargetEntity;
 
@@ -131,7 +132,9 @@ public class SDNCAdapterMockTransformer extends ResponseDefinitionTransformer {
                        }
                        LOGGER.debug("Sending callback response:" + callbackUrl);
                        try {
-                               HttpClient client = new HttpClient(UriBuilder.fromUri(callbackUrl).build().toURL(), "text/xml", TargetEntity.SDNC_ADAPTER);
+                               HttpClient client = new HttpClientFactory().newTextXmlClient(
+                                       UriBuilder.fromUri(callbackUrl).build().toURL(),
+                                       TargetEntity.SDNC_ADAPTER);
                                client.post(payLoad);
                        } catch (Exception e) {
                                LOGGER.debug("Exception :",e);
index f53fd6f..832caae 100644 (file)
@@ -24,6 +24,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 
 import org.onap.so.client.HttpClient;
+import org.onap.so.client.HttpClientFactory;
 import org.onap.so.logger.MsoLogger;
 import org.onap.so.utils.TargetEntity;
 
@@ -122,7 +123,9 @@ public class SDNCAdapterNetworkTopologyMockTransformer extends ResponseDefinitio
                        }
                        LOGGER.debug("Sending callback response to url: " + callbackUrl);
                        try {
-                               HttpClient client = new HttpClient(UriBuilder.fromUri(callbackUrl).build().toURL(), "text/xml", TargetEntity.SDNC_ADAPTER);
+                               HttpClient client = new HttpClientFactory().newTextXmlClient(
+                                       UriBuilder.fromUri(callbackUrl).build().toURL(),
+                                       TargetEntity.SDNC_ADAPTER);
                                Response response = client.post(payLoad);
                                LOGGER.debug("Successfully posted callback? Status: " + response.getStatus());
                        } catch (Exception e) {
index 63abf4d..e190535 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.so.bpmn.mock;
 import javax.ws.rs.core.UriBuilder;
 
 import org.onap.so.client.HttpClient;
+import org.onap.so.client.HttpClientFactory;
 import org.onap.so.utils.TargetEntity;
 
 import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
@@ -152,7 +153,9 @@ public class VnfAdapterAsyncTransformer extends ResponseDefinitionTransformer {
                        }
                        
                        try {
-                               HttpClient client = new HttpClient(UriBuilder.fromUri(callbackUrl).build().toURL(), "text/xml", TargetEntity.VNF_ADAPTER);
+                               HttpClient client = new HttpClientFactory().newTextXmlClient(
+                                       UriBuilder.fromUri(callbackUrl).build().toURL(),
+                                       TargetEntity.VNF_ADAPTER);
                                client.post(payLoad);
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
index de21d64..107a70d 100644 (file)
@@ -24,6 +24,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 
 import org.onap.so.client.HttpClient;
+import org.onap.so.client.HttpClientFactory;
 import org.onap.so.logger.MsoLogger;
 import org.onap.so.utils.TargetEntity;
 
@@ -131,7 +132,9 @@ public class VnfAdapterCreateMockTransformer extends ResponseDefinitionTransform
                        }
                        LOGGER.debug("Sending callback response to url: " + callbackUrl);
                        try {
-                               HttpClient client = new HttpClient(UriBuilder.fromUri(callbackUrl).build().toURL(), "text/xml", TargetEntity.VNF_ADAPTER);
+                               HttpClient client = new HttpClientFactory().newTextXmlClient(
+                                       UriBuilder.fromUri(callbackUrl).build().toURL(),
+                                       TargetEntity.VNF_ADAPTER);
                                Response response = client.post(payLoad);
                                LOGGER.debug("Successfully posted callback? Status: " + response.getStatus());
                                //System.err.println("Successfully posted callback:" + result.getStatus());
index 99ad84d..cf0f966 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.so.bpmn.mock;
 import javax.ws.rs.core.UriBuilder;
 
 import org.onap.so.client.HttpClient;
+import org.onap.so.client.HttpClientFactory;
 import org.onap.so.logger.MsoLogger;
 import org.onap.so.utils.TargetEntity;
 
@@ -132,7 +133,9 @@ public class VnfAdapterDeleteMockTransformer extends ResponseDefinitionTransform
                        }
 
                        try {
-                               HttpClient client = new HttpClient(UriBuilder.fromUri(callbackUrl).build().toURL(), "text/xml", TargetEntity.VNF_ADAPTER);
+                               HttpClient client = new HttpClientFactory().newTextXmlClient(
+                                       UriBuilder.fromUri(callbackUrl).build().toURL(),
+                                       TargetEntity.VNF_ADAPTER);
                                client.post(payLoad);
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
index 7ad687a..5eaa4e7 100644 (file)
@@ -24,6 +24,7 @@ package org.onap.so.bpmn.mock;
 import javax.ws.rs.core.UriBuilder;
 
 import org.onap.so.client.HttpClient;
+import org.onap.so.client.HttpClientFactory;
 import org.onap.so.logger.MsoLogger;
 import org.onap.so.utils.TargetEntity;
 
@@ -148,7 +149,9 @@ public class VnfAdapterQueryMockTransformer extends ResponseDefinitionTransforme
                        }
 
                        try {
-                               HttpClient client = new HttpClient(UriBuilder.fromUri(callbackUrl).build().toURL(), "text/xml", TargetEntity.VNF_ADAPTER);
+                               HttpClient client = new HttpClientFactory().newTextXmlClient(
+                                       UriBuilder.fromUri(callbackUrl).build().toURL(),
+                                       TargetEntity.VNF_ADAPTER);
                                client.post(payLoad);
                        } catch (Exception e) {
                                LOGGER.debug("Exception :",e);
index 560915d..06f2fb7 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.so.bpmn.mock;
 import javax.ws.rs.core.UriBuilder;
 
 import org.onap.so.client.HttpClient;
+import org.onap.so.client.HttpClientFactory;
 import org.onap.so.logger.MsoLogger;
 import org.onap.so.utils.TargetEntity;
 
@@ -133,7 +134,9 @@ public class VnfAdapterRollbackMockTransformer extends ResponseDefinitionTransfo
                        }
 
                        try {
-                               HttpClient client = new HttpClient(UriBuilder.fromUri(callbackUrl).build().toURL(), "text/xml", TargetEntity.VNF_ADAPTER);
+                               HttpClient client = new HttpClientFactory().newTextXmlClient(
+                                       UriBuilder.fromUri(callbackUrl).build().toURL(),
+                                       TargetEntity.VNF_ADAPTER);
                                client.post(payLoad);
                        } catch (Exception e) {
                                System.out.println("catch error in - request.post() ");                         
index 9e89271..9e60e87 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.so.bpmn.mock;
 import javax.ws.rs.core.UriBuilder;
 
 import org.onap.so.client.HttpClient;
+import org.onap.so.client.HttpClientFactory;
 import org.onap.so.logger.MsoLogger;
 import org.onap.so.utils.TargetEntity;
 
@@ -133,7 +134,9 @@ public class VnfAdapterUpdateMockTransformer extends ResponseDefinitionTransform
                        }
 
                        try {
-                               HttpClient client = new HttpClient(UriBuilder.fromUri(callbackUrl).build().toURL(), "text/xml", TargetEntity.VNF_ADAPTER);
+                               HttpClient client = new HttpClientFactory().newTextXmlClient(
+                                       UriBuilder.fromUri(callbackUrl).build().toURL(),
+                                       TargetEntity.VNF_ADAPTER);
                                client.post(payLoad);
                        } catch (Exception e) {
                                System.out.println("catch error in - request.post() ");
index 2a2d1f4..6222214 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.so.bpmn.infrastructure.scripts
 
+import org.onap.so.client.HttpClientFactory
 import org.onap.so.client.aai.AAIObjectType
 import org.onap.so.client.aai.entities.uri.AAIResourceUri
 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
@@ -29,11 +30,9 @@ import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.HttpClient
-import org.onap.so.logger.MessageEnum
 import org.onap.so.logger.MsoLogger
 import org.onap.so.bpmn.core.UrnPropertiesReader
 
-import groovy.json.*
 import javax.ws.rs.core.Response
 import org.onap.so.utils.TargetEntity
 
@@ -271,7 +270,7 @@ public class CreateVFCNSResource extends AbstractServiceTaskProcessor {
             // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7'
             // user 'bepl' authHeader is the same with mso.db.auth
             String basicAuthValuedb =  UrnPropertiesReader.getVariable("mso.db.auth", execution)
-            HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
+            HttpClient httpClient = new HttpClientFactory().newJsonClient(url, TargetEntity.VNF_ADAPTER)
             httpClient.addAdditionalHeader("Accept", "application/json")
             httpClient.addAdditionalHeader("Authorization", basicAuthValuedb)
 
index 1d75d39..fd6a4a1 100644 (file)
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.so.bpmn.infrastructure.scripts;
+package org.onap.so.bpmn.infrastructure.scripts
 
-import groovy.xml.XmlUtil
 
-import groovy.json.*
 import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
 import org.onap.so.logger.MsoLogger
-import org.onap.so.logger.MessageEnum
-
 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 import org.onap.so.bpmn.common.scripts.NetworkUtils
@@ -37,13 +34,9 @@ import org.onap.so.bpmn.common.scripts.VidUtils
 import org.onap.so.bpmn.core.WorkflowException
 import org.onap.so.utils.TargetEntity
 
-import java.util.UUID;
 import javax.ws.rs.core.Response
 import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.delegate.DelegateExecution
-import org.apache.commons.lang3.*
-import org.apache.commons.codec.binary.Base64;
-import org.springframework.web.util.UriUtils
 
 /**
  * This groovy class supports the <class>DoCreateNetworkInstance.bpmn</class> process.
@@ -203,7 +196,7 @@ public class DoCreateNetworkInstanceRollback extends AbstractServiceTaskProcesso
                        execution.setVariable(Prefix + "urlRollbackPoNetwork", urlRollbackPoNetwork)
 
                        URL url = new URL(urlRollbackPoNetwork)
-                       HttpClient httpClient = new HttpClient(url, "application/xml", TargetEntity.OPENSTACK_ADAPTER)
+                       HttpClient httpClient = new HttpClientFactory().newXmlClient(url, TargetEntity.OPENSTACK_ADAPTER)
                        httpClient.addAdditionalHeader("Authorization", execution.getVariable("BasicAuthHeaderValuePO"))
                        Response response = httpClient.delete(rollbackNetworkRequest)
 
index 1e7f731..33d0e25 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.so.bpmn.infrastructure.scripts
 
+import org.onap.so.client.HttpClientFactory
 import org.onap.so.client.aai.AAIObjectType
 import org.onap.so.client.aai.entities.uri.AAIResourceUri
 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
@@ -35,7 +36,6 @@ import org.onap.so.bpmn.core.UrnPropertiesReader
 
 import org.onap.so.utils.TargetEntity
 
-import groovy.json.*
 import javax.ws.rs.core.Response
 
 /**
@@ -251,7 +251,7 @@ public class DoCreateVFCNetworkServiceInstance extends AbstractServiceTaskProces
             // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7'
             // user 'bepl' authHeader is the same with mso.db.auth
             String basicAuthValuedb =  UrnPropertiesReader.getVariable("mso.db.auth", execution)
-            HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
+            HttpClient httpClient = new HttpClientFactory().newJsonClient(url, TargetEntity.VNF_ADAPTER)
             httpClient.addAdditionalHeader("Accept", "application/json")
             httpClient.addAdditionalHeader("Authorization", basicAuthValuedb)
 
index a09f22f..089239f 100644 (file)
@@ -21,6 +21,7 @@
 package org.onap.so.bpmn.infrastructure.scripts
 
 import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory
+import org.onap.so.client.HttpClientFactory
 
 import javax.ws.rs.core.MediaType
 import javax.ws.rs.core.Response
@@ -44,7 +45,6 @@ import org.onap.so.bpmn.core.RollbackData
 import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.bpmn.core.WorkflowException
 import org.onap.so.bpmn.core.domain.VnfResource
-import org.onap.so.bpmn.core.json.DecomposeJsonUtil
 import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.HttpClient
 import org.onap.so.client.aai.AAIObjectPlurals
@@ -79,6 +79,7 @@ public class DoCreateVfModule extends VfModuleBase {
        JsonUtils jsonUtil = new JsonUtils()
        SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
        CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create()
+       private final HttpClientFactory httpClientFactory = new HttpClientFactory()
 
        /**
         * Validates the request message and sets up the workflow.
@@ -641,7 +642,7 @@ public class DoCreateVfModule extends VfModuleBase {
                        String endPoint = aaiUriUtil.createAaiUri(uri)
 
                        try {
-                               HttpClient client = new HttpClient(new URL(endPoint), MediaType.APPLICATION_XML, TargetEntity.AAI)
+                               HttpClient client = httpClientFactory.newXmlClient(new URL(endPoint), TargetEntity.AAI)
                                client.addAdditionalHeader('X-TransactionId', UUID.randomUUID().toString())
                                client.addAdditionalHeader('X-FromAppId', 'MSO')
                                client.addAdditionalHeader('Content-Type', MediaType.APPLICATION_XML)
@@ -723,7 +724,7 @@ public class DoCreateVfModule extends VfModuleBase {
                        AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, vnfId).queryParam("vf-module-name",vfModuleName)
                        String endPoint = aaiUriUtil.createAaiUri(uri)
 
-                       HttpClient client = new HttpClient(new URL(endPoint), MediaType.APPLICATION_XML, TargetEntity.AAI)
+                       HttpClient client = httpClientFactory.newXmlClient(new URL(endPoint), TargetEntity.AAI)
                        client.addAdditionalHeader('X-TransactionId', UUID.randomUUID().toString())
                        client.addAdditionalHeader('X-FromAppId', 'MSO')
                        client.addAdditionalHeader('Content-Type', MediaType.APPLICATION_XML)
index 5f50afa..48f255b 100644 (file)
  */
 package org.onap.so.bpmn.infrastructure.scripts
 
-import org.onap.so.logger.MsoLogger
-
-import static org.apache.commons.lang3.StringUtils.*;
-
-import javax.ws.rs.core.Response
-import javax.xml.parsers.DocumentBuilder
-import javax.xml.parsers.DocumentBuilderFactory
-
-import org.apache.commons.lang3.*
+import groovy.json.JsonOutput
+import groovy.json.JsonSlurper
+import org.apache.commons.lang3.StringUtils
 import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.delegate.DelegateExecution
 import org.json.JSONArray
 import org.json.JSONObject
-
 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 import org.onap.so.bpmn.common.scripts.MsoUtils
+import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.bpmn.core.WorkflowException
 import org.onap.so.bpmn.core.domain.Resource
 import org.onap.so.bpmn.core.domain.ServiceDecomposition
-import org.onap.so.bpmn.core.UrnPropertiesReader
-
-import org.onap.so.utils.TargetEntity
 import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
+import org.onap.so.logger.MsoLogger
+import org.onap.so.utils.TargetEntity
 import org.springframework.web.util.UriUtils
 import org.w3c.dom.Document
-import org.w3c.dom.Element
 import org.w3c.dom.Node
-import org.w3c.dom.NodeList
 import org.xml.sax.InputSource
 
-import groovy.json.*
+import javax.ws.rs.core.Response
+import javax.xml.parsers.DocumentBuilder
+import javax.xml.parsers.DocumentBuilderFactory
+
+import static org.apache.commons.lang3.StringUtils.isBlank
 
 /**
  * This groovy class supports the <class>DoDeleteE2EServiceInstance.bpmn</class> process.
@@ -347,7 +343,7 @@ public class DoDeleteE2EServiceInstance extends AbstractServiceTaskProcessor {
                String serviceAaiPath = "${aai_endpoint}${urlLink}"
 
                URL url = new URL(serviceAaiPath)
-               HttpClient client = new HttpClient(url, "application/xml", TargetEntity.AAI)
+               HttpClient client = new HttpClientFactory().newXmlClient(url, TargetEntity.AAI)
 
 
                Response response = client.get()
index ca4643d..c95704e 100644 (file)
@@ -34,6 +34,7 @@ import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.bpmn.core.WorkflowException
 import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
 import org.onap.so.client.aai.AAIObjectType
 import org.onap.so.client.aai.entities.AAIResultWrapper
 import org.onap.so.client.aai.entities.Relationships
@@ -449,7 +450,7 @@ public class DoDeleteNetworkInstance extends AbstractServiceTaskProcessor {
                        String vnfAdapterRequest = execution.getVariable(Prefix + "deleteNetworkRequest")
 
                        URL url = new URL(vnfAdapterUrl)
-                       HttpClient httpClient = new HttpClient(url, "application/xml", TargetEntity.OPENSTACK_ADAPTER)
+                       HttpClient httpClient = new HttpClientFactory().newXmlClient(url, TargetEntity.OPENSTACK_ADAPTER)
                        httpClient.addAdditionalHeader("Authorization", execution.getVariable("BasicAuthHeaderValuePO"))
                        Response response = httpClient.delete(vnfAdapterRequest)
 
index ee094b0..6109d86 100644 (file)
@@ -26,10 +26,10 @@ import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
 import org.onap.so.client.aai.AAIObjectType
 import org.onap.so.client.aai.entities.uri.AAIResourceUri
 import org.onap.so.client.aai.entities.uri.AAIUriFactory
-import org.onap.so.logger.MessageEnum
 import org.onap.so.logger.MsoLogger
 import org.onap.so.utils.TargetEntity
 import org.onap.so.bpmn.core.UrnPropertiesReader
@@ -45,6 +45,7 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
     ExceptionUtil exceptionUtil = new ExceptionUtil()
 
     JsonUtils jsonUtil = new JsonUtils()
+    private final HttpClientFactory httpClientFactory = new HttpClientFactory()
 
     /**
      * Pre Process the BPMN Flow Request
@@ -222,7 +223,7 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
                        // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7'
             // user 'bepl' authHeader is the same with mso.db.auth
             String basicAuthValuedb =  UrnPropertiesReader.getVariable("mso.db.auth", execution)
-            HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
+            HttpClient httpClient = httpClientFactory.newJsonClient(url, TargetEntity.VNF_ADAPTER)
             httpClient.addAdditionalHeader("Accept", "application/json")
             httpClient.addAdditionalHeader("Authorization", basicAuthValuedb)
 
@@ -253,7 +254,7 @@ public class DoDeleteVFCNetworkServiceInstance extends AbstractServiceTaskProces
             // Get the Basic Auth credentials for the VFCAdapter, username is 'bpel', auth is '07a7159d3bf51a0e53be7a8f89699be7'
             // user 'bepl' authHeader is the same with mso.db.auth
             String basicAuthValuedb =  UrnPropertiesReader.getVariable("mso.db.auth", execution)
-            HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
+            HttpClient httpClient = httpClientFactory.newJsonClient(url, TargetEntity.VNF_ADAPTER)
             httpClient.addAdditionalHeader("Accept", "application/json")
             httpClient.addAdditionalHeader("Authorization", basicAuthValuedb)
 
index a99f6e9..19d30bb 100644 (file)
@@ -29,8 +29,9 @@ import org.onap.so.bpmn.common.scripts.ExceptionUtil
 import org.onap.so.bpmn.core.json.JsonUtils
 
 import org.camunda.bpm.engine.delegate.BpmnError
-import org.camunda.bpm.engine.runtime.Execution
 import com.fasterxml.jackson.databind.ObjectMapper
+import org.onap.so.client.HttpClientFactory
+
 import javax.ws.rs.core.Response
 
 import org.onap.so.bpmn.infrastructure.vfcmodel.ScaleResource
@@ -201,7 +202,7 @@ public class DoScaleVFCNetworkServiceInstance extends AbstractServiceTaskProcess
         try{
                        URL url = new URL(urlString);
 
-                       HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.VNF_ADAPTER)
+            HttpClient httpClient = new HttpClientFactory().newJsonClient(url, TargetEntity.VNF_ADAPTER)
                        httpClient.addAdditionalHeader("Authorization", "Basic QlBFTENsaWVudDpwYXNzd29yZDEk")
 
                        apiResponse = httpClient.post(requestBody)
index 7fdbb5c..9eb05cf 100644 (file)
@@ -20,9 +20,8 @@
 
 package org.onap.so.bpmn.infrastructure.scripts
 
-import static org.apache.commons.lang3.StringUtils.*;
+import org.onap.so.client.HttpClientFactory
 
-import javax.ws.rs.core.MediaType
 import javax.ws.rs.core.Response
 import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.delegate.DelegateExecution;
@@ -30,21 +29,18 @@ import org.onap.so.bpmn.common.scripts.AaiUtil
 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 import org.onap.so.bpmn.common.scripts.MsoUtils
-import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.bpmn.core.domain.ModelInfo
 import org.onap.so.bpmn.core.domain.ModuleResource
 import org.onap.so.bpmn.core.domain.VnfResource
 import org.onap.so.bpmn.core.json.JsonUtils
 import org.onap.so.client.graphinventory.entities.uri.Depth
 import org.onap.so.client.HttpClient
-import org.onap.so.client.aai.AAIObjectType;
-import org.onap.so.client.aai.AAIResourcesClient
+import org.onap.so.client.aai.AAIObjectType
 import org.onap.so.client.aai.entities.uri.AAIResourceUri
 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
 import org.onap.so.logger.MessageEnum
 import org.onap.so.logger.MsoLogger
 import org.onap.so.utils.TargetEntity
-import org.springframework.web.util.UriUtils;
 
 /**
  * This class supports the VID Flow
@@ -163,7 +159,7 @@ class DoUpdateVnfAndModules extends AbstractServiceTaskProcessor {
                        msoLogger.debug("AAI endPoint: " + endPoint)
 
                        try {
-                               HttpClient client = new HttpClient(new URL(endPoint), MediaType.APPLICATION_XML, TargetEntity.AAI)
+                               HttpClient client = new HttpClientFactory().newXmlClient(new URL(endPoint), TargetEntity.AAI)
                                client.addAdditionalHeader('X-TransactionId', UUID.randomUUID().toString())
                                client.addAdditionalHeader('X-FromAppId', 'MSO')
                                client.addAdditionalHeader('Content-Type', 'application/xml')
index 66e970a..6f13a86 100644 (file)
@@ -34,10 +34,10 @@ public class HttpClient extends RestClient {
 
        protected final Logger log = LoggerFactory.getLogger(HttpClient.class);
     private TargetEntity targetEntity;
-       public HttpClient(URL host, String contentType, TargetEntity targetEntity) {
+
+    HttpClient(URL host, String contentType, TargetEntity targetEntity) {
                super(host, contentType);
                this.targetEntity = targetEntity;
-
        }
 
     @Override
index 9705d7d..d02c18f 100644 (file)
 package org.onap.so.client;
 
 import java.net.URL;
+import javax.ws.rs.core.MediaType;
 import org.onap.so.utils.TargetEntity;
 
 public class HttpClientFactory {
 
-    public HttpClient create(URL host, String contentType, TargetEntity targetEntity) {
-        return new HttpClient(host, contentType, targetEntity);
+    public HttpClient newJsonClient(URL host, TargetEntity targetEntity) {
+        return new HttpClient(host, MediaType.APPLICATION_JSON, targetEntity);
+    }
+
+    public HttpClient newXmlClient(URL host, TargetEntity targetEntity) {
+        return new HttpClient(host, MediaType.APPLICATION_XML, targetEntity);
+    }
+
+    public HttpClient newTextXmlClient(URL host, TargetEntity targetEntity) {
+        return new HttpClient(host, MediaType.TEXT_XML, targetEntity);
     }
 }
index 221005c..75ce5f3 100644 (file)
@@ -30,22 +30,21 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
 import static com.github.tomakehurst.wiremock.client.WireMock.verify;
 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
 
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
 import java.net.MalformedURLException;
 import java.net.URL;
-
 import org.junit.Rule;
 import org.junit.Test;
 import org.onap.so.utils.TargetEntity;
 
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
-
 public class HttpClientTest{
 
 
+       private final HttpClientFactory httpClientFactory = new HttpClientFactory();
        @Rule
        public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicHttpsPort());
 
-    @Test(expected = Test.None.class)
+       @Test
        public void testPost_success() throws MalformedURLException{
 
         stubFor(post(urlEqualTo("/services/sdnc/post"))
@@ -54,7 +53,7 @@ public class HttpClientTest{
                 .withBody("")));
 
       URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post");
-      HttpClient client = new HttpClient(url, "application/json", TargetEntity.BPMN);
+      HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN);
 
          client.addBasicAuthHeader("97FF88AB352DA16E00DDD81E3876431DEF8744465DACA489EB3B3BE1F10F63EDA1715E626D0A4827A3E19CD88421BF", "123");
          client.addAdditionalHeader("Accept", "application/json");
@@ -64,7 +63,7 @@ public class HttpClientTest{
          verify(exactly(1), postRequestedFor(urlEqualTo("/services/sdnc/post")));
        }
 
-    @Test(expected = Test.None.class)
+    @Test
        public void testPost_nullHeader() throws MalformedURLException{
 
         stubFor(post(urlEqualTo("/services/sdnc/post"))
@@ -73,7 +72,7 @@ public class HttpClientTest{
                 .withBody("")));
 
       URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post");
-      HttpClient client = new HttpClient(url, "application/json", TargetEntity.BPMN);
+      HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN);
 
          client.addAdditionalHeader("Accept", "application/json");
          client.addAdditionalHeader("id", null);
@@ -84,7 +83,7 @@ public class HttpClientTest{
                          .withHeader("Accept", equalTo("application/json")));
        }
 
-    @Test(expected = Test.None.class)
+    @Test
        public void testPost_nullBasicAuth() throws MalformedURLException{
 
         stubFor(post(urlEqualTo("/services/sdnc/post"))
@@ -93,7 +92,7 @@ public class HttpClientTest{
                 .withBody("")));
 
       URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post");
-      HttpClient client = new HttpClient(url, "application/json", TargetEntity.BPMN);
+      HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN);
 
       client.addBasicAuthHeader("", "12345");
          client.addAdditionalHeader("Accept", "application/json");
index 6fca4a1..06196fd 100644 (file)
@@ -47,11 +47,12 @@ import org.mockito.junit.MockitoJUnitRunner;
 @RunWith(MockitoJUnitRunner.class)
 public class RestClientTest {
 
-       
+
+       private final HttpClientFactory httpClientFactory = new HttpClientFactory();
        @Mock
        private RestProperties props;
-       
-       
+
+
        @Test
        public void retries() throws Exception {
                RestClient spy = buildSpy();
@@ -82,7 +83,8 @@ public class RestClientTest {
                
        }
        private RestClient buildSpy() throws MalformedURLException, IllegalArgumentException, UriBuilderException {
-               RestClient client = new HttpClient(UriBuilder.fromUri("http://localhost/test").build().toURL(), "application/json", TargetEntity.BPMN);
+               RestClient client = httpClientFactory
+                       .newJsonClient(UriBuilder.fromUri("http://localhost/test").build().toURL(), TargetEntity.BPMN);
                
                return spy(client);
        }
index 8a4d561..4e8e956 100644 (file)
@@ -21,9 +21,6 @@
 package org.onap.so.apihandlerinfra.tenantisolation.helpers;
 
 import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
 
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
@@ -36,6 +33,7 @@ import org.onap.so.apihandlerinfra.exceptions.ApiException;
 import org.onap.so.apihandlerinfra.exceptions.ValidateException;
 import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
 import org.onap.so.client.HttpClient;
+import org.onap.so.client.HttpClientFactory;
 import org.onap.so.logger.MessageEnum;
 import org.onap.so.logger.MsoLogger;
 import org.onap.so.utils.CryptoUtils;
@@ -53,6 +51,7 @@ public class SDCClientHelper {
 
        private static String MESSAGE_UNDEFINED_ERROR = "Undefined Error Message!";
        private static String MESSAGE_UNEXPECTED_FORMAT = "Unexpected response format from SDC.";
+       private final HttpClientFactory httpClientFactory = new HttpClientFactory();
 
        @Value("${mso.sdc.endpoint}")
        private String sdcEndpoint;
@@ -91,7 +90,7 @@ public class SDCClientHelper {
 
                        URL url = new URL(urlString);
 
-                       HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.SDC);
+                       HttpClient httpClient = httpClientFactory.newJsonClient(url, TargetEntity.SDC);
                        httpClient.addBasicAuthHeader(sdcClientAuth, msoKey);
 
                        Response apiResponse = setHttpPostResponse(httpClient, jsonPayload);