Fix critical sonar for ONAP-PAP-REST 91/8391/3
authorGuo Ruijing <ruijing.guo@intel.com>
Thu, 24 Aug 2017 08:13:53 +0000 (08:13 +0000)
committerGuo Ruijing <ruijing.guo@intel.com>
Thu, 24 Aug 2017 08:27:56 +0000 (08:27 +0000)
This patch is to fix error-handling sonar issue
for ONAP-PAP-REST.

Change-Id: Ic5755cc02f282938d098c3a5c9e869318429c2c6
Issue-Id: POLICY-174
Signed-off-by: Guo Ruijing <ruijing.guo@intel.com>
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ConfigPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java

index e11538c..f4c06c3 100644 (file)
@@ -1092,7 +1092,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        String message = "DELETE interface called for PAP " + papResourceName + " but it has an Administrative"
                                        + " state of " + im.getStateManager().getAdminState()
                                        + "\n Exception Message: " + ae.getMessage();
-                       LOGGER.info(message);
+                       LOGGER.info(message, ae);
                        PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Failed - See Error.log");
@@ -1102,7 +1102,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        String message = "PUT interface called for PAP " + papResourceName + " but it has a Standby Status"
                                        + " of " + im.getStateManager().getStandbyStatus()
                                        + "\n Exception Message: " + se.getMessage();
-                       LOGGER.info(message);
+                       LOGGER.info(message, se);
                        PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Failed - See Error.log");
index 3355fab..2a5e9d3 100644 (file)
@@ -76,7 +76,7 @@ public class ClosedLoopPolicy extends Policy {
                                        //Remove the trapMaxAge in Verification Signature
                                        body = body.replace(",\"trapMaxAge\":null", "");
                                }catch(Exception e){
-                                       LOGGER.debug("No Trap Max Age in JSON body");
+                                       LOGGER.debug("No Trap Max Age in JSON body", e);
                                }
                                this.policyAdapter.setJsonBody(body);
                        } catch (Exception e) {
index 1b29c03..02ba2ef 100644 (file)
@@ -179,11 +179,8 @@ public class ConfigPolicy extends Policy {
                        XMLReader reader = parser.getXMLReader();
                        reader.setErrorHandler(new XMLErrorHandler());
                        reader.parse(new InputSource(new StringReader(data)));
-               } catch (ParserConfigurationException e) {
-                       return false;
-               } catch (SAXException e) {
-                       return false;
-               } catch (IOException e) {
+               } catch (ParserConfigurationException | SAXException | IOException e) {
+                       LOGGER.debug(e);
                        return false;
                }
                return true;
index 923e528..5abe7ce 100644 (file)
@@ -231,6 +231,7 @@ public class CreateBrmsParamPolicy extends Policy {
                                                                line = line.split("\\/\\*")[0]
                                                                                + line.split("\\*\\/")[1].replace("*/", "");
                                                        } catch (Exception e) {
+                                                               LOGGER.debug(e);
                                                                line = line.split("\\/\\*")[0];
                                                        }
                                                } else {
@@ -242,6 +243,7 @@ public class CreateBrmsParamPolicy extends Policy {
                                                try {
                                                        line = line.split("\\*\\/")[1].replace("*/", "");
                                                } catch (Exception e) {
+                                                       LOGGER.debug(e);
                                                        line = "";
                                                }
                                        }
@@ -275,6 +277,7 @@ public class CreateBrmsParamPolicy extends Policy {
                                        try {
                                                nextComponent = components[i + 1];
                                        } catch (Exception e) {
+                                               LOGGER.debug(e);
                                                nextComponent = components[i];
                                        }
                                        //If the type is of type String then we add the UI Item and type to the map. 
index fd9e49c..aad70e5 100644 (file)
@@ -90,7 +90,7 @@ public class CreateNewMicroServiceModel {
                                File deleteFile = new File(cleanUpFile); 
                                FileUtils.forceDelete(deleteFile);
                        } catch (IOException e) {
-                               logger.error("Failed to unzip model file " + randomID);
+                               logger.error("Failed to unzip model file " + randomID, e);
                        }
            }else {
                    tempMap = utils.processEpackage("ExtractDir" + File.separator + randomID+".xmi", MODEL_TYPE.XMI);
index 98c8137..d2ed1ad 100644 (file)
@@ -212,7 +212,7 @@ public class PolicyDBDao {
 
                } catch(Exception e){
                        PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Exception querying for other registered PolicyDBDaos");
-                       logger.warn("List of remote PolicyDBDaos will be empty");
+                       logger.warn("List of remote PolicyDBDaos will be empty", e);
                }
                try{
                        em.getTransaction().commit();
@@ -220,7 +220,7 @@ public class PolicyDBDao {
                        try{
                                em.getTransaction().rollback();
                        } catch(Exception e2){
-
+                               logger.debug("List of remote PolicyDBDaos will be empty", e2);
                        }
                }
                em.close();
@@ -500,6 +500,7 @@ public class PolicyDBDao {
                                        ourUrl = splitPapUrlUserPass((String)o)[0];
                                }catch(Exception e){
                                        ourUrl = o;
+                                       logger.debug(e);
                                }
                                if(o == null){
                                        o = "undefined";
@@ -867,6 +868,7 @@ public class PolicyDBDao {
             }
         } catch(Exception e){
             nameAndVersion[0] = originalPolicyName;         
+            logger.debug(e);
         }
         try{
             nameAndVersion[1] = policyName.substring(policyName.lastIndexOf('.')+1);
@@ -875,6 +877,7 @@ public class PolicyDBDao {
             }
         } catch(Exception e){
             nameAndVersion[1] = "1";
+            logger.debug(e);
         }
         return nameAndVersion;
     }
@@ -2795,4 +2798,4 @@ public class PolicyDBDao {
         }
        }
 
-}
\ No newline at end of file
+}