Merge "Reduce vnf data response from A&AI in change management flows"
[vid.git] / vid-app-common / src / main / java / org / onap / vid / aai / PombaRestInterface.java
index c4bc852..e9895e6 100644 (file)
@@ -2,15 +2,16 @@
  * ============LICENSE_START=======================================================
  * VID
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2018 Nokia. All rights reserved.
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 - 2019 Nokia. All rights reserved.
+ * Modifications Copyright (C) 2019 IBM.
  * ================================================================================
  * 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.
 
 package org.onap.vid.aai;
 
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.vid.aai.util.*;
-import org.onap.vid.utils.Logging;
-import org.springframework.http.HttpMethod;
+import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
 
+import java.util.UUID;
 import javax.ws.rs.client.Client;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
-import java.util.UUID;
-
-import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.vid.aai.util.AAIRestInterface;
+import org.onap.vid.aai.util.HttpClientMode;
+import org.onap.vid.aai.util.HttpsAuthClient;
+import org.onap.vid.aai.util.ServletRequestHelper;
+import org.onap.vid.aai.util.SystemPropertyHelper;
+import org.onap.vid.utils.Logging;
+import org.springframework.http.HttpMethod;
 
 public class PombaRestInterface extends AAIRestInterface {
+       
+    private Client client = null;
 
-    public PombaRestInterface (HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
-        super(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
+    public PombaRestInterface (HttpsAuthClient httpsAuthClientFactory,
+        ServletRequestHelper servletRequestHelper,
+        SystemPropertyHelper systemPropertyHelper,
+        Logging loggingService) {
+        super(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper, loggingService);
     }
 
-    private Client client = null;
-
-    private void initRestClient()
+    @Override
+    protected void initRestClient()
     {
         if (client == null) {
             try {
-                client = httpsAuthClientFactory.getClient(HttpClientMode.UNSECURE);
+                client = httpsAuthClientFactory.getClient(HttpClientMode.WITH_KEYSTORE);
             }
             catch (Exception e) {
-                logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient" + e.toString());
-                logger.debug(EELFLoggerDelegate.debugLogger, "Exception in REST call to DB : " + e.toString());
+                logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient", e);
+                logger.debug(EELFLoggerDelegate.debugLogger, "Exception in REST call to DB : ", e);
             }
         }
     }
@@ -62,7 +70,7 @@ public class PombaRestInterface extends AAIRestInterface {
         try {
             initRestClient();
 
-            Logging.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, payload);
+            loggingService.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, payload);
             final Response cres = client.target(url)
                     .request()
                     .accept(MediaType.APPLICATION_JSON)
@@ -70,7 +78,7 @@ public class PombaRestInterface extends AAIRestInterface {
                     .header(FROM_APP_ID_HEADER,  fromAppId)
                     .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
                     .post(Entity.entity(payload, MediaType.APPLICATION_JSON));
-            Logging.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, cres);
+            loggingService.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, cres);
 
             if (cres.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) {
                 logger.info(EELFLoggerDelegate.errorLogger, getValidResponseLogMessage(methodName));
@@ -78,6 +86,7 @@ public class PombaRestInterface extends AAIRestInterface {
             } else {
                 logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, cres));
             }
+            return cres;
         } catch (Exception e) {
             logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
         }