Resubmitting KeyProperty code change since tests failed
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / service / ApplicationsRestClientServiceImpl.java
index 18dabfb..ab504fb 100644 (file)
@@ -67,6 +67,8 @@ import org.onap.portalapp.util.SystemType;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.onboarding.util.KeyConstants;
+import org.onap.portalsdk.core.onboarding.util.KeyProperties;
 import org.onap.portalsdk.core.util.SystemProperties;
 import org.slf4j.MDC;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -133,7 +135,7 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
                logger.debug(EELFLoggerDelegate.debugLogger, "http response status=" + status);
                MDC.put(EPCommonSystemProperties.EXTERNAL_API_RESPONSE_CODE, Integer.toString(status));
                if (!isHttpSuccess(status)) {
-                       String errMsg = "Failed. Status=" + status + restPath +"; [" + ((ResponseImpl)response).getStatusInfo().getReasonPhrase().toString()
+                       String errMsg = "Failed. Status=" + status + restPath +"; [" + ((ResponseImpl)response).getStatusInfo().getReasonPhrase()
                                        + "]";
                        URL url = null;
                        try {
@@ -176,8 +178,8 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
                
                if (externalApp != null) {
                        String appBaseUri = (type == SystemType.APPLICATION) ? externalApp.getAppRestEndpoint() : "";
-                       String username = (type == SystemType.APPLICATION) ? externalApp.getUsername(): "";
-                       String encriptedPwd = (type == SystemType.APPLICATION) ? externalApp.getAppPassword(): "";
+                       String username = (type == SystemType.APPLICATION) ? externalApp.getAppBasicAuthUsername(): "";
+                       String encriptedPwd = (type == SystemType.APPLICATION) ? externalApp.getAppBasicAuthPassword(): "";
 
                        String appName = (type == SystemType.APPLICATION) ? externalApp.getName(): "";
                        String decreptedAppPwd = StringUtils.EMPTY;
@@ -194,7 +196,7 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
                        if(!encriptedPwd.isEmpty() || encriptedPwd != null || StringUtils.isEmpty(encriptedPwd)){
                        try {
                                decreptedAppPwd = CipherUtil.decryptPKC(encriptedPwd,
-                                               SystemProperties.getProperty(SystemProperties.Decryption_Key));
+                                               KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY));
                        } catch (Exception e) {
                                logger.error(EELFLoggerDelegate.errorLogger, "createClientFor failed to decrypt", e);
                        }
@@ -202,20 +204,20 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
                        WebClient client = createClientForPath(appBaseUri, restPath);
                        
                        
-                       if(externalApp.getAppPassword().isEmpty() || externalApp.getAppPassword()==null){
+                       if(externalApp.getAppBasicAuthPassword().isEmpty() || externalApp.getAppBasicAuthPassword()==null){
                                logger.debug(EELFLoggerDelegate.debugLogger, "Entering in the externalApp get app password contains null : {}");
 
                                externalApp = appsCacheService.getApp(1L);
                                logger.debug(EELFLoggerDelegate.debugLogger, "external App Information : {}",externalApp);
 
-                               String mechidUsername=externalApp.getUsername();
+                               String mechidUsername=externalApp.getAppBasicAuthUsername();
                                logger.debug(EELFLoggerDelegate.debugLogger, "external App mechidUsername Information : {}",mechidUsername);
 
-                               String password=externalApp.getAppPassword();
+                               String password=externalApp.getAppBasicAuthPassword();
                                String decreptedexternalAppPwd = StringUtils.EMPTY;
                                try {
                                        decreptedexternalAppPwd = CipherUtil.decryptPKC(password,
-                                                       SystemProperties.getProperty(SystemProperties.Decryption_Key));
+                                                       KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY));
                                } catch (CipherUtilException e) {
                                        logger.error(EELFLoggerDelegate.errorLogger, "failed to decreptedexternalAppPwd when external app pwd is null", e);
                                }
@@ -255,7 +257,6 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
                Response response = getResponse(appId, restPath);
 
                if (response != null) {
-                       //verifyResponse(response);
                        verifyResponse(response,restPath);
                        /* It is not recommendable to use the implementation class org.apache.cxf.jaxrs.impl.ResponseImpl in the code, 
                        but had to force this in-order to prevent conflict with the ResponseImpl class of Jersey Client which 
@@ -278,13 +279,11 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
                Response response = getResponse(appId, restPath);
 
                if (response != null) {
-                       //verifyResponse(response);
                        verifyResponse(response,restPath);
                        /* It is not recommendable to use the implementation class org.apache.cxf.jaxrs.impl.ResponseImpl in the code, 
                        but had to force this in-order to prevent conflict with the ResponseImpl class of Jersey Client which 
                        doesn't work as expected. Created Portal-253 for tracking  */
-                       String incomingJson = ((ResponseImpl)response).readEntity(String.class);
-                       return incomingJson;
+                       return ((ResponseImpl)response).readEntity(String.class);
                }
                
                return "";
@@ -308,7 +307,6 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
                Response response = getResponse(appId, restPath);
 
                if (response != null) {
-                       //verifyResponse(response);
                        verifyResponse(response,restPath);
                        String str = ((ResponseImpl)response).readEntity(String.class);
                        EcompPortalUtils.logAndSerializeObject(logger, restPath, "GET result =", str);
@@ -316,7 +314,6 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
                        try {
                                t = mapper.readValue(str, clazz);
                        } catch (Exception e) {
-                               e.printStackTrace();
                                EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeInvalidJsonInput, e);
                        }
                }
@@ -373,16 +370,12 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
                }
 
                if (response != null) {
-                       //verifyResponse(response);
                        verifyResponse(response,restPath);
-                       // String contentType = response.getHeaderString("Content-Type");
                        if (clazz != null) {
                                String str = ((ResponseImpl)response).readEntity(String.class);
                                EcompPortalUtils.logAndSerializeObject(logger, restPath, "POST result =", str);
                                try {
                                        t = (T) gson.fromJson(str, clazz);
-
-                                       //t = gson.fromJson(str, clazz);
                                } catch (Exception e) {
                                        EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeInvalidJsonInput, e);
                                }
@@ -430,7 +423,6 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
                }
 
                if (response != null) {
-                       //verifyResponse(response);
                        verifyResponse(response,restPath);
                        String str = ((ResponseImpl)response).readEntity(String.class);
                        EcompPortalUtils.logAndSerializeObject(logger, restPath, "PUT result =", str);