Fix minor issues
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / scheduler / client / HttpsBasicClient.java
index 857bec3..c79d6c0 100644 (file)
@@ -4,6 +4,8 @@
  * ===================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
  *
  * Unless otherwise specified, all software contained herein is licensed
  * under the Apache License, Version 2.0 (the "License");
@@ -39,7 +41,6 @@
 package org.onap.portalapp.portal.scheduler.client;
 
 import java.io.File;
-import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
@@ -55,8 +56,8 @@ import org.glassfish.jersey.client.ClientConfig;
 import org.glassfish.jersey.client.ClientProperties;
 import org.onap.portalapp.portal.scheduler.SchedulerProperties;
 import org.onap.portalapp.portal.scheduler.util.CustomJacksonJaxBJsonProvider;
+import org.onap.portalapp.util.DateUtil;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.util.SystemProperties;
 
  /**
   *  General SSL client using the VID tomcat keystore. It doesn't use client certificates.
@@ -66,10 +67,7 @@ public class HttpsBasicClient{
        
        /** The logger. */
        static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpsBasicClient.class);
-       
-       /** The Constant dateFormat. */
-       final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
-       
+
        /**
         * Retrieve an SSL client.
         *
@@ -79,32 +77,35 @@ public class HttpsBasicClient{
        public static Client getClient() throws Exception {
                String methodName = "getClient";
                ClientConfig config = new ClientConfig();
-               //config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-               //config.getClasses().add(org.onap.aai.util.CustomJacksonJaxBJsonProvider.class);
+
        
                SSLContext ctx = null;
                
                try {
-                       
+
+                       SimpleDateFormat dateFormat = DateUtil.getDateFormat();
                        config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
                        
-                       String truststore_path = SchedulerProperties.getProperty(SchedulerProperties.VID_TRUSTSTORE_FILENAME);
-                       logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " truststore_path=" + truststore_path);
-                       String truststore_password = SchedulerProperties.getProperty(SchedulerProperties.VID_TRUSTSTORE_PASSWD_X);
+                       String truststorePath = SchedulerProperties.getProperty(SchedulerProperties.VID_TRUSTSTORE_FILENAME);
+                       logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " "
+                               + "truststore_path=" +
+                               truststorePath);
+                       String truststorePassword = SchedulerProperties.getProperty(SchedulerProperties.VID_TRUSTSTORE_PASSWD_X);
                        
                        
-                       String decrypted_truststore_password = Password.deobfuscate(truststore_password);
+                       String decryptedTruststorePassword = Password.deobfuscate(truststorePassword);
                        //logger.debug(dateFormat.format(new Date()) + " " + methodName + " decrypted_truststore_password=" + decrypted_truststore_password);
                        
-                       File tr = new File (truststore_path);
-                       logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " absolute truststore path=" + tr.getAbsolutePath());
+                       File tr = new File (truststorePath);
+                       logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " absolute "
+                               + "truststore path=" + tr.getAbsolutePath());
                        
                        //String keystore_path = certFilePath + AAIProperties.FILESEPARTOR + SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_FILENAME);
                        //String keystore_password = SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_PASSWD_X);
                        //String decrypted_keystore_password = EncryptedPropValue.decryptTriple(keystore_password);
                        
-                   System.setProperty("javax.net.ssl.trustStore", truststore_path);
-                   System.setProperty("javax.net.ssl.trustStorePassword", decrypted_truststore_password);
+                   System.setProperty("javax.net.ssl.trustStore", truststorePath);
+                   System.setProperty("javax.net.ssl.trustStorePassword", decryptedTruststorePassword);
                        HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){
                            public boolean verify(String string,SSLSession ssls) {
                                return true;
@@ -132,9 +133,7 @@ public class HttpsBasicClient{
                        ctx.init(kmf.getKeyManagers(), null, null);
                        */
                        ctx.init(null, null, null);
-                       //config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, 
-                       //                                                      new HTTPSProperties( , ctx));
-                       
+
                        return ClientBuilder.newBuilder()
                                .sslContext(ctx)
                                .hostnameVerifier(new HostnameVerifier() {
@@ -146,17 +145,9 @@ public class HttpsBasicClient{
                                .build()
                                .register(CustomJacksonJaxBJsonProvider.class);
                        
-               } catch (Exception e) {
-                       logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up config: exiting");
-                       //System.out.println("Error setting up config: exiting");
-                       e.printStackTrace();
-                       return null;
-               }
-                       
-               //Client client = ClientBuilder.newClient(config);
-               // uncomment this line to get more logging for the request/response
-               // client.addFilter(new LoggingFilter(System.out));
-               
-               //return client;
-       }
-}  
+        } catch (Exception e) {
+            logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up config: exiting", e);
+            return null;
+        }
+    }
+}