summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org/onap
diff options
context:
space:
mode:
authorGuo Ruijing <ruijing.guo@intel.com>2017-09-08 07:49:04 +0000
committerGuo Ruijing <ruijing.guo@intel.com>2017-09-11 09:11:18 +0000
commitb4d71bc89bef6eb2659eb54bdebcc7f9acbba127 (patch)
tree2aa70d548c4f5d6293ca09570eab213ea0fe798b /ONAP-PAP-REST/src/main/java/org/onap
parent461b2b7eeca1586423349bc0c4c65f80f027292d (diff)
Fix critical sonar for ONAP-PAP-REST
This patch is to fix sonar issue for ONAP-PAP-REST. Change-Id: I71530f1f92e5eda479e04c495bb7858b9d995b73 Issue-Id: POLICY-174 Signed-off-by: Guo Ruijing <ruijing.guo@intel.com>
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 5132fae48..c1c2575a5 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;
@@ -335,6 +336,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);
@@ -780,8 +789,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();
@@ -1566,8 +1574,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() + "'");
}
@@ -1585,8 +1592,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() + "'");
}
@@ -1603,8 +1609,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() + "'");
}
@@ -1621,8 +1626,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");
}
@@ -1660,8 +1664,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() + "'");
}