ResPost Update for aai-traversal 11/5811/1
authorUbuntu <brian.matt@windstream.com>
Fri, 14 Jul 2017 12:27:48 +0000 (12:27 +0000)
committerUbuntu <brian.matt@windstream.com>
Fri, 14 Jul 2017 12:36:01 +0000 (12:36 +0000)
Change-Id: I2a4ac963ac6db95e11315f3f96daab8a157ec832
Signed-off-by: Ubuntu <brian.matt@windstream.com>
vid-app-common/src/main/java/org/openecomp/aai/util/AAIRestInterface.java

index fa4eefc..cd50951 100755 (executable)
@@ -1,9 +1,9 @@
 /*-\r
- * ============LICENSE_START=======================================================
- * VID
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+ * ============LICENSE_START=======================================================\r
+ * VID\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
@@ -14,7 +14,7 @@
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
  * See the License for the specific language governing permissions and\r
- * limitations under the License.
+ * limitations under the License.\r
  * ============LICENSE_END=========================================================\r
  */\r
 package org.openecomp.aai.util;\r
@@ -276,17 +276,43 @@ public class AAIRestInterface {
                if (xml)\r
                        responseType = "application/xml";\r
                   \r
-            initRestClient();    \r
+            initRestClient();\r
+\r
+                       String clientCert = SystemProperties.getProperty(AAIProperties.AAI_USE_CLIENT_CERT);\r
+\r
+                       boolean useClientCert = false;\r
+                       if (clientCert != null &&\r
+                                       SystemProperties.getProperty(AAIProperties.AAI_USE_CLIENT_CERT).equalsIgnoreCase("true")) {\r
+                               useClientCert  = true;\r
+                       }\r
     \r
             url = SystemProperties.getProperty(AAIProperties.AAI_SERVER_URL_BASE) + path;\r
 \r
-            final Response cres = client.target(url)\r
-                 .request()\r
-                 .accept(responseType)\r
-                 .header("X-TransactionId", transId)\r
-                 .header("X-FromAppId",  fromAppId)\r
-                 .post(Entity.entity(payload, MediaType.APPLICATION_JSON));\r
-            \r
+            final Response cres;\r
+                       if (useClientCert == true) {\r
+                               cres = client.target(url)\r
+                                               .request()\r
+                                               .accept(responseType)\r
+                                               .header("X-TransactionId", transId)\r
+                                               .header("X-FromAppId",  fromAppId)\r
+                                               .header("Content-Type", "application/json")\r
+                                               .post(Entity.entity(payload, MediaType.APPLICATION_JSON));\r
+                       } else {\r
+\r
+                               String vidUsername = SystemProperties.getProperty(AAIProperties.AAI_VID_USERNAME);\r
+                               String vidPassword = Password.deobfuscate(SystemProperties.getProperty(AAIProperties.AAI_VID_PASSWD_X));\r
+                               String encodeThis = vidUsername + ":" + vidPassword;\r
+\r
+                               cres = client.target(url)\r
+                                               .request()\r
+                                               .accept(responseType)\r
+                                               .header("X-TransactionId", transId)\r
+                                               .header("X-FromAppId", fromAppId)\r
+                                               .header("Content-Type", "application/json")\r
+                                               .header("Authorization", "Basic " + Base64.getEncoder().encodeToString(encodeThis.getBytes("utf-8")))\r
+                                               .post(Entity.entity(payload, MediaType.APPLICATION_JSON));\r
+                       }\r
+\r
                if (cres.getStatus() == 200 && cres.getStatus() <= 299) {\r
                        logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " REST api POST was successful!");\r
                        logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " REST api POST was successful!");\r