Correct the http client auth issue 80/73780/1
authorseshukm <seshu.kumar.m@huawei.com>
Wed, 28 Nov 2018 12:06:29 +0000 (20:06 +0800)
committerseshukm <seshu.kumar.m@huawei.com>
Wed, 28 Nov 2018 12:08:21 +0000 (20:08 +0800)
Issue-ID: SO-1257

Change-Id: Iac3cf2cf594b9b3224b5741d8589c7d3b9c5e205
Signed-off-by: seshukm <seshu.kumar.m@huawei.com>
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java

index b4851ee..5e05637 100644 (file)
@@ -47,6 +47,9 @@ 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.rest.APIResponse;
+import org.onap.so.rest.RESTClient;
+import org.onap.so.rest.RESTConfig;
 import org.onap.so.utils.TargetEntity;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -261,10 +264,20 @@ 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);
-       
-        Response response = client.get();
-        String value = response.readEntity(String.class);
+
+        RESTClient restClient = new RESTClient(new RESTConfig(
+                UriBuilder.fromUri(catalogEndPoint)
+                        .path(SERVICE_URL_TOSCA_CSAR)
+                        .queryParam("serviceModelUuid", uuid)
+                        .build().toURL().toString()
+        ));
+
+        restClient.addHeader("Accept", "application/json");
+        restClient.addAuthorizationHeader(UrnPropertiesReader.getVariable("mso.db.auth"));
+
+        APIResponse apiResponse = restClient.httpGet();
+
+        String value = apiResponse.getResponseBodyAsString();
 
         HashMap<String, String> map = new Gson().fromJson(value, new TypeToken<HashMap<String, String>>() {}.getType());