X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ECOMP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcomponents%2FPolicy.java;h=536f8e6b35739b85cbd016939b7cdcb49069c7c4;hb=fc5c07705edc4dcb7083b39116a43844bb6a1490;hp=0f8ccfba01094e9b4f3098386abb910004534511;hpb=a330af579866dacbe595e2e4ad1dd29cd3c96945;p=policy%2Fengine.git diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java index 0f8ccfba0..536f8e6b3 100644 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java @@ -35,15 +35,12 @@ import java.util.Map; import javax.json.Json; import javax.json.JsonReader; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; - import org.apache.commons.io.FilenameUtils; import org.json.JSONObject; import org.openecomp.policy.common.logging.eelf.MessageCodes; import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; import org.openecomp.policy.rest.XACMLRestProperties; import org.openecomp.policy.rest.adapter.PolicyRestAdapter; import org.openecomp.policy.xacml.util.XACMLPolicyWriter; @@ -53,7 +50,15 @@ import com.att.research.xacml.util.XACMLProperties; import com.att.research.xacmlatt.pdp.policy.PolicyDef; import com.att.research.xacmlatt.pdp.policy.dom.DOMPolicyDef; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; + public abstract class Policy { + + private static final Logger LOGGER = FlexLogger.getLogger(Policy.class); + /** * Common Fields @@ -113,7 +118,7 @@ public abstract class Policy { public static String ACTION_HOME = null; public static String CONFIG_URL = null; - protected Map performer = new HashMap(); + protected Map performer = new HashMap<>(); private static String actionHome = null; private static String configHome = null; @@ -158,7 +163,7 @@ public abstract class Policy { try { uri = new URI(key); } catch (URISyntaxException e) { - e.printStackTrace(); + LOGGER.error("Exception Occured"+e); } attributeDesignator.setCategory(CATEGORY_ACCESS_SUBJECT); attributeDesignator.setDataType(STRING_DATATYPE); @@ -184,7 +189,7 @@ public abstract class Policy { try { dynamicURI = new URI(key); } catch (URISyntaxException e) { - e.printStackTrace();// log msg + LOGGER.error("Exception Occured"+e);// log msg } dynamicAttributeDesignator.setCategory(CATEGORY_RESOURCE); dynamicAttributeDesignator.setDataType(dataType); @@ -205,13 +210,17 @@ public abstract class Policy { // Validation for json. protected static boolean isJSONValid(String data) { + JsonReader jsonReader = null; try { new JSONObject(data); InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); - JsonReader jsonReader = Json.createReader(stream); + jsonReader = Json.createReader(stream); System.out.println("Json Value is: " + jsonReader.read().toString() ); } catch (Exception e) { + LOGGER.error("Exception Occured while reading json"+e); return false; + }finally{ + jsonReader.close(); } return true; } @@ -282,7 +291,7 @@ public abstract class Policy { //create policy once all the validations are completed protected Map createPolicy(final Path policyPath, final Object policyData) { - Map success = new HashMap(); + Map success = new HashMap<>(); // // Is the root a PolicySet or Policy? // @@ -303,6 +312,12 @@ public abstract class Policy { } } catch (Exception e) { success.put("error", "Validation Failed"); + }finally{ + try { + inputStream.close(); + } catch (IOException e) { + LOGGER.error("Exception Occured while closing the input stream"+e); + } } } else { PolicyLogger.error("Unknown data type sent back.");