sonar blocker/critical fixes
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / XACMLPapServlet.java
index e11538c..4d3fe06 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;
@@ -170,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;
        
        /**
@@ -283,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
@@ -334,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);
@@ -535,7 +547,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                                PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message);
                                                loggingContext.transactionEnded();
                                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                                               response.sendError(HttpServletResponse.SC_FORBIDDEN, message);
+                                               setResponseError(response,HttpServletResponse.SC_FORBIDDEN, message);
                                                im.endTransaction();
                                                return;
                                        }
@@ -563,18 +575,22 @@ 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);
                                                loggingContext.transactionEnded();
                                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                                               response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
+                                               setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
                                                im.endTransaction();
                                                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();
@@ -583,7 +599,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                                PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " " + message);
                                                loggingContext.transactionEnded();
                                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                                               response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+                                               setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                                                im.endTransaction();
                                                return;
                                        }
@@ -591,7 +607,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        String message = "PDP is Unauthorized to Connect to PAP: "+ id;
                                        PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message);
                                        loggingContext.transactionEnded();
-                                       response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "PDP not Authorized to connect to this PAP. Please contact the PAP Admin for registration.");
+                                       setResponseError(response, HttpServletResponse.SC_UNAUTHORIZED, "PDP not Authorized to connect to this PAP. Please contact the PAP Admin for registration.");
                                        PolicyLogger.audit("Transaction Failed - See Error.log");
                                        im.endTransaction();
                                        return;
@@ -603,15 +619,24 @@ 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();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "PDP not associated with any group, even the default");
+                               setResponseError(response, HttpServletResponse.SC_UNAUTHORIZED, "PDP not associated with any group, even the default");
                                im.endTransaction();
                                return;
                        }
@@ -621,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"));
@@ -636,33 +665,49 @@ 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();
                        loggingContext.transactionEnded();
                        auditLogger.info("Success");
                        PolicyLogger.audit("Transaction Ended Successfully");
-               } catch (PAPException e) {
+               } catch (PAPException | IOException | NumberFormatException e) {
                        if(pdpTransaction != null){
                                pdpTransaction.rollbackTransaction();
                        }
                        LOGGER.debug(XACMLErrorConstants.ERROR_PROCESS_FLOW + "POST exception: " + e, e);
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                       response.sendError(500, e.getMessage());
+                       setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
                        im.endTransaction();
                        return;
                }
@@ -702,7 +747,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        if (pathInfo != null){
                                //DO NOT do a im.startTransaction for the test request
                                if (pathInfo.equals("/pap/test")) {
-                                       testService(loggingContext, response);
+                                       try {
+                                               testService(loggingContext, response);
+                                       } catch (IOException e) {
+                                               LOGGER.debug(e);
+                                       }
                                        return;
                                }
                        }
@@ -713,21 +762,21 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                String message = "GET 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");
-                               response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+                               setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                                return;
                        }catch (StandbyStatusException se) {
                                String message = "GET 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");
-                               response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+                               setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                                return;
                        }
                        // Request from the API to get the gitPath
@@ -735,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();
@@ -745,7 +798,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message);
                                        loggingContext.transactionEnded();
                                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                                       response.sendError(HttpServletResponse.SC_FORBIDDEN, message);
+                                       setResponseError(response, HttpServletResponse.SC_FORBIDDEN, message);
                                        im.endTransaction();
                                        return;
                                }
@@ -754,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();
@@ -764,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("127.0.0.1") ||
                                                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();
@@ -788,19 +848,24 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message);
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_UNAUTHORIZED, message);
+                               setResponseError(response, HttpServletResponse.SC_UNAUTHORIZED, message);
                                im.endTransaction();
                                return;
                        }
                        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);
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_UNAUTHORIZED, message);
+                               setResponseError(response, HttpServletResponse.SC_UNAUTHORIZED, message);
                                im.endTransaction();
                                return;
                        }
@@ -811,7 +876,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                LOGGER.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + message);
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
+                               setResponseError(response,HttpServletResponse.SC_NOT_FOUND, message);
                                im.endTransaction();
                                return;
                        }
@@ -821,12 +886,16 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                LOGGER.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + message);
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
+                               setResponseError(response,HttpServletResponse.SC_NOT_FOUND, message);
                                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);
@@ -836,16 +905,18 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                PolicyLogger.audit("Transaction Ended Successfully");
                        } catch (IOException e) {
                                String message = "Failed to open policy id " + policyId;
+                               LOGGER.debug(e);
                                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
+                               setResponseError(response,HttpServletResponse.SC_NOT_FOUND, message);
                        }
                }  catch (PAPException e) {
+                       LOGGER.debug(e);
                        PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, e, "XACMLPapServlet", " GET exception");
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                       response.sendError(500, e.getMessage());
+                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
                        im.endTransaction();
                        return;
                }
@@ -870,27 +941,26 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                }
                try {
                        im.startTransaction();
-               } catch (AdministrativeStateException ae){
-                       String message = "PUT interface called for PAP " + papResourceName + " but it has an Administrative"
-                                       + " state of " + im.getStateManager().getAdminState()
-                                       + "\n Exception Message: " + ae.getMessage();
-                       LOGGER.info(message +ae);
-                       PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
-                       loggingContext.transactionEnded();
-                       PolicyLogger.audit("Transaction Failed - See Error.log");
-                       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
-                       return;
-               }catch (StandbyStatusException se) {
-                       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  +se);
+               } catch (AdministrativeStateException | StandbyStatusException e) {
+                       String message = "PUT interface called for PAP " + papResourceName;
+                       if (e instanceof AdministrativeStateException) {
+                               message += " but it has an Administrative state of "
+                                       + im.getStateManager().getAdminState();
+                       } else if (e instanceof StandbyStatusException) {
+                               message += " but it has a Standby Status of "
+                                       + im.getStateManager().getStandbyStatus();
+
+                       }
+                       message += "\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");
-                       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                        return;
                }
+
                XACMLRest.dumpRequest(request);
                //need to check if request is from the API or Admin console
                String apiflag = request.getParameter("apiflag");
@@ -898,11 +968,10 @@ 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){
-                               response.sendError(400, "entityid or entitytype not supplied");
+                               setResponseError(response,400, "entityid or entitytype not supplied");
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Ended Successfully");
                                im.endTransaction();
@@ -922,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 {
@@ -930,7 +1003,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS + message );
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_FORBIDDEN, message);
+                               setResponseError(response,HttpServletResponse.SC_FORBIDDEN, message);
                                return;
                        }
                }
@@ -953,7 +1026,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        } catch(UnsupportedEncodingException e){
                                PolicyLogger.error("\nXACMLPapServlet.doPut() - Unsupported URL encoding of policyToCreateUpdate (UTF-8)"
                                                + "\npolicyToCreateUpdate = " + " ");
-                               response.sendError(500,"policyToCreateUpdate encoding not supported"
+                               setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"policyToCreateUpdate encoding not supported"
                                                + "\nfailure with the following exception: " + e);
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See error.log");
@@ -966,7 +1039,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                renameTransaction.renamePolicy(oldPolicyName,newPolicyName, "XACMLPapServlet.doPut");
                        }catch(Exception e){
                                renameTransaction.rollbackTransaction();
-                               response.sendError(500,"createUpdateTransaction.createPolicy(policyToCreateUpdate, XACMLPapServlet.doPut) "
+                               setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"createUpdateTransaction.createPolicy(policyToCreateUpdate, XACMLPapServlet.doPut) "
                                                + "\nfailure with the following exception: " + e);
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See error.log");
@@ -1013,11 +1086,15 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message);
                                        loggingContext.transactionEnded();
                                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                                       response.sendError(HttpServletResponse.SC_FORBIDDEN, message);
+                                       setResponseError(response,HttpServletResponse.SC_FORBIDDEN, message);
                                        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();
@@ -1025,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();
@@ -1037,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();
@@ -1046,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();
@@ -1056,7 +1145,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message);
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_FORBIDDEN, message);
+                               setResponseError(response,HttpServletResponse.SC_FORBIDDEN, message);
                                im.endTransaction();
                                return;
                        }
@@ -1066,7 +1155,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Request does not have groupId or apiflag");
                loggingContext.transactionEnded();
                PolicyLogger.audit("Transaction Failed - See Error.log");
-               response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request does not have groupId or apiflag");
+               setResponseError(response,HttpServletResponse.SC_BAD_REQUEST, "Request does not have groupId or apiflag");
                loggingContext.transactionEnded();
                PolicyLogger.audit("Transaction Failed - See error.log");
                im.endTransaction();
@@ -1092,21 +1181,21 @@ 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");
-                       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                        return;
                }catch (StandbyStatusException se) {
                        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");
-                       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                        return;
                }
                XACMLRest.dumpRequest(request);
@@ -1120,7 +1209,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message);
                                        loggingContext.transactionEnded();
                                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                                       response.sendError(HttpServletResponse.SC_FORBIDDEN, message);
+                                       setResponseError(response,HttpServletResponse.SC_FORBIDDEN, message);
                                        return;
                                }
                                APIRequestHandler apiRequestHandler = new APIRequestHandler();
@@ -1135,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();
@@ -1145,7 +1238,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Request does not have groupId");
                loggingContext.transactionEnded();
                PolicyLogger.audit("Transaction Failed - See Error.log");
-               response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request does not have groupId");
+               setResponseError(response,HttpServletResponse.SC_BAD_REQUEST, "Request does not have groupId");
                im.endTransaction();
        }
 
@@ -1313,7 +1406,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Failed - See Error.log");
                        String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + "Exception in request to update group from API - See Error.log on on the PAP.";
-                       response.sendError(500, e.getMessage());
+                       setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
                        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                        response.addHeader("error","addGroupError");
                        response.addHeader("message", message);
@@ -1340,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");
@@ -1353,7 +1452,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        loggingContext.transactionEnded();
        
                                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                                       response.sendError(500, "Unable to create new group '" + groupId + "'");
+                                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to create new group '" + groupId + "'");
                                        return;
                                }
                                response.setStatus(HttpServletResponse.SC_NO_CONTENT);
@@ -1370,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);
@@ -1382,7 +1486,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        response.addHeader("message", message);
                                        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
                                } else {
-                                       response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
+                                       setResponseError(response,HttpServletResponse.SC_NOT_FOUND, message);
                                }
                                return;
                        }
@@ -1445,7 +1549,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                                response.addHeader("message", message);
                                                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                                        } else {
-                                               response.sendError(500, message);
+                                               setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                                        }
                                        return;
                                }
@@ -1470,7 +1574,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                PolicyDBDaoTransaction setDefaultGroupTransaction = policyDBDao.getNewTransaction();
                                try {
                                        setDefaultGroupTransaction.changeDefaultGroup(group, "XACMLPapServlet.doACPost");
-                                       papEngine.SetDefaultGroup(group);
+                                       papEngine.setDefaultGroup(group);
                                        setDefaultGroupTransaction.commitTransaction();
                                } catch (Exception e) {
                                        setDefaultGroupTransaction.rollbackTransaction();
@@ -1478,7 +1582,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        loggingContext.transactionEnded();
        
                                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                                       response.sendError(500, "Unable to set group '" + groupId + "' to default");
+                                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to set group '" + groupId + "' to default");
                                        return;
                                }
                                response.setStatus(HttpServletResponse.SC_NO_CONTENT);
@@ -1533,7 +1637,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " AC POST exception");
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                       response.sendError(500, e.getMessage());
+                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
                        return;
                }
        }
@@ -1548,7 +1652,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
         * @throws ServletException
         * @throws IOException
         */
-       private void doACGet(HttpServletRequest request, HttpServletResponse response, String groupId, ONAPLoggingContext loggingContext) throws ServletException, IOException {
+       private void doACGet(HttpServletRequest request, HttpServletResponse response, String groupId, ONAPLoggingContext loggingContext) throws IOException {
                try {
                        String parameterDefault = request.getParameter("default");
                        String pdpId = request.getParameter("pdpId");
@@ -1560,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");
@@ -1577,16 +1684,24 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        if (pdpGroup == null) {
                                                // Request is for the (unspecified) group containing a given PDP
                                                loggingContext.setServiceName("AC:PAP.getPDP");
-                                               OnapPDP pdp = papEngine.getPDP(pdpId);
+                                               OnapPDP pdp = null;
+                                               try{
+                                                   pdp = papEngine.getPDP(pdpId);
+                                               }catch(PAPException e){
+                                                   LOGGER.error(e);
+                                               }
                                                // 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() + "'");
                                                }
                                                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");
@@ -1594,17 +1709,25 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        } else {
                                                // Request is for the group containing a given PDP
                                                loggingContext.setServiceName("AC:PAP.getGroupForPDP");
-                                               OnapPDP pdp = papEngine.getPDP(pdpId);
-                                               OnapPDPGroup group = papEngine.getPDPGroup((OnapPDP) pdp);
+                                               OnapPDPGroup group =null;
+                                               try{
+                                                   OnapPDP pdp = papEngine.getPDP(pdpId);
+                               group = papEngine.getPDPGroup((OnapPDP) pdp);
+                                               }catch(PAPException e){
+                                                   LOGGER.error(e);
+                                               }
                                                // 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");
@@ -1615,14 +1738,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");
@@ -1630,14 +1756,18 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                }
                        }
                        // for all other GET 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);
                                loggingContext.transactionEnded();
-
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
+                               setResponseError(response,HttpServletResponse.SC_NOT_FOUND, message);
                                return;
                        }
                        // Figure out which request this is based on the parameters
@@ -1649,19 +1779,22 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " GET Policy not implemented");
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_BAD_REQUEST, "GET Policy not implemented");
+                               setResponseError(response,HttpServletResponse.SC_BAD_REQUEST, "GET Policy not implemented");
                        } else {
                                // 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");
@@ -1676,12 +1809,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " UNIMPLEMENTED ");
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                       response.sendError(HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED");
+                       setResponseError(response,HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED");
                } catch (PAPException e) {
                        PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " AC Get exception");
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                       response.sendError(500, e.getMessage());
+                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
                        return;
                }
        }
@@ -1696,7 +1829,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
         * @throws ServletException
         * @throws IOException
         */
-       private void doACPut(HttpServletRequest request, HttpServletResponse response, String groupId, ONAPLoggingContext loggingContext) throws ServletException, IOException {
+       private void doACPut(HttpServletRequest request, HttpServletResponse response, String groupId, ONAPLoggingContext loggingContext) throws IOException {
                PolicyDBDaoTransaction acPutTransaction = policyDBDao.getNewTransaction();
                try {
                        // for PUT operations the group may or may not need to exist before the operation can be done
@@ -1708,7 +1841,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
+                               setResponseError(response,HttpServletResponse.SC_NOT_FOUND, message);
                                return;
                        }
                        if (request.getParameter("policy") != null) {
@@ -1732,10 +1865,14 @@ 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.useDelimiter("\\A");
-                               json =  scanner.hasNext() ? scanner.next() : "";
-                               scanner.close();
+                               try{
+                                   Scanner scanner = new Scanner(request.getInputStream());
+                                   scanner.useDelimiter("\\A");
+                       json =  scanner.hasNext() ? scanner.next() : "";
+                       scanner.close();
+                               }catch(IOException e){
+                                   LOGGER.error(e);
+                               }
                                LOGGER.info("JSON request from AC: " + json);
                                // convert Object sent as JSON into local object
                                ObjectMapper mapper = new ObjectMapper();
@@ -1748,11 +1885,17 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PDP new/update had bad input. pdpId=" + pdpId + " objectFromJSON="+objectFromJSON);
                                        loggingContext.transactionEnded();
                                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                                       response.sendError(500, "Bad input, pdpid="+pdpId+" object="+objectFromJSON);
+                                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad input, pdpid="+pdpId+" object="+objectFromJSON);
                                }
                                StdPDP pdp = (StdPDP) objectFromJSON;
                                if(pdp != null){
-                                       if (papEngine.getPDP(pdpId) == null) {
+                                   OnapPDP oPDP = null;
+                                   try{
+                                       oPDP = papEngine.getPDP(pdpId);
+                                   }catch (PAPException e){
+                                       LOGGER.error(e);
+                                   }
+                                       if (oPDP == null) {
                                                // this is a request to create a new PDP object
                                                try{
                                                        acPutTransaction.addPdpToGroup(pdp.getId(), group.getId(), pdp.getName(), 
@@ -1762,7 +1905,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");
@@ -1772,7 +1919,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()) {
@@ -1804,7 +1955,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " UNIMPLEMENTED");
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED");
+                               setResponseError(response,HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED");
                                return;
                        } else {
                                // Assume that this is an update of an existing PDP Group
@@ -1813,10 +1964,14 @@ 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.useDelimiter("\\A");
-                               json =  scanner.hasNext() ? scanner.next() : "";
-                               scanner.close();
+                try{
+                    Scanner scanner = new Scanner(request.getInputStream());
+                    scanner.useDelimiter("\\A");
+                    json =  scanner.hasNext() ? scanner.next() : "";
+                    scanner.close();
+                }catch(IOException e){
+                    LOGGER.error(e);
+                }
                                LOGGER.info("JSON request from AC: " + json);
                                // convert Object sent as JSON into local object
                                ObjectMapper mapper = new ObjectMapper();
@@ -1826,7 +1981,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + group.getId() + " objectFromJSON="+objectFromJSON);
                                        loggingContext.transactionEnded();
                                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                                       response.sendError(500, "Bad input, id="+group.getId() +" object="+objectFromJSON);
+                                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad input, id="+group.getId() +" object="+objectFromJSON);
                                }
                                // The Path on the PAP side is not carried on the RESTful interface with the AC
                                // (because it is local to the PAP)
@@ -1839,6 +1994,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());
                                }
                                
@@ -1847,9 +2003,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");
@@ -1865,11 +2023,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                return;
                        }
                } catch (PAPException e) {
+                       LOGGER.debug(e);
                        acPutTransaction.rollbackTransaction();
                        PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " AC PUT exception");
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                       response.sendError(500, e.getMessage());
+                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
                        return;
                }
        }
@@ -1884,7 +2043,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
         * @throws ServletException
         * @throws IOException
         */
-       private void doACDelete(HttpServletRequest request, HttpServletResponse response, String groupId, ONAPLoggingContext loggingContext) throws ServletException, IOException {
+       private void doACDelete(HttpServletRequest request, HttpServletResponse response, String groupId, ONAPLoggingContext loggingContext) throws IOException {
                //This code is to allow deletes to propagate to the database since delete is not implemented
                String isDeleteNotify = request.getParameter("isDeleteNotify");
                if(isDeleteNotify != null){
@@ -1892,8 +2051,8 @@ 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");
-                               response.sendError(500,"policyToDelete encoding not supported");
+                               LOGGER.error("Unsupported URL encoding of policyToDelete (UTF-8", e);
+                               setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"policyToDelete encoding not supported");
                                return;
                        }
                        PolicyDBDaoTransaction deleteTransaction = policyDBDao.getNewTransaction();
@@ -1901,7 +2060,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                deleteTransaction.deletePolicy(policyToDelete);
                        } catch(Exception e){
                                deleteTransaction.rollbackTransaction();
-                               response.sendError(500,"deleteTransaction.deleteTransaction(policyToDelete) "
+                               setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"deleteTransaction.deleteTransaction(policyToDelete) "
                                                + "\nfailure with the following exception: " + e);
                                return;
                        }
@@ -1919,7 +2078,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unknown groupId '" + groupId +"'");
+                               setResponseError(response,HttpServletResponse.SC_NOT_FOUND, "Unknown groupId '" + groupId +"'");
                                return;
                        }
                        // determine the operation needed based on the parameters in the request
@@ -1929,7 +2088,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " UNIMPLEMENTED");
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED");
+                               setResponseError(response,HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED");
                                return;
                        } else if (request.getParameter("pdpId") != null) {
                                // ARGS:        group=<groupId> pdpId=<pdpId>                  <= delete PDP 
@@ -1938,9 +2097,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);
@@ -1958,14 +2121,18 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " UNIMPLEMENTED");
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed - See Error.log");
-                               response.sendError(HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED");
+                               setResponseError(response,HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED");
                                return;
                        } else {
                                // ARGS:      group=<groupId> movePDPsToGroupId=<movePDPsToGroupId>            <= delete a group and move all its PDPs to the given group
                                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<>();
@@ -1977,7 +2144,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
@@ -1995,7 +2166,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " AC DELETE exception");
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                       response.sendError(500, e.getMessage());
+                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
                        return;
                }
        }
@@ -2169,6 +2340,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        } catch (InterruptedException e) {
                                PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " Heartbeat interrupted.  Shutting down");
                                this.terminate();
+                               Thread.currentThread().interrupt();
                        }
                }
        }
@@ -2207,7 +2379,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);
@@ -2328,12 +2500,14 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                        setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN);
                                }
                        } catch (Exception e) {
+                               LOGGER.debug(e);
                                PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Unable to sync config with PDP '" + pdp.getId() + "'");
                                loggingContext.transactionEnded();
                                PolicyLogger.audit("Transaction Failed: Unable to sync config with PDP '" + pdp.getId() + "': " + e);
                                try {
                                        setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN);
                                } catch (PAPException e1) {
+                                       LOGGER.debug(e1);
                                        PolicyLogger.audit("Transaction Failed: Unable to set status of PDP " + pdp.getId() + " to UNKNOWN: " + e);
                                        PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Unable to set status of PDP '" + pdp.getId() + "' to UNKNOWN");
                                }
@@ -2427,35 +2601,23 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                        PolicyLogger.audit("Transaction Failed - See Error.log");
                        response.setStatus(HttpServletResponse.SC_OK);
                        return;
-               }catch (ForwardProgressException fpe){
-                       //No forward progress is being made
-                       String message = "GET:/pap/test called and PAP " + papResourceName + " is not making forward progress."
-                                       + " Exception Message: " + fpe.getMessage();
-                       LOGGER.info(message);
-                       PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
-                       loggingContext.transactionEnded();
-                       PolicyLogger.audit("Transaction Failed - See Error.log");
-                       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
-                       return;
-               }catch (AdministrativeStateException ase){
-                       //Administrative State is locked
-                       String message = "GET:/pap/test called and PAP " + papResourceName + " Administrative State is LOCKED "
-                                       + " Exception Message: " + ase.getMessage();
-                       LOGGER.info(message);
-                       PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
-                       loggingContext.transactionEnded();
-                       PolicyLogger.audit("Transaction Failed - See Error.log");
-                       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
-                       return;
-               }catch (StandbyStatusException sse){
-                       //Administrative State is locked
-                       String message = "GET:/pap/test called and PAP " + papResourceName + " Standby Status is NOT PROVIDING SERVICE "
-                                       + " Exception Message: " + sse.getMessage();
-                       LOGGER.info(message);
+               }catch (ForwardProgressException | AdministrativeStateException | StandbyStatusException e){
+                       String submsg;
+                       if (e instanceof ForwardProgressException) {
+                               submsg = " is not making forward progress.";
+                       } else if (e instanceof AdministrativeStateException) {
+                               submsg = " Administrative State is LOCKED.";
+                       } else {
+                               submsg = " Standby Status is NOT PROVIDING SERVICE.";
+                       }
+
+                       String message = "GET:/pap/test called and PAP " + papResourceName + submsg
+                                       + " Exception Message: " + e.getMessage();
+                       LOGGER.info(message, e);
                        PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
                        loggingContext.transactionEnded();
                        PolicyLogger.audit("Transaction Failed - See Error.log");
-                       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+                       setResponseError(response,HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                        return;
                }catch (Exception e) {
                        //A subsystem is not making progress, is locked, standby or is not responding
@@ -2465,7 +2627,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");
@@ -2484,7 +2646,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                                ssFailureList = "UnknownSubSystem";
                        }
                        response.addHeader("X-ONAP-SubsystemFailure", ssFailureList);
-                       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+                       setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                        return;
                }
        }
@@ -2516,7 +2678,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());
                                }
                        }
@@ -2524,7 +2686,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);
                                }
                        }
@@ -2537,6 +2699,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                try {
                        loadWebapps();
                } catch (PAPException e) {
+                       LOGGER.debug(e);
                        return null;
                }
                return configHome;
@@ -2550,6 +2713,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
                try {
                        loadWebapps();
                } catch (PAPException e) {
+                       LOGGER.debug(e);
                        return null;
                }
                return actionHome;