+ @RequestMapping(value={"/searchDictionary"}, method={RequestMethod.POST})
+ public ModelAndView searchDictionaryController(HttpServletRequest request, HttpServletResponse response) throws Exception{
+ Object resultList = null;
+ String uri = request.getRequestURI();
+ try{
+ String body = callPAP(request, "POST", uri.replaceFirst("/", "").trim());
+ if(body.contains("CouldNotConnectException")){
+ List<String> data = new ArrayList<>();
+ data.add("Elastic Search Server is down");
+ resultList = data;
+ }else{
+ JSONObject json = new JSONObject(body);
+ resultList = json.get("policyresult");
+ }
+ }catch(Exception e){
+ policyLogger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Exception Occured while querying Elastic Search: " + e);
+ List<String> data = new ArrayList<>();
+ data.add("Elastic Search Server is down");
+ resultList = data;
+ }
+
+ response.setCharacterEncoding(PolicyController.getCharacterencoding());
+ response.setContentType(PolicyController.getContenttype());
+ PrintWriter out = response.getWriter();
+ JSONObject j = new JSONObject("{result: " + resultList + "}");
+ out.write(j.toString());
+ return null;
+ }
+
+ @RequestMapping(value={"/searchPolicy"}, method={RequestMethod.POST})
+ public ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{
+ Object resultList = null;
+ String uri = request.getRequestURI()+"?action=search";
+ String body = callPAP(request, "POST", uri.replaceFirst("/", "").trim());
+
+ JSONObject json = new JSONObject(body);
+ try{
+ resultList = json.get("policyresult");
+ }catch(Exception e){
+ List<String> data = new ArrayList<>();
+ data.add("Elastic Search Server is down");
+ resultList = data;
+ policyLogger.error("Exception Occured while searching for Policy in Elastic Database" +e);
+ }
+
+ response.setCharacterEncoding("UTF-8");
+ response.setContentType("application / json");
+ request.setCharacterEncoding("UTF-8");
+
+ PrintWriter out = response.getWriter();
+ JSONObject j = new JSONObject("{result: " + resultList + "}");
+ out.write(j.toString());
+ return null;
+ }
+