Merge "Added JUNITS for ONAP-REST Component"
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / controller / EnforcerDictionaryController.java
index f0389fc..9e248bf 100644 (file)
@@ -20,7 +20,9 @@
 
 package org.onap.policy.pap.xacml.rest.controller;
 
+import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -35,6 +37,7 @@ import org.onap.policy.common.logging.flexlogger.Logger;
 import org.onap.policy.pap.xacml.rest.util.JsonMessage;
 import org.onap.policy.rest.dao.CommonClassDao;
 import org.onap.policy.rest.jpa.EnforcingType;
+import org.onap.policy.utils.PolicyUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Controller;
@@ -54,7 +57,7 @@ public class EnforcerDictionaryController {
        CommonClassDao commonClassDao;
 
        @RequestMapping(value={"/get_EnforcerTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getEnforcerDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
+       public void getEnforcerDictionaryEntityData(HttpServletResponse response){
                try{
                        Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
@@ -75,7 +78,7 @@ public class EnforcerDictionaryController {
        }
        
        @RequestMapping(value={"/enforcer_dictionary/save_enforcerType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
-       public ModelAndView saveEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
+       public ModelAndView saveEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
                try {
                        ObjectMapper mapper = new ObjectMapper();
                        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@@ -102,13 +105,14 @@ public class EnforcerDictionaryController {
                        response.setCharacterEncoding("UTF-8");
                        request.setCharacterEncoding("UTF-8");
                        PrintWriter out = response.getWriter();
-                       out.write(e.getMessage());
+                       out.write(PolicyUtils.CATCH_EXCEPTION);
+                       LOGGER.error(e);
                }
                return null;
        }
 
        @RequestMapping(value={"/enforcer_dictionary/remove_enforcer"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
-       public ModelAndView removeEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
+       public ModelAndView removeEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
                try{
                        ObjectMapper mapper = new ObjectMapper();
                        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@@ -132,7 +136,7 @@ public class EnforcerDictionaryController {
                        response.setCharacterEncoding("UTF-8");
                        request.setCharacterEncoding("UTF-8");
                        PrintWriter out = response.getWriter();
-                       out.write(e.getMessage());
+                       out.write(PolicyUtils.CATCH_EXCEPTION);
                }
                return null;
        }