Health check issue fixes
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / XACMLPapServlet.java
index 5132fae..88f6d45 100644 (file)
@@ -43,6 +43,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
+import java.util.Scanner;
 import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -80,6 +81,7 @@ import org.onap.policy.pap.xacml.rest.handler.SavePolicyHandler;
 import org.onap.policy.pap.xacml.restAuth.CheckPDP;
 import org.onap.policy.rest.XACMLRest;
 import org.onap.policy.rest.XACMLRestProperties;
+import org.onap.policy.rest.dao.PolicyDBException;
 import org.onap.policy.utils.PolicyUtils;
 import org.onap.policy.xacml.api.XACMLErrorConstants;
 import org.onap.policy.xacml.api.pap.ONAPPapEngineFactory;
@@ -113,7 +115,6 @@ import com.google.common.base.Splitter;
                })
 public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeListener, Runnable {
        private static final long serialVersionUID = 1L;
-       private static final String localIp = "127.0.0.1";
        private static final Logger LOGGER      = FlexLogger.getLogger(XACMLPapServlet.class);
        // audit (transaction) LOGGER
        private static final Logger auditLogger = FlexLogger.getLogger("auditLogger");
@@ -171,7 +172,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
         * This thread may be invoked upon startup to initiate sending PDP policy/pip configuration when
         * this servlet starts. Its configurable by the admin.
         */
-       private transient static Thread initiateThread = null;
+       private static transient Thread initiateThread = null;
        private transient ONAPLoggingContext baseLoggingContext = null;
        
        /**
@@ -284,22 +285,24 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        // The factory knows how to go about creating a PAP Engine
                        setPAPEngine((PAPPolicyEngine) factory.newEngine());
                        PolicyDBDaoTransaction addNewGroup = null;
-                       try{
-                               if(((org.onap.policy.xacml.std.pap.StdEngine)papEngine).wasDefaultGroupJustAdded){
-                                       addNewGroup = policyDBDao.getNewTransaction();
-                                       OnapPDPGroup group = papEngine.getDefaultGroup();
-                                       addNewGroup.createGroup(group.getId(), group.getName(), group.getDescription(), "automaticallyAdded");
-                                       addNewGroup.commitTransaction();
-                                       addNewGroup = policyDBDao.getNewTransaction();
-                                       addNewGroup.changeDefaultGroup(group, "automaticallyAdded");
-                                       addNewGroup.commitTransaction();
-                               }
-                       } catch(Exception e){
-                               PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " Error creating new default group in the database");
-                               if(addNewGroup != null){
-                                       addNewGroup.rollbackTransaction();
-                               }
-                       }
+            if (((org.onap.policy.xacml.std.pap.StdEngine) papEngine).wasDefaultGroupJustAdded) {
+                try {
+                    addNewGroup = policyDBDao.getNewTransaction();
+                    OnapPDPGroup group = papEngine.getDefaultGroup();
+                    addNewGroup.createGroup(group.getId(), group.getName(), group.getDescription(),
+                            "automaticallyAdded");
+                    addNewGroup.commitTransaction();
+                    addNewGroup = policyDBDao.getNewTransaction();
+                    addNewGroup.changeDefaultGroup(group, "automaticallyAdded");
+                    addNewGroup.commitTransaction();
+                } catch (Exception e) {
+                    PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet",
+                            " Error creating new default group in the database");
+                    if (addNewGroup != null) {
+                        addNewGroup.rollbackTransaction();
+                    }
+                }
+            }
                        policyDBDao.setPapEngine((PAPPolicyEngine) XACMLPapServlet.papEngine);
                if (Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_RUN_AUDIT_FLAG))){
                        //get an AuditTransaction to lock out all other transactions
@@ -335,6 +338,14 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
         initiateThread.start();
     }
 
+    private static void mapperWriteValue(ObjectMapper mapper,  HttpServletResponse response, Object value) {
+        try {
+            mapper.writeValue(response.getOutputStream(), value);
+        } catch (Exception e) {
+            LOGGER.error(e);
+        }
+    }
+
     private static void startHeartBeatService(Heartbeat heartbeat) {
            XACMLPapServlet.heartbeat = heartbeat;
         XACMLPapServlet.heartbeatThread = new Thread(XACMLPapServlet.heartbeat);
@@ -564,7 +575,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        try {
                                                pdpTransaction.addPdpToGroup(id, XACMLPapServlet.papEngine.getDefaultGroup().getId(), id, "Registered on first startup", Integer.parseInt(jmxport), "PDP autoregister");
                                                XACMLPapServlet.papEngine.newPDP(id, XACMLPapServlet.papEngine.getDefaultGroup(), id, "Registered on first startup", Integer.parseInt(jmxport));
-                                       } catch (NullPointerException | PAPException | IllegalArgumentException | IllegalStateException | PersistenceException e) {
+                                       } catch (NullPointerException | PAPException | IllegalArgumentException | IllegalStateException | PersistenceException | PolicyDBException e) {
                                                pdpTransaction.rollbackTransaction();
                                                String message = "Failed to create new PDP for id: " + id;
                                                PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " " + message);
@@ -575,7 +586,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                                return;
                                        }
                                        // get the PDP we just created
-                                       pdp = XACMLPapServlet.papEngine.getPDP(id);
+                           try{
+                               pdp = XACMLPapServlet.papEngine.getPDP(id);
+                           }catch(PAPException e){
+                               LOGGER.error(e);
+                           }
                                        if (pdp == null) {
                                                if(pdpTransaction != null){
                                                        pdpTransaction.rollbackTransaction();
@@ -604,10 +619,19 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                }
                        }
                        if (jmxport != null && jmxport != ""){
-                               ((StdPDP) pdp).setJmxPort(Integer.valueOf(jmxport));
+                           try{
+                       ((StdPDP) pdp).setJmxPort(Integer.valueOf(jmxport));
+                           }catch(NumberFormatException e){
+                               LOGGER.error(e);
+                           }
                        }
                        // Get the PDP's Group
-                       OnapPDPGroup group = XACMLPapServlet.papEngine.getPDPGroup((OnapPDP) pdp);
+                       OnapPDPGroup group =null;
+                       try{
+                   group= XACMLPapServlet.papEngine.getPDPGroup((OnapPDP) pdp);
+                       }catch(PAPException e){
+                           LOGGER.error(e);
+                       }
                        if (group == null) {
                                PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " PDP not associated with any group, even the default");
                                loggingContext.transactionEnded();
@@ -622,7 +646,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        Properties pipconfig = group.getPipConfigProperties();
                        // Get the current policy/pip configuration that the PDP has
                        Properties pdpProperties = new Properties();
-                       pdpProperties.load(request.getInputStream());
+                       try{
+                   pdpProperties.load(request.getInputStream());
+                       }catch(IOException e){
+                           LOGGER.error(e);
+                       }
                        LOGGER.info("PDP Current Properties: " + pdpProperties.toString());
                        LOGGER.info("Policies: " + (policies != null ? policies.toString() : "null"));
                        LOGGER.info("Pip config: " + (pipconfig != null ? pipconfig.toString() : "null"));
@@ -637,19 +665,35 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        // retrieve them.
                                        this.populatePolicyURL(request.getRequestURL(), policies);
                                        // Copy the properties to the output stream
-                                       policies.store(response.getOutputStream(), "");
+                                       try{
+                                           policies.store(response.getOutputStream(), "");
+                                       }catch(IOException e){
+                               LOGGER.error(e);
+                           }
                                }
                                if (pipconfig != null) {
                                        // Copy the properties to the output stream
-                                       pipconfig.store(response.getOutputStream(), "");
+                                       try{
+                                           pipconfig.store(response.getOutputStream(), "");
+                                       }catch(IOException e){
+                               LOGGER.error(e);
+                           }
                                }
                                // We are good - and we are sending them information
                                response.setStatus(HttpServletResponse.SC_OK);
-                               setPDPSummaryStatus(pdp, PDPStatus.Status.OUT_OF_SYNCH);
+                               try{
+                                   setPDPSummaryStatus(pdp, PDPStatus.Status.OUT_OF_SYNCH);
+                               }catch(PAPException e){
+                       LOGGER.error(e);
+                   }
                        } else {
                                // Tell them they are good
                                response.setStatus(HttpServletResponse.SC_NO_CONTENT);
-                               setPDPSummaryStatus(pdp, PDPStatus.Status.UP_TO_DATE);
+                               try{
+                                   setPDPSummaryStatus(pdp, PDPStatus.Status.UP_TO_DATE);
+                               }catch(PAPException e){
+                       LOGGER.error(e);
+                   }
                        }
                        // tell the AC that something changed
                        notifyAC();
@@ -740,7 +784,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        if (apiflag!=null) {
                                if(authorizeRequest(request)){
                                        APIRequestHandler apiRequestHandler = new APIRequestHandler();
-                                       apiRequestHandler.doGet(request,response, apiflag);
+                                       try{
+                                           apiRequestHandler.doGet(request,response, apiflag);
+                                       }catch(IOException e){
+                                           LOGGER.error(e);
+                                       }
                                        loggingContext.transactionEnded();
                                        PolicyLogger.audit("Transaction Ended Successfully");
                                        im.endTransaction();
@@ -759,7 +807,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        String groupId = request.getParameter("groupId");
                        if (groupId != null) {
                                // this is from the Admin Console, so handle separately
-                               doACGet(request, response, groupId, loggingContext);
+                               try{
+                                   doACGet(request, response, groupId, loggingContext);
+                               } catch(IOException e){
+                    LOGGER.error(e);
+                }
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Ended Successfully");
                                im.endTransaction();
@@ -769,19 +821,22 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        String id = this.getPDPID(request);
                        LOGGER.info("doGet from: " + id);
                        // Get the PDP Object
-                       OnapPDP pdp = XACMLPapServlet.papEngine.getPDP(id);
+                       OnapPDP pdp = null;
+                       try{
+                           pdp = XACMLPapServlet.papEngine.getPDP(id);
+                       }catch(PAPException e){
+                           LOGGER.error(e);
+                       }
                        // Is it known?
                        if (pdp == null) {
                                // Check if request came from localhost
                                if (request.getRemoteHost().equals("localhost") ||
-                                               request.getRemoteHost().equals(localIp) ||
                                                request.getRemoteHost().equals(request.getLocalAddr())) {
                                        // Return status information - basically all the groups
                                        loggingContext.setServiceName("PAP.getGroups");
                                        Set<OnapPDPGroup> groups = papEngine.getOnapPDPGroups();
                                        // convert response object to JSON and include in the response
-                                       ObjectMapper mapper = new ObjectMapper();
-                                       mapper.writeValue(response.getOutputStream(),  groups);
+                                       mapperWriteValue(new ObjectMapper(), response,  groups);
                                        response.setHeader("content-type", "application/json");
                                        response.setStatus(HttpServletResponse.SC_OK);
                                        loggingContext.transactionEnded();
@@ -799,7 +854,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        }
                        loggingContext.setServiceName("PAP.getPolicy");
                        // Get the PDP's Group
-                       OnapPDPGroup group = XACMLPapServlet.papEngine.getPDPGroup((OnapPDP) pdp);
+                       OnapPDPGroup group = null;
+                       try {
+                           group = XACMLPapServlet.papEngine.getPDPGroup((OnapPDP) pdp);
+                       } catch (PAPException e) {
+                           LOGGER.error(e);
+                       }
                        if (group == null) {
                                String message = "No group associated with pdp " + pdp.getId();
                                LOGGER.warn(XACMLErrorConstants.ERROR_PERMISSIONS + message);
@@ -830,8 +890,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                im.endTransaction();
                                return;
                        }
-                       LOGGER.warn("PolicyDebugging: Policy Validity: " + policy.isValid() + "\n "
-                                       + "Policy Name : " + policy.getName() + "\n Policy URI: " + policy.getLocation().toString());
+                       try{
+                   LOGGER.warn("PolicyDebugging: Policy Validity: " + policy.isValid() + "\n "
+                           + "Policy Name : " + policy.getName() + "\n Policy URI: " + policy.getLocation().toString());
+                       } catch (PAPException| IOException e){
+                           LOGGER.error(e);
+                       }
                        try (InputStream is = new FileInputStream(((StdPDPGroup)group).getDirectory().toString()+File.separator+policyId); OutputStream os = response.getOutputStream()) {
                                // Send the policy back
                                IOUtils.copy(is, os);
@@ -847,7 +911,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                PolicyLogger.audit("Transaction Failed - See Error.log");
                                setResponseError(response,HttpServletResponse.SC_NOT_FOUND, message);
                        }
-               }  catch (PAPException | IOException e) {
+               }  catch (PAPException e) {
                        LOGGER.debug(e);
                        PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, e, "XACMLPapServlet", " GET exception");
                        loggingContext.transactionEnded();
@@ -904,7 +968,6 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                String policyDBDaoRequestUrl = request.getParameter("policydbdaourl");
                if(policyDBDaoRequestUrl != null){
                        String policyDBDaoRequestEntityId = request.getParameter("entityid");
-                       //String policyDBDaoRequestEntityType = request.getParameter("entitytype");
                        String policyDBDaoRequestEntityType = request.getParameter("entitytype");
                        String policyDBDaoRequestExtraData = request.getParameter("extradata");
                        if(policyDBDaoRequestEntityId == null || policyDBDaoRequestEntityType == null){
@@ -928,7 +991,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                if (importService != null) {
                        if(authorizeRequest(request)){
                                APIRequestHandler apiRequestHandler = new APIRequestHandler();
-                               apiRequestHandler.doPut(request, response, importService);
+                               try{
+                                   apiRequestHandler.doPut(request, response, importService);
+                               }catch(IOException e){
+                                   LOGGER.error(e);
+                               }
                                im.endTransaction();
                                return;
                        } else {
@@ -1023,7 +1090,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        return;
                                }
                                if(apiflag.equalsIgnoreCase("addPolicyToGroup")){
-                                       updateGroupsFromAPI(request, response, groupId, loggingContext);
+                                   try{
+                                       updateGroupsFromAPI(request, response, groupId, loggingContext);
+                                   }catch(IOException e){
+                                       LOGGER.error(e);
+                                   }
                                        loggingContext.transactionEnded();
                                        PolicyLogger.audit("Transaction Ended Successfully");
                                        im.endTransaction();
@@ -1031,7 +1102,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                }
                        }
                        // this is from the Admin Console, so handle separately
-                       doACPut(request, response, groupId, loggingContext);
+                       try {
+                           doACPut(request, response, groupId, loggingContext);
+                       } catch (IOException e) {
+                LOGGER.error(e);
+            }
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Ended Successfully");
                        im.endTransaction();
@@ -1043,7 +1118,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                if (apiflag != null && apiflag.equalsIgnoreCase("admin")){
                        // this request is from the Admin Console
                        SavePolicyHandler savePolicyHandler = SavePolicyHandler.getInstance();
-                       savePolicyHandler.doPolicyAPIPut(request, response);
+                       try{
+                           savePolicyHandler.doPolicyAPIPut(request, response);
+                       } catch (IOException e) {
+                LOGGER.error(e);
+            }
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Ended Successfully");
                        im.endTransaction();
@@ -1052,7 +1131,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        // this request is from the Policy Creation API 
                        if(authorizeRequest(request)){
                                APIRequestHandler apiRequestHandler = new APIRequestHandler();
-                               apiRequestHandler.doPut(request, response, request.getHeader("ClientScope"));
+                               try{
+                                   apiRequestHandler.doPut(request, response, request.getHeader("ClientScope"));
+                   } catch (IOException e) {
+                       LOGGER.error(e);
+                   }
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Ended Successfully");
                                im.endTransaction();
@@ -1141,7 +1224,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                return;
                        }
                        // this is from the Admin Console, so handle separately
-                       doACDelete(request, response, groupId, loggingContext);
+                       try{
+                           doACDelete(request, response, groupId, loggingContext);
+                       } catch (IOException e) {
+                LOGGER.error(e);
+            }
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Ended Successfully");
                        im.endTransaction();
@@ -1346,8 +1433,14 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        if (groupName != null && groupDescription != null) {
                                // Args:              group=<groupId> groupName=<name> groupDescription=<description>            <= create a new group
                                loggingContext.setServiceName("AC:PAP.createGroup");
-                               String unescapedName = URLDecoder.decode(groupName, "UTF-8");
-                               String unescapedDescription = URLDecoder.decode(groupDescription, "UTF-8");
+                               String unescapedName = null;
+                               String unescapedDescription = null;
+                               try{
+                                   unescapedName = URLDecoder.decode(groupName, "UTF-8");
+                                   unescapedDescription = URLDecoder.decode(groupDescription, "UTF-8");
+                               } catch (UnsupportedEncodingException e) {
+                                   LOGGER.error(e);
+                               }
                                PolicyDBDaoTransaction newGroupTransaction = policyDBDao.getNewTransaction();
                                try {                                   
                                        newGroupTransaction.createGroup(PolicyDBDao.createNewPDPGroupId(unescapedName), unescapedName, unescapedDescription,"XACMLPapServlet.doACPost");
@@ -1376,7 +1469,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                return;
                        }
                        // for all remaining POST operations the group must exist before the operation can be done
-                       OnapPDPGroup group = papEngine.getGroup(groupId);
+                       OnapPDPGroup group = null;
+                       try{
+                           group = papEngine.getGroup(groupId);
+                       } catch (PAPException e){
+                           LOGGER.error(e);
+                       }
                        if (group == null) {
                                String message = "Unknown groupId '" + groupId + "'";
                                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
@@ -1566,14 +1664,17 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        loggingContext.setServiceName("AC:PAP.getDefaultGroup");
                                        OnapPDPGroup group = papEngine.getDefaultGroup();
                                        // convert response object to JSON and include in the response
-                                       ObjectMapper mapper = new ObjectMapper();
-                                       mapper.writeValue(response.getOutputStream(),  group);
+                                       mapperWriteValue(new ObjectMapper(), response,  group);
                                        if (LOGGER.isDebugEnabled()) {
                                                LOGGER.debug("GET Default group req from '" + request.getRequestURL() + "'");
                                        }
                                        response.setStatus(HttpServletResponse.SC_OK);
                                        response.setHeader("content-type", "application/json");
-                                       response.getOutputStream().close();
+                                       try{
+                        response.getOutputStream().close();
+                    } catch (IOException e){
+                        LOGGER.error(e);
+                    }
                                        loggingContext.transactionEnded();
                                        auditLogger.info("Success");
                                        PolicyLogger.audit("Transaction Ended Successfully");
@@ -1585,8 +1686,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                                loggingContext.setServiceName("AC:PAP.getPDP");
                                                OnapPDP pdp = papEngine.getPDP(pdpId);
                                                // convert response object to JSON and include in the response
-                                               ObjectMapper mapper = new ObjectMapper();
-                                               mapper.writeValue(response.getOutputStream(),  pdp);
+                                               mapperWriteValue(new ObjectMapper(), response,  pdp);
                                                if (LOGGER.isDebugEnabled()) {
                                                        LOGGER.debug("GET pdp '" + pdpId + "' req from '" + request.getRequestURL() + "'");
                                                }
@@ -1603,14 +1703,17 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                                OnapPDP pdp = papEngine.getPDP(pdpId);
                                                OnapPDPGroup group = papEngine.getPDPGroup((OnapPDP) pdp);
                                                // convert response object to JSON and include in the response
-                                               ObjectMapper mapper = new ObjectMapper();
-                                               mapper.writeValue(response.getOutputStream(),  group);
+                                               mapperWriteValue(new ObjectMapper(), response,  group);
                                                if (LOGGER.isDebugEnabled()) {
                                                        LOGGER.debug("GET PDP '" + pdpId + "' Group req from '" + request.getRequestURL() + "'");
                                                }
                                                response.setStatus(HttpServletResponse.SC_OK);
                                                response.setHeader("content-type", "application/json");
-                                               response.getOutputStream().close();
+                                               try{
+                               response.getOutputStream().close();
+                           } catch (IOException e){
+                               LOGGER.error(e);
+                           }
                                                loggingContext.transactionEnded();
                                                auditLogger.info("Success");
                                                PolicyLogger.audit("Transaction Ended Successfully");
@@ -1621,14 +1724,17 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        loggingContext.setServiceName("AC:PAP.getAllGroups");
                                        Set<OnapPDPGroup> groups = papEngine.getOnapPDPGroups();
                                        // convert response object to JSON and include in the response
-                                       ObjectMapper mapper = new ObjectMapper();
-                                       mapper.writeValue(response.getOutputStream(),  groups);
+                                       mapperWriteValue(new ObjectMapper(), response,  groups);
                                        if (LOGGER.isDebugEnabled()) {
                                                LOGGER.debug("GET All groups req");
                                        }
                                        response.setStatus(HttpServletResponse.SC_OK);
                                        response.setHeader("content-type", "application/json");
-                                       response.getOutputStream().close();
+                                       try{
+                           response.getOutputStream().close();
+                       } catch (IOException e){
+                           LOGGER.error(e);
+                       }
                                        loggingContext.transactionEnded();
                                        auditLogger.info("Success");
                                        PolicyLogger.audit("Transaction Ended Successfully");
@@ -1641,7 +1747,6 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                String message = "Unknown groupId '" + groupId + "'";
                                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
                                loggingContext.transactionEnded();
-
                                PolicyLogger.audit("Transaction Failed - See Error.log");
                                setResponseError(response,HttpServletResponse.SC_NOT_FOUND, message);
                                return;
@@ -1660,14 +1765,17 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                // No other parameters, so return the identified Group
                                loggingContext.setServiceName("AC:PAP.getGroup");
                                // convert response object to JSON and include in the response
-                               ObjectMapper mapper = new ObjectMapper();
-                               mapper.writeValue(response.getOutputStream(),  group);
+                               mapperWriteValue(new ObjectMapper(), response,  group);
                                if (LOGGER.isDebugEnabled()) {
                                        LOGGER.debug("GET group '" + group.getId() + "' req from '" + request.getRequestURL() + "'");
                                }
                                response.setStatus(HttpServletResponse.SC_OK);
                                response.setHeader("content-type", "application/json");
-                               response.getOutputStream().close();
+                               try{
+                                   response.getOutputStream().close();
+                               } catch (IOException e){
+                                   LOGGER.error(e);
+                               }
                                loggingContext.transactionEnded();
                                auditLogger.info("Success");
                                PolicyLogger.audit("Transaction Ended Successfully");
@@ -1738,7 +1846,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                // get the request content into a String
                                String json = null;
                                // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file)
-                               java.util.Scanner scanner = new java.util.Scanner(request.getInputStream());
+                               Scanner scanner = null;
+                               try{
+                                   scanner = new Scanner(request.getInputStream());
+                               }catch(IOException e){
+                                   LOGGER.error(e);
+                               }
                                scanner.useDelimiter("\\A");
                                json =  scanner.hasNext() ? scanner.next() : "";
                                scanner.close();
@@ -1768,7 +1881,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                                                        +"pdp="+ (pdp.getId()) +",to group="+group.getId());
                                                        throw new PAPException(e.getMessage());
                                                }
-                                               papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort());
+                                               try{
+                                                   papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort());
+                                               }catch(PAPException e){
+                                                   LOGGER.error(e);
+                                               }
                                        } else {
                                                try{
                                                        acPutTransaction.updatePdp(pdp, "XACMLPapServlet.doACPut");
@@ -1778,7 +1895,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                                        throw new PAPException(e.getMessage());
                                                }
                                                // this is a request to update the pdp
-                                               papEngine.updatePDP(pdp);
+                                               try{
+                                                   papEngine.updatePDP(pdp);
+                                               }catch(PAPException e){
+                            LOGGER.error(e);
+                        }
                                        }
                                        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
                                        if (LOGGER.isDebugEnabled()) {
@@ -1819,7 +1940,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                // get the request content into a String
                                String json = null;
                                // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file)
-                               java.util.Scanner scanner = new java.util.Scanner(request.getInputStream());
+                               Scanner scanner = null;
+                try{
+                    scanner = new Scanner(request.getInputStream());
+                }catch(IOException e){
+                    LOGGER.error(e);
+                }
                                scanner.useDelimiter("\\A");
                                json =  scanner.hasNext() ? scanner.next() : "";
                                scanner.close();
@@ -1845,6 +1971,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                } catch(Exception e){
                                        PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " Error while updating group in the database: "
                                                        +"group="+group.getId());
+                                       LOGGER.error(e);
                                        throw new PAPException(e.getMessage());
                                }
                                
@@ -1853,9 +1980,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                if (pushPolicyHandler.preSafetyCheck(updatedGroup, configHome)) {               
                                        LOGGER.debug("Precheck Successful.");
                                }
-                               
-                papEngine.updateGroup((StdPDPGroup)objectFromJSON);
-
+                               try{
+                                   papEngine.updateGroup((StdPDPGroup)objectFromJSON);
+                               }catch(PAPException e){
+                                   LOGGER.error(e);
+                               }
                                response.setStatus(HttpServletResponse.SC_NO_CONTENT);
                                if (LOGGER.isDebugEnabled()) {
                                        LOGGER.debug("Group '" + group.getId() + "' updated");
@@ -1899,7 +2028,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        try{
                                policyToDelete = URLDecoder.decode(policyToDelete,"UTF-8");
                        } catch(UnsupportedEncodingException e){
-                               PolicyLogger.error("Unsupported URL encoding of policyToDelete (UTF-8");
+                               LOGGER.error("Unsupported URL encoding of policyToDelete (UTF-8", e);
                                setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"policyToDelete encoding not supported");
                                return;
                        }
@@ -1945,9 +2074,13 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                try{
                                        removePdpOrGroupTransaction.removePdpFromGroup(pdp.getId(),"XACMLPapServlet.doACDelete");
                                } catch(Exception e){
-                                       throw new PAPException();
+                                       throw new PAPException(e);
                                }
-                               papEngine.removePDP((OnapPDP) pdp);
+                               try{
+                       papEngine.removePDP((OnapPDP) pdp);
+                               }catch(PAPException e){
+                    LOGGER.error(e);
+                }
                                // adjust the status of the group, which may have changed when we removed this PDP
                                ((StdPDPGroup)group).resetStatus();
                                response.setStatus(HttpServletResponse.SC_NO_CONTENT);
@@ -1972,7 +2105,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                String moveToGroupId = request.getParameter("movePDPsToGroupId");
                                OnapPDPGroup moveToGroup = null;
                                if (moveToGroupId != null) {
-                                       moveToGroup = papEngine.getGroup(moveToGroupId);
+                                   try{
+                                       moveToGroup = papEngine.getGroup(moveToGroupId);
+                                   }catch(PAPException e){
+                           LOGGER.error(e);
+                       }
                                }
                                // get list of PDPs in the group being deleted so we can notify them that they got changed
                                Set<OnapPDP> movedPDPs = new HashSet<>();
@@ -1984,7 +2121,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, e, "XACMLPapServlet", " Failed to delete PDP Group. Exception");
                                        throw new PAPException(e.getMessage());
                                }
-                               papEngine.removeGroup(group, moveToGroup);
+                               try{
+                                   papEngine.removeGroup(group, moveToGroup);
+                               }catch(PAPException e){
+                    LOGGER.error(e);
+                }
                                response.setStatus(HttpServletResponse.SC_NO_CONTENT);
                                notifyAC();
                                // notify any PDPs in the removed set that their config may have changed
@@ -2215,7 +2356,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        groups = papEngine.getOnapPDPGroups();
                } catch (PAPException e) {
                        PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " getPDPGroups failed");
-                       throw new RuntimeException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get Groups: " + e);
+                       throw new IllegalAccessError(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get Groups: " + e);
                }
                for (OnapPDPGroup group : groups) {
                        groupChanged(group);
@@ -2463,7 +2604,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        }
                        String message = "GET:/pap/test called and PAP " + papResourceName + " has had a subsystem failure."
                                        + " Exception Message: " + eMsg;
-                       LOGGER.info(message);
+                       LOGGER.info(message, e);
                        PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Failed - See Error.log");
@@ -2514,7 +2655,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                try {
                                        Files.createDirectories(webappsPathConfig);
                                } catch (IOException e) {
-                                       PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Failed to create config directory: "
+                                       PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", "Failed to create config directory: "
                                                        + webappsPathConfig.toAbsolutePath().toString());
                                }
                        }
@@ -2522,7 +2663,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                try {
                                        Files.createDirectories(webappsPathAction);
                                } catch (IOException e) {
-                                       LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: "
+                                       LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create action directory: "
                                                        + webappsPathAction.toAbsolutePath().toString(), e);
                                }
                        }