X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=PolicyEngineClient%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2FpolicyEngine%2FClosedLoopPolicyClient.java;h=a54030b94c4763aa4bacac638fee614bd76a9651;hp=4f0926cca58e6132b574d187fac9af6fea440382;hb=fc5c07705edc4dcb7083b39116a43844bb6a1490;hpb=d9007d680d19734d5dc106479784c420236cca4b diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyClient.java index 4f0926cca..a54030b94 100644 --- a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyClient.java +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyClient.java @@ -23,6 +23,7 @@ package org.openecomp.policyEngine; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.nio.file.Path; @@ -49,20 +50,26 @@ public class ClosedLoopPolicyClient { //Builds JSONObject from File private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException { JsonObject json = null;; - + JsonReader jsonReader = null; if (jsonString != null && jsonInput == null) { StringReader in = null; in = new StringReader(jsonString); - JsonReader jsonReader = Json.createReader(in); + jsonReader = Json.createReader(in); json = jsonReader.readObject(); - } - else { + in.close(); + }else { InputStream in = null; in = new FileInputStream(jsonInput); - JsonReader jsonReader = Json.createReader(in); + jsonReader = Json.createReader(in); json = jsonReader.readObject(); + try { + in.close(); + } catch (IOException e) { + System.err.println("Exception Occured while closing input stream"+e); + } } - + jsonReader.close(); + return json; } public static void main(String[] args) { @@ -78,10 +85,9 @@ public class ClosedLoopPolicyClient { // Set up Micro Services Attributes File jsonFile = null; String MSjsonString= null; - if (MSjsonString == null) { - Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\faultTestJson.json"); - jsonFile = file.toFile(); - } + Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\faultTestJson.json"); + jsonFile = file.toFile(); + policyParameters.setConfigBody(buildJSON(jsonFile, MSjsonString).toString()); policyParameters.setConfigBodyType(PolicyType.JSON);