X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FAutoPushController.java;h=b26709ff4cbe8490dedf9005fea8271489915349;hp=f97a131a0a4bbb14f39c15b7cb782701da8e5621;hb=1e61676b77dd09659027b8984f050df7e8538526;hpb=f36e53a3637e1204a42491ec0eeed7b3c763f681 diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java index f97a131a0..b26709ff4 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java @@ -31,7 +31,6 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; -import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -80,7 +79,6 @@ import org.springframework.web.servlet.ModelAndView; public class AutoPushController extends RestrictedBaseController { private static final Logger logger = FlexLogger.getLogger(AutoPushController.class); - private static final String UTF8 = "UTF-8"; @Autowired CommonClassDao commonClassDao; @@ -195,6 +193,11 @@ public class AutoPushController extends RestrictedBaseController { public ModelAndView pushPolicyToPDPGroup(HttpServletRequest request, HttpServletResponse response) throws IOException { try { + response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); + request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); + // + // + // ArrayList selectedPdps = new ArrayList<>(); ArrayList selectedPoliciesInUI = new ArrayList<>(); PolicyController controller = getPolicyControllerInstance(); @@ -334,24 +337,12 @@ public class AutoPushController extends RestrictedBaseController { currentPoliciesInGroup.addAll(selectedPolicies); updatedGroupObject.setPolicies(currentPoliciesInGroup); this.container.updateGroup(updatedGroupObject, userId); - - response.setCharacterEncoding(UTF8); - response.setContentType("application / json"); - request.setCharacterEncoding(UTF8); - - PrintWriter out = response.getWriter(); + response.setContentType(PolicyUtils.APPLICATION_JSON); refreshGroups(); - JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups)); - out.write(new JSONObject(msg).toString()); - // - // Why is this here? This defeats the purpose of the loop?? - // Sonar says to remove it or make it conditional - // - return null; + response.getWriter().write(new JSONObject( + new JsonMessage(mapper.writeValueAsString(groups))).toString()); } } catch (Exception e) { - response.setCharacterEncoding(UTF8); - request.setCharacterEncoding(UTF8); logger.error(e); response.getWriter().write(PolicyUtils.CATCH_EXCEPTION); } @@ -365,6 +356,11 @@ public class AutoPushController extends RestrictedBaseController { @RequestMapping(value = {"/auto_Push/remove_GroupPolicies.htm"}, method = {RequestMethod.POST}) public ModelAndView removePDPGroup(HttpServletRequest request, HttpServletResponse response) throws IOException { try { + response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); + request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); + // + // + // PolicyController controller = getPolicyControllerInstance(); this.container = new PDPGroupContainer(controller.getPapEngine()); ObjectMapper mapper = new ObjectMapper(); @@ -397,17 +393,11 @@ public class AutoPushController extends RestrictedBaseController { this.container.updateGroup(updatedGroupObject); } - response.setCharacterEncoding(UTF8); - response.setContentType("application / json"); - request.setCharacterEncoding(UTF8); + response.setContentType(PolicyUtils.APPLICATION_JSON); - PrintWriter out = response.getWriter(); refreshGroups(); - out.write(new JSONObject(new JsonMessage(mapper.writeValueAsString(groups))).toString()); - return null; + response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(groups))).toString()); } catch (Exception e) { - response.setCharacterEncoding(UTF8); - request.setCharacterEncoding(UTF8); logger.error(e); response.getWriter().write(PolicyUtils.CATCH_EXCEPTION); }