From 1b6cf61e10678539215aa95247ac59a7ab7143eb Mon Sep 17 00:00:00 2001 From: Oleksandr Moliavko Date: Thu, 8 Aug 2019 09:34:45 +0300 Subject: Added null check for listFiles() result to prevent crash at iterating through file list; replaced System.out.println calls with logger calls Issue-ID: SO-1841 Signed-off-by: Oleksandr Moliavko Change-Id: I6b4a49228903f013127b39244db9d1b67c0ff2f0 --- .../bpmn/activity/DeployActivitySpecs.java | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/bpmn/so-bpmn-building-blocks/src/main/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecs.java b/bpmn/so-bpmn-building-blocks/src/main/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecs.java index e4f1998c40..12f30cfa58 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecs.java +++ b/bpmn/so-bpmn-building-blocks/src/main/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecs.java @@ -31,6 +31,8 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; import org.springframework.stereotype.Component; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Component public class DeployActivitySpecs { @@ -38,10 +40,12 @@ public class DeployActivitySpecs { private static final String ACTIVITY_SPEC_URI = "/activityspec-api/v1.0/activity-spec"; private static final String CONTENT_TYPE_JSON = "application/json"; + private static final Logger logger = LoggerFactory.getLogger(DeployActivitySpecs.class); + public static void main(String[] args) throws Exception { if (args == null || args.length == 0) { - System.out.println("Please specify hostname argument"); + logger.info("Please specify hostname argument"); return; } @@ -49,20 +53,23 @@ public class DeployActivitySpecs { File dir = new File(ACTIVITY_FILE_LOCATION); if (!dir.isDirectory()) { - System.out.println("ActivitySpec store is not a directory"); + logger.debug("ActivitySpec store is not a directory"); return; } - for (File f : dir.listFiles()) { - String activitySpecName = f.getName(); - String errorMessage = deployActivitySpec(hostname, activitySpecName); - if (errorMessage == null) { - System.out.println("Deployed Activity Spec: " + activitySpecName); - } else { - System.out.println("Error deploying Activity Spec: " + activitySpecName + " : " + errorMessage); + if (dir.listFiles() != null) { + for (File f : dir.listFiles()) { + String activitySpecName = f.getName(); + String errorMessage = deployActivitySpec(hostname, activitySpecName); + if (errorMessage == null) { + logger.debug("Deployed Activity Spec: " + activitySpecName); + } else { + logger.error("Error deploying Activity Spec: " + activitySpecName + " : " + errorMessage); + } } + } else { + logger.error("Null file list for Activity Specs."); } - return; } protected static String deployActivitySpec(String hostname, String activitySpecName) throws Exception { -- cgit 1.2.3-korg