summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2018-03-21 13:20:54 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-21 13:20:54 +0000
commite53bd66cc71fcc3f7dff762054790c382d7dd499 (patch)
treee457e55abfb060d978508e2480a368ea294dc929
parent6e00f46e0c2ee4dbbdb0e222e6f361210d1a0da1 (diff)
parenteef3c224cb6cad4b82a96938ade1e42ca881eea2 (diff)
Merge "Fix all bugs reported by Sonar in policy/engine"
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicy.java27
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ConfigPolicy.java15
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsRawPolicy.java14
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateClosedLoopPerformanceMetrics.java26
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java15
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java10
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/Policy.java1
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java30
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java4
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java122
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java2
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java11
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/getDictionaryTest.java2
-rw-r--r--ONAP-PDP/src/main/java/org/onap/policy/xacml/action/FindAction.java19
-rw-r--r--ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java12
15 files changed, 183 insertions, 127 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicy.java
index 8e9c4b659..7c05a31c6 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicy.java
@@ -70,27 +70,16 @@ public class ClosedLoopPolicy extends Policy {
//save configuration of the policy based on the policyname
private void saveConfigurations(String policyName, String jsonBody) {
- try {
+
+ if(policyName.endsWith(".xml")){
+ policyName = policyName.replace(".xml", "");
+ }
+ try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator+ policyName +".json")){
String body = jsonBody;
- try {
- try{
- //Remove the trapMaxAge in Verification Signature
- body = body.replace(",\"trapMaxAge\":null", "");
- }catch(Exception e){
- LOGGER.debug("No Trap Max Age in JSON body", e);
- }
- this.policyAdapter.setJsonBody(body);
- } catch (Exception e) {
- LOGGER.error("Exception Occured"+e);
- }
-
- if(policyName.endsWith(".xml")){
- policyName = policyName.replace(".xml", "");
- }
- PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator+ policyName +".json");
+ //Remove the trapMaxAge in Verification Signature
+ body = body.replace(",\"trapMaxAge\":null", "");
+ this.policyAdapter.setJsonBody(body);
out.println(body);
- out.close();
-
} catch (Exception e) {
LOGGER.error("Exception Occured while writing Configuration Data"+e);
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ConfigPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ConfigPolicy.java
index adcffe939..48eb784a7 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ConfigPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ConfigPolicy.java
@@ -80,17 +80,24 @@ public class ConfigPolicy extends Policy {
// Saving the Configurations file at server location for config policy.
protected void saveConfigurations(String policyName) {
+ BufferedWriter bw = null;
try {
String fileName = getConfigFile(policyName);
- FileWriter fw = new FileWriter(CONFIG_HOME + File.separator + fileName);
- BufferedWriter bw = new BufferedWriter(fw);
+ bw = new BufferedWriter(new FileWriter(CONFIG_HOME + File.separator + fileName));
bw.write(configBodyData);
- bw.close();
if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Configuration is succesfully saved");
+ LOGGER.debug("Configuration is succesfully saved");
}
} catch (IOException e) {
LOGGER.error("Exception Occured while writing Configuration Data"+e);
+ } finally {
+ if(bw != null){
+ try {
+ bw.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the BufferedWriter"+e);
+ }
+ }
}
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsRawPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsRawPolicy.java
index a6240e0ee..0bac0e066 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsRawPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsRawPolicy.java
@@ -72,15 +72,13 @@ public class CreateBrmsRawPolicy extends Policy {
// Saving the Configurations file at server location for CreateBrmsRawPolicy policy.
protected void saveConfigurations(String policyName, String jsonBody) {
- try {
- if (policyName.endsWith(".xml")) {
- policyName = policyName.substring(0,
- policyName.lastIndexOf(".xml"));
- }
- PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".txt");
+
+ if (policyName.endsWith(".xml")) {
+ policyName = policyName.substring(0,
+ policyName.lastIndexOf(".xml"));
+ }
+ try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".txt")){
out.println(jsonBody);
- out.close();
-
} catch (Exception e) {
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsRawPolicy", "Exception saving configurations file");
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateClosedLoopPerformanceMetrics.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateClosedLoopPerformanceMetrics.java
index 68cc9eff7..456924ac9 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateClosedLoopPerformanceMetrics.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateClosedLoopPerformanceMetrics.java
@@ -67,23 +67,15 @@ public class CreateClosedLoopPerformanceMetrics extends Policy {
}
//save configuration of the policy based on the policyname
- private void saveConfigurations(String policyName, String jsonBody) {
- try {
- String body = null;
- try {
- body = jsonBody;
- } catch (Exception e) {
- LOGGER.error("Exception Occured"+e);
- }
- if(policyName.endsWith(".xml")){
- policyName = policyName.substring(0, policyName.lastIndexOf(".xml"));
- }
- PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + "."+ policyName +".json");
- out.println(body);
- policyAdapter.setJsonBody(body);
- policyAdapter.setConfigBodyData(body);
- out.close();
-
+ private void saveConfigurations(String policyName, final String jsonBody) {
+
+ if(policyName.endsWith(".xml")){
+ policyName = policyName.substring(0, policyName.lastIndexOf(".xml"));
+ }
+ try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + "."+ policyName +".json")){
+ out.println(jsonBody);
+ policyAdapter.setJsonBody(jsonBody);
+ policyAdapter.setConfigBodyData(jsonBody);
} catch (Exception e) {
LOGGER.error("Exception Occured"+e);
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java
index 6e46ab1c0..e747edb9b 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java
@@ -1265,16 +1265,11 @@ public class FirewallConfigPolicy extends Policy {
}
private JsonObject stringToJson(String jsonString) {
- JsonObject json = null;
- if (jsonString != null) {
- //Read jsonBody to JsonObject
- StringReader in = null;
- in = new StringReader(jsonString);
-
- JsonReader jsonReader = Json.createReader(in);
- json = jsonReader.readObject();
- jsonReader.close();
- }
+ //Read jsonBody to JsonObject
+ StringReader in = new StringReader(jsonString);
+ JsonReader jsonReader = Json.createReader(in);
+ JsonObject json = jsonReader.readObject();
+ jsonReader.close();
return json;
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
index b0e48a7f4..e02121125 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
@@ -88,13 +88,11 @@ public class MicroServiceConfigPolicy extends Policy {
//save configuration of the policy based on the policyname
private void saveConfigurations(String policyName, String jsonBody) {
- try {
- if(policyName.endsWith(".xml")){
- policyName = policyName.replace(".xml", "");
- }
- PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName +".json");
+ if(policyName.endsWith(".xml")){
+ policyName = policyName.replace(".xml", "");
+ }
+ try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName +".json")){
out.println(jsonBody);
- out.close();
} catch (Exception e) {
LOGGER.error("Exception Occured While writing Configuration data"+e);
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/Policy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/Policy.java
index 20c76f3be..2196209d8 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/Policy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/Policy.java
@@ -108,7 +108,6 @@ public abstract class Policy {
public static final String URI_DATATYPE = "http://www.w3.org/2001/XMLSchema#anyURI";
public static final String RULE_VARIABLE = "var:";
public static final String EMPTY_STRING = "";
- private static final String String = null;
protected static String CONFIG_HOME = null;
protected static String ACTION_HOME = null;
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
index 71eb1156f..9ac858277 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
@@ -479,11 +479,14 @@ public class PolicyDBDao {
HttpURLConnection connection = null;
UUID requestID = UUID.randomUUID();
URL url;
+ String papUrl;
try {
- String papUrl = getPapUrlUserPass()[0];
- if(papUrl == null){
- papUrl = "undefined";
- }
+ String[] papUrlUserPass = getPapUrlUserPass();
+ if(papUrlUserPass == null ){
+ papUrl = "undefined";
+ } else {
+ papUrl = papUrlUserPass[0];
+ }
logger.debug("We are going to try to notify "+o);
//is this our own url?
String ourUrl = o;
@@ -1315,8 +1318,7 @@ public class PolicyDBDao {
private String[] getNameScopeAndVersionFromPdpPolicy(String fileName){
String[] splitByDots = fileName.split("\\.");
if(splitByDots.length < 3){
- //should we throw something
- return null;
+ return null;
}
String policyName = splitByDots[splitByDots.length-3];
String version = splitByDots[splitByDots.length-2];
@@ -1365,10 +1367,7 @@ public class PolicyDBDao {
*/
private static boolean isNullOrEmpty(String... strings){
for(String s : strings){
- if(!(s instanceof String)){
- return true;
- }
- if("".equals(s)){
+ if(s == null || "".equals(s)){
return true;
}
}
@@ -1532,7 +1531,7 @@ public class PolicyDBDao {
}
}
}
- if(transactionTimer instanceof Thread){
+ if(transactionTimer != null){
transactionTimer.interrupt();
}
}
@@ -1563,7 +1562,7 @@ public class PolicyDBDao {
}
}
- if(transactionTimer instanceof Thread){
+ if(transactionTimer != null){
transactionTimer.interrupt();
}
}
@@ -2042,7 +2041,7 @@ public class PolicyDBDao {
}
em.close();
}
- if(transactionTimer instanceof Thread){
+ if(transactionTimer != null){
transactionTimer.interrupt();
}
}
@@ -2544,7 +2543,10 @@ public class PolicyDBDao {
//we need to convert the form of the policy id that is used groups into the form that is used
//for the database. (com.Config_mypol.1.xml) to (Config_mypol.xml)
- String[] policyNameScopeAndVersion = getNameScopeAndVersionFromPdpPolicy(policyID);
+ String[] policyNameScopeAndVersion = getNameScopeAndVersionFromPdpPolicy(policyID);
+ if(policyNameScopeAndVersion == null) {
+ throw new IllegalArgumentException("Invalid input - policyID must contain name, scope and version");
+ }
Query policyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.policyName=:policyName AND p.scope=:scope AND p.deleted=:deleted");
policyQuery.setParameter("policyName", policyNameScopeAndVersion[0]);
policyQuery.setParameter(scope, policyNameScopeAndVersion[1]);
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java
index 107983562..397904f30 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java
@@ -161,10 +161,8 @@ public class PushPolicyController {
return;
}
File temp = new File(policyName);
- try {
- BufferedWriter bw = new BufferedWriter(new FileWriter(temp));
+ try (BufferedWriter bw = new BufferedWriter(new FileWriter(temp))){
bw.write(policyEntity.getPolicyData());
- bw.close();
URI selectedURI = temp.toURI();
// Create the policy Object
selectedPolicy = new StdPDPPolicy(policyName, true, policyID, selectedURI);
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java
index 5de09215c..dcabefcc8 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java
@@ -115,6 +115,7 @@ public class ElasticSearchPolicyUpdate {
Connection conn = null;
Statement stmt = null;
+ ResultSet result = null;
List<Index> listIndex = new ArrayList<>();
@@ -124,7 +125,7 @@ public class ElasticSearchPolicyUpdate {
stmt = conn.createStatement();
String policyEntityQuery = "Select * from PolicyEntity";
- ResultSet result = stmt.executeQuery(policyEntityQuery);
+ result = stmt.executeQuery(policyEntityQuery);
while(result.next()){
StringBuilder policyDataString = new StringBuilder("{");
@@ -171,36 +172,10 @@ public class ElasticSearchPolicyUpdate {
if(!"decision".equals(_type)){
if(configurationdataid != null){
- String configEntityQuery = "Select * from ConfigurationDataEntity where configurationDataId = ?";
- PreparedStatement pstmt = null;
- pstmt = conn.prepareStatement(configEntityQuery);
- pstmt.setString(1, configurationdataid);
- ResultSet configResult = pstmt.executeQuery();
- while(configResult.next()){
- String configBody = configResult.getString("configbody");
- String configType = configResult.getString("configtype");
- if(configBody!=null){
- configBody = configBody.replace("null", "\"\"");
- configBody= configBody.replace("\"", "\\\"");
- policyDataString.append("\"jsonBodyData\":\""+configBody+"\",\"configType\":\""+configType+"\",");
- }
- }
- configResult.close();
+ updateConfigData(conn, configurationdataid, policyDataString);
}
-
if(actionbodyid != null){
- String actionEntityQuery = "Select * from ActionBodyEntity where actionBodyId = ?";
- PreparedStatement pstmt = null;
- pstmt = conn.prepareStatement(actionEntityQuery);
- pstmt.setString(1, actionbodyid);
- ResultSet actionResult = pstmt.executeQuery();
- while(actionResult.next()){
- String actionBody = actionResult.getString("actionbody");
- actionBody = actionBody.replace("null", "\"\"");
- actionBody = actionBody.replace("\"", "\\\"");
- policyDataString.append("\"jsonBodyData\":\""+actionBody+"\",");
- }
- actionResult.close();
+ updateActionData(conn, actionbodyid, policyDataString);
}
}
@@ -245,6 +220,20 @@ public class ElasticSearchPolicyUpdate {
} catch (Exception e) {
LOGGER.error("Exception Occured while performing database Operation for Elastic Search Policy Upgrade"+e);
}finally{
+ if(result != null){
+ try {
+ result.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the resultset"+e);
+ }
+ }
+ if(stmt != null){
+ try {
+ stmt.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the statement"+e);
+ }
+ }
if(conn != null){
try {
conn.close();
@@ -315,4 +304,79 @@ public class ElasticSearchPolicyUpdate {
return policyDataString.toString();
}
+ private static void updateConfigData(Connection conn, String configurationdataid, StringBuilder policyDataString) throws Exception {
+
+ PreparedStatement pstmt = null;
+ ResultSet configResult = null;
+ try {
+ String configEntityQuery = "Select * from ConfigurationDataEntity where configurationDataId = ?";
+ pstmt = null;
+ pstmt = conn.prepareStatement(configEntityQuery);
+ pstmt.setString(1, configurationdataid);
+ configResult = pstmt.executeQuery();
+ while(configResult.next()){
+ String configBody = configResult.getString("configbody");
+ String configType = configResult.getString("configtype");
+ if(configBody!=null){
+ configBody = configBody.replace("null", "\"\"");
+ configBody= configBody.replace("\"", "\\\"");
+ policyDataString.append("\"jsonBodyData\":\""+configBody+"\",\"configType\":\""+configType+"\",");
+ }
+ }
+ } catch(Exception e) {
+ LOGGER.error("Exception Occured while updating configData"+e);
+ throw(e);
+ } finally {
+ if(configResult != null){
+ try {
+ configResult.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the ResultSet"+e);
+ }
+ }
+ if(pstmt != null){
+ try {
+ pstmt.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the PreparedStatement"+e);
+ }
+ }
+ }
+ }
+
+ private static void updateActionData(Connection conn, String actionbodyid, StringBuilder policyDataString) throws Exception {
+
+ PreparedStatement pstmt = null;
+ ResultSet actionResult = null;
+ try {
+ String actionEntityQuery = "Select * from ActionBodyEntity where actionBodyId = ?";
+ pstmt = conn.prepareStatement(actionEntityQuery);
+ pstmt.setString(1, actionbodyid);
+ actionResult = pstmt.executeQuery();
+ while(actionResult.next()){
+ String actionBody = actionResult.getString("actionbody");
+ actionBody = actionBody.replace("null", "\"\"");
+ actionBody = actionBody.replace("\"", "\\\"");
+ policyDataString.append("\"jsonBodyData\":\""+actionBody+"\",");
+ }
+ } catch(Exception e) {
+ LOGGER.error("Exception Occured while updating actionData"+e);
+ throw(e);
+ } finally {
+ if(actionResult != null){
+ try {
+ actionResult.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the ResultSet"+e);
+ }
+ }
+ if(pstmt != null){
+ try {
+ pstmt.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the PreparedStatement"+e);
+ }
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
index d3628f3c1..9b86204e0 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
@@ -247,7 +247,7 @@ public class GetDictionaryService {
jsonString = jsonString.replace("microServiceDictionaryDatas", "DictionaryDatas");
break;
default:
- return null;
+ break;
}
return jsonString;
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java
index 8258aba1a..af7112ebd 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java
@@ -341,12 +341,13 @@ public class PDPServices {
pdpConfigLocation = pdpConfigLocation.replace("/", File.separator);
}
InputStream inputStream = null;
+ JsonReader jsonReader = null;
try {
inputStream = new FileInputStream(new File(pdpConfigLocation));
try {
if (pdpConfigLocation.endsWith("json")) {
pdpResponse.setType(PolicyType.JSON);
- JsonReader jsonReader = Json.createReader(inputStream);
+ jsonReader = Json.createReader(inputStream);
pdpResponse.setConfig(jsonReader.readObject().toString());
jsonReader.close();
} else if (pdpConfigLocation.endsWith("xml")) {
@@ -400,6 +401,14 @@ public class PDPServices {
LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
throw new PDPException(XACMLErrorConstants.ERROR_PROCESS_FLOW +
"Cannot open a connection to the configURL", e);
+ } finally {
+ if(jsonReader != null) {
+ try {
+ jsonReader.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the JsonReader"+e);
+ }
+ }
}
} catch (FileNotFoundException e) {
LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/getDictionaryTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/getDictionaryTest.java
index e18f8bb03..38dafee35 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/getDictionaryTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/getDictionaryTest.java
@@ -41,7 +41,7 @@ public class getDictionaryTest {
dp.setDictionary("test");
GetDictionaryService gds = new GetDictionaryService(dp, null);
String result = (String) formatDictionary.invoke(gds, input);
- assertNull(result);
+ assertNotNull(result);
//
dp.setDictionary("OnapName");
gds = new GetDictionaryService(dp, null);
diff --git a/ONAP-PDP/src/main/java/org/onap/policy/xacml/action/FindAction.java b/ONAP-PDP/src/main/java/org/onap/policy/xacml/action/FindAction.java
index c6a889821..5fde0adf3 100644
--- a/ONAP-PDP/src/main/java/org/onap/policy/xacml/action/FindAction.java
+++ b/ONAP-PDP/src/main/java/org/onap/policy/xacml/action/FindAction.java
@@ -240,6 +240,7 @@ public class FindAction {
Pattern pattern = Pattern.compile("\\$([a-zA-Z0-9.:]*)");
Matcher match = pattern.matcher(configURL);
StringBuffer sb = new StringBuffer();
+ JsonReader jsonReader = null;
while (match.find()) {
LOGGER.info("Found Macro : " + match.group(1));
String replaceValue = matchValues.get(match.group(1));
@@ -292,7 +293,7 @@ public class FindAction {
connection = configURL.openConnection();
// InputStream in = connection.getInputStrem();
// LOGGER.info("The Body Content is : " + IOUtils.toString(in));
- JsonReader jsonReader = Json.createReader(connection.getInputStream());
+ jsonReader = Json.createReader(connection.getInputStream());
StringEntity input = new StringEntity(jsonReader.readObject().toString());
input.setContentType("application/json");
postRequest.setEntity(input);
@@ -312,6 +313,13 @@ public class FindAction {
LOGGER.error(e.getMessage() +e);
response = e.getMessage();
} finally {
+ if(jsonReader != null) {
+ try {
+ jsonReader.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the JsonReader"+e);
+ }
+ }
httpClient.getConnectionManager().shutdown();
}
} else if(matchValues.get("method").equalsIgnoreCase("PUT")) {
@@ -330,7 +338,7 @@ public class FindAction {
connection = configURL.openConnection();
//InputStream in = connection.getInputStream();
//LOGGER.info("The Body Content is : " + IOUtils.toString(in));
- JsonReader jsonReader = Json.createReader(connection.getInputStream());
+ jsonReader = Json.createReader(connection.getInputStream());
StringEntity input = new StringEntity(jsonReader.readObject().toString());
input.setContentType("application/json");
putRequest.setEntity(input);
@@ -349,6 +357,13 @@ public class FindAction {
LOGGER.error(e.getMessage() +e);
response = e.getMessage();
}finally {
+ if(jsonReader != null) {
+ try {
+ jsonReader.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the JsonReader"+e);
+ }
+ }
httpClient.getConnectionManager().shutdown();
}
}
diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java
index ca2271ab4..d3dc7ae18 100644
--- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java
+++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java
@@ -180,18 +180,8 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
// We don't have the default group, create it
//
String defaultId = properties.getProperty(PROP_PAP_GROUPS_DEFAULT, PROP_PAP_GROUPS_DEFAULT_NAME);
- if(defaultId == null){
- defaultId = PROP_PAP_GROUPS_DEFAULT_NAME;
- }
- if("".equals(defaultId)){
- defaultId = PROP_PAP_GROUPS_DEFAULT_NAME;
- }
- //we're going to check one more time in case the PROP_PAP_GROUPS_DEFAULT_NAME doesn't exist
- if(defaultId == null){
- defaultId = "default";
- }
if("".equals(defaultId)){
- defaultId = "default";
+ defaultId = PROP_PAP_GROUPS_DEFAULT_NAME;
}
logger.warn("Default group does NOT exist, creating " + defaultId);
Path defaultPath = Paths.get(this.repository.toString(), defaultId);