aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org/onap
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2017-09-11 14:29:37 +0000
committerGerrit Code Review <gerrit@onap.org>2017-09-11 14:29:37 +0000
commit1bfd18f999cda39a7b27bef8972864aafe59aecb (patch)
tree7474d9dc36ee5a5645355e13916961622bc0f18b /ONAP-PAP-REST/src/main/java/org/onap
parentcc4274f251d7c634cfa2d1dc5bccdd4de9fb1c2b (diff)
parentb4d71bc89bef6eb2659eb54bdebcc7f9acbba127 (diff)
Merge "Fix critical sonar for ONAP-PAP-REST"
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org/onap')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java27
1 files changed, 15 insertions, 12 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
index 121e4bc0b..b3ac236cf 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
@@ -53,6 +53,7 @@ import javax.persistence.PersistenceException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
@@ -337,6 +338,14 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
initiateThread.start();
}
+ private static void mapperWriteValue(ObjectMapper mapper, ServletOutputStream out, Object value) {
+ try {
+ mapper.writeValue(out, value);
+ } catch (Exception e) {
+ LOGGER.debug(e);
+ }
+ }
+
private static void startHeartBeatService(Heartbeat heartbeat) {
XACMLPapServlet.heartbeat = heartbeat;
XACMLPapServlet.heartbeatThread = new Thread(XACMLPapServlet.heartbeat);
@@ -819,8 +828,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
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.getOutputStream(), groups);
response.setHeader("content-type", "application/json");
response.setStatus(HttpServletResponse.SC_OK);
loggingContext.transactionEnded();
@@ -1605,8 +1613,7 @@ 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.getOutputStream(), group);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GET Default group req from '" + request.getRequestURL() + "'");
}
@@ -1624,8 +1631,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
loggingContext.setServiceName("AC:PAP.getPDP");
OnapPDP pdp = papEngine.getPDP(pdpId);
// convert response object to JSON and include in the response
- ObjectMapper mapper = new ObjectMapper();
- mapper.writeValue(response.getOutputStream(), pdp);
+ mapperWriteValue(new ObjectMapper(), response.getOutputStream(), pdp);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GET pdp '" + pdpId + "' req from '" + request.getRequestURL() + "'");
}
@@ -1642,8 +1648,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
OnapPDP pdp = papEngine.getPDP(pdpId);
OnapPDPGroup group = papEngine.getPDPGroup((OnapPDP) pdp);
// convert response object to JSON and include in the response
- ObjectMapper mapper = new ObjectMapper();
- mapper.writeValue(response.getOutputStream(), group);
+ mapperWriteValue(new ObjectMapper(), response.getOutputStream(), group);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GET PDP '" + pdpId + "' Group req from '" + request.getRequestURL() + "'");
}
@@ -1660,8 +1665,7 @@ 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.getOutputStream(), groups);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GET All groups req");
}
@@ -1699,8 +1703,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// No other parameters, so return the identified Group
loggingContext.setServiceName("AC:PAP.getGroup");
// convert response object to JSON and include in the response
- ObjectMapper mapper = new ObjectMapper();
- mapper.writeValue(response.getOutputStream(), group);
+ mapperWriteValue(new ObjectMapper(), response.getOutputStream(), group);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GET group '" + group.getId() + "' req from '" + request.getRequestURL() + "'");
}