Fix compilation issue due to generic Exception 19/32119/3
authorJim Hahn <jrh3@att.com>
Mon, 19 Feb 2018 16:53:40 +0000 (11:53 -0500)
committerJim Hahn <jrh3@att.com>
Mon, 19 Feb 2018 17:00:52 +0000 (12:00 -0500)
After modifying common to remove generic Exceptions, policy/engine would
no longer compile.  Had to modify policy/engine to accomodate the
specific exception.

Change-Id: If339285235994119009a8dcf9484bc81016e2600
Issue-ID: POLICY-246
Signed-off-by: Jim Hahn <jrh3@att.com>
LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java
LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java
ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java

index 259b2cb..5ead822 100644 (file)
@@ -46,9 +46,8 @@ import java.util.regex.Pattern;
 import java.util.stream.Stream;
 
 import org.apache.log4j.Logger;
 import java.util.stream.Stream;
 
 import org.apache.log4j.Logger;
-import org.onap.policy.common.im.AdministrativeStateException;
 import org.onap.policy.common.im.IntegrityMonitor;
 import org.onap.policy.common.im.IntegrityMonitor;
-import org.onap.policy.common.im.StandbyStatusException;
+import org.onap.policy.common.im.IntegrityMonitorException;
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.utils.CryptoUtils;
 import org.onap.xacml.parser.LogEntryObject.LOGTYPE;
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.utils.CryptoUtils;
 import org.onap.xacml.parser.LogEntryObject.LOGTYPE;
@@ -579,10 +578,8 @@ public class ParseLog {
                if (im!=null){
                        try {
                                im.startTransaction();
                if (im!=null){
                        try {
                                im.startTransaction();
-                       } catch (AdministrativeStateException e) {
-                               logger.error("Error received" + e);                             
-                       } catch (StandbyStatusException ex) {
-                               logger.error("Error received" + ex);
+                       } catch (IntegrityMonitorException e) {
+                               logger.error("Error received" + e);
                        }
                }
                returnLogValue = pullOutLogValues(line, type);
                        }
                }
                returnLogValue = pullOutLogValues(line, type);
index 1f42ac3..62af131 100644 (file)
@@ -40,6 +40,7 @@ import org.junit.Test;
 import org.mockito.Mockito;
 import org.onap.policy.common.im.AdministrativeStateException;
 import org.onap.policy.common.im.IntegrityMonitor;
 import org.mockito.Mockito;
 import org.onap.policy.common.im.AdministrativeStateException;
 import org.onap.policy.common.im.IntegrityMonitor;
+import org.onap.policy.common.im.IntegrityMonitorException;
 import org.onap.policy.common.im.StandbyStatusException;
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.common.logging.flexlogger.Logger;
 import org.onap.policy.common.im.StandbyStatusException;
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.common.logging.flexlogger.Logger;
@@ -488,7 +489,7 @@ public class ParseLogTest {
                im = Mockito.mock(IntegrityMonitor.class);
                try {
                        Mockito.doNothing().when(im).startTransaction();
                im = Mockito.mock(IntegrityMonitor.class);
                try {
                        Mockito.doNothing().when(im).startTransaction();
-               } catch (StandbyStatusException | AdministrativeStateException e) {
+               } catch (IntegrityMonitorException e) {
                        fail();
                }
                Mockito.doNothing().when(im).endTransaction();
                        fail();
                }
                Mockito.doNothing().when(im).endTransaction();
index 392c32a..bedc212 100644 (file)
@@ -64,6 +64,7 @@ import org.onap.policy.common.ia.IntegrityAudit;
 import org.onap.policy.common.im.AdministrativeStateException;
 import org.onap.policy.common.im.ForwardProgressException;
 import org.onap.policy.common.im.IntegrityMonitor;
 import org.onap.policy.common.im.AdministrativeStateException;
 import org.onap.policy.common.im.ForwardProgressException;
 import org.onap.policy.common.im.IntegrityMonitor;
+import org.onap.policy.common.im.IntegrityMonitorException;
 import org.onap.policy.common.im.IntegrityMonitorProperties;
 import org.onap.policy.common.im.StandbyStatusException;
 import org.onap.policy.common.logging.ONAPLoggingContext;
 import org.onap.policy.common.im.IntegrityMonitorProperties;
 import org.onap.policy.common.im.StandbyStatusException;
 import org.onap.policy.common.logging.ONAPLoggingContext;
@@ -557,6 +558,16 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        PolicyLogger.audit("Transaction Failed - See Error.log");
                        setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                        return;
                        PolicyLogger.audit("Transaction Failed - See Error.log");
                        setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                        return;
+               } catch (IntegrityMonitorException e) {
+                       String message = "POST interface called for PAP " + papResourceName + " but an exception occurred"
+                                       + "\n Exception Message: " + e.getMessage();
+                       LOGGER.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message, e);
+                       loggingContext.metricEnded();
+                       PolicyLogger.metrics("XACMLPapServlet doPost im startTransaction");
+                       loggingContext.transactionEnded();
+                       PolicyLogger.audit("Transaction Failed - See Error.log");
+                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+                       return;
                }
                try {
                        loggingContext.metricStarted();
                }
                try {
                        loggingContext.metricStarted();
@@ -825,6 +836,15 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                PolicyLogger.audit("Transaction Failed - See Error.log");
                                setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                                return;
                                PolicyLogger.audit("Transaction Failed - See Error.log");
                                setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                                return;
+                       } catch (IntegrityMonitorException e) {
+                               String message = "GET interface called for PAP " + papResourceName + " but an exception occurred"
+                                               + "\n Exception Message: " + e.getMessage();
+                               LOGGER.info(message, e);
+                               PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
+                               loggingContext.transactionEnded();
+                               PolicyLogger.audit("Transaction Failed - See Error.log");
+                               setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+                               return;
                        }
                        // Request from the API to get the gitPath
                        String apiflag = request.getParameter("apiflag");
                        }
                        // Request from the API to get the gitPath
                        String apiflag = request.getParameter("apiflag");
@@ -997,7 +1017,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        im.startTransaction();
                        loggingContext.metricEnded();
                        PolicyLogger.metrics("XACMLPapServlet doPut im startTransaction");
                        im.startTransaction();
                        loggingContext.metricEnded();
                        PolicyLogger.metrics("XACMLPapServlet doPut im startTransaction");
-               } catch (AdministrativeStateException | StandbyStatusException e) {
+               } catch (IntegrityMonitorException e) {
                        String message = "PUT interface called for PAP " + papResourceName;
                        if (e instanceof AdministrativeStateException) {
                                message += " but it has an Administrative state of "
                        String message = "PUT interface called for PAP " + papResourceName;
                        if (e instanceof AdministrativeStateException) {
                                message += " but it has an Administrative state of "
@@ -1005,6 +1025,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        } else if (e instanceof StandbyStatusException) {
                                message += " but it has a Standby Status of "
                                        + im.getStateManager().getStandbyStatus();
                        } else if (e instanceof StandbyStatusException) {
                                message += " but it has a Standby Status of "
                                        + im.getStateManager().getStandbyStatus();
+                       } else {
+                               message += " but an exception occurred";
 
                        }
                        message += "\n Exception Message: " + e.getMessage();
 
                        }
                        message += "\n Exception Message: " + e.getMessage();
@@ -1279,6 +1301,15 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        PolicyLogger.audit("Transaction Failed - See Error.log");
                        setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                        return;
                        PolicyLogger.audit("Transaction Failed - See Error.log");
                        setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                        return;
+               } catch (IntegrityMonitorException e) {
+                       String message = "PUT interface called for PAP " + papResourceName + " but an exception occurred"
+                                       + "\n Exception Message: " + e.getMessage();
+                       LOGGER.info(message, e);
+                       PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
+                       loggingContext.transactionEnded();
+                       PolicyLogger.audit("Transaction Failed - See Error.log");
+                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+                       return;
                }
                loggingContext.metricStarted();
                XACMLRest.dumpRequest(request);
                }
                loggingContext.metricStarted();
                XACMLRest.dumpRequest(request);
index 6082953..567ff2e 100644 (file)
@@ -52,6 +52,7 @@ import org.onap.policy.api.PolicyParameters;
 import org.onap.policy.common.im.AdministrativeStateException;
 import org.onap.policy.common.im.ForwardProgressException;
 import org.onap.policy.common.im.IntegrityMonitor;
 import org.onap.policy.common.im.AdministrativeStateException;
 import org.onap.policy.common.im.ForwardProgressException;
 import org.onap.policy.common.im.IntegrityMonitor;
+import org.onap.policy.common.im.IntegrityMonitorException;
 import org.onap.policy.common.im.IntegrityMonitorProperties;
 import org.onap.policy.common.im.StandbyStatusException;
 import org.onap.policy.common.logging.ONAPLoggingContext;
 import org.onap.policy.common.im.IntegrityMonitorProperties;
 import org.onap.policy.common.im.StandbyStatusException;
 import org.onap.policy.common.logging.ONAPLoggingContext;
@@ -445,7 +446,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable {
                try {
                        im.startTransaction();
                }
                try {
                        im.startTransaction();
                }
-               catch (AdministrativeStateException | StandbyStatusException e) {
+               catch (IntegrityMonitorException e) {
                        String message = e.toString();
                        PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + e);
                        loggingContext.transactionEnded();
                        String message = e.toString();
                        PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + e);
                        loggingContext.transactionEnded();
@@ -744,7 +745,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable {
                try {
                        im.startTransaction();
                }
                try {
                        im.startTransaction();
                }
-               catch (AdministrativeStateException | StandbyStatusException e) {
+               catch (IntegrityMonitorException e) {
                        String message = e.toString();
                        PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message);
                        loggingContext.transactionEnded();
                        String message = e.toString();
                        PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message);
                        loggingContext.transactionEnded();
@@ -864,7 +865,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable {
                try {
                        im.startTransaction();
                }
                try {
                        im.startTransaction();
                }
-               catch (AdministrativeStateException | StandbyStatusException e) {
+               catch (IntegrityMonitorException e) {
                        String message = e.toString();
                        PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + e);
                        loggingContext.transactionEnded();
                        String message = e.toString();
                        PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + e);
                        loggingContext.transactionEnded();
index 594b51c..e8747f7 100644 (file)
@@ -42,13 +42,10 @@ import org.junit.Test;
 import org.mockito.Mockito;
 import org.onap.policy.common.ia.DbDAO;
 import org.onap.policy.common.ia.IntegrityAuditProperties;
 import org.mockito.Mockito;
 import org.onap.policy.common.ia.DbDAO;
 import org.onap.policy.common.ia.IntegrityAuditProperties;
-import org.onap.policy.common.im.AdministrativeStateException;
 import org.onap.policy.common.im.IntegrityMonitor;
 import org.onap.policy.common.im.IntegrityMonitor;
-import org.onap.policy.common.im.StandbyStatusException;
+import org.onap.policy.common.im.IntegrityMonitorException;
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.common.logging.flexlogger.Logger;
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.common.logging.flexlogger.Logger;
-
-import org.onap.policy.pdp.rest.XACMLPdpServletTest;
 import org.powermock.api.mockito.PowerMockito;
 import org.springframework.mock.web.MockHttpServletResponse;
 import org.springframework.mock.web.MockServletConfig;
 import org.powermock.api.mockito.PowerMockito;
 import org.springframework.mock.web.MockHttpServletResponse;
 import org.springframework.mock.web.MockServletConfig;
@@ -168,7 +165,7 @@ public class XACMLPdpServletTest extends TestCase{
                
                try {
                        Mockito.doNothing().when(im).startTransaction();
                
                try {
                        Mockito.doNothing().when(im).startTransaction();
-               } catch (StandbyStatusException | AdministrativeStateException e) {
+               } catch (IntegrityMonitorException e) {
                        fail();
                }
                Mockito.doNothing().when(im).endTransaction();
                        fail();
                }
                Mockito.doNothing().when(im).endTransaction();