- public void importBlackListFile(HttpServletRequest request, HttpServletResponse response) throws Exception {
- List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
- List<String> errorLogs = new ArrayList<>();
- Gson mapper = new Gson();
- errorLogs.add("error");
- Map<String, Object> model = new HashMap<>();
- if (items.isEmpty()) {
- errorLogs.add("The File doesn't have any content and it is invalid.");
- model.put(BLACKLISTENTRIESDATA, errorLogs);
- } else {
- readItems(items, errorLogs, model);
+ public void importBlackListFile(HttpServletRequest request, HttpServletResponse response) {
+ try {
+ List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
+ List<String> errorLogs = new ArrayList<>();
+ Gson mapper = new Gson();
+ errorLogs.add("error");
+ Map<String, Object> model = new HashMap<>();
+ if (items.isEmpty()) {
+ errorLogs.add("The File doesn't have any content and it is invalid.");
+ model.put(BLACKLISTENTRIESDATA, errorLogs);
+ } else {
+ readItems(items, errorLogs, model);
+ }
+ response.getWriter().write(new JSONObject(new JsonMessage(mapper.toJson(model))).toString());
+ } catch (FileUploadException | IOException e) {
+ policyLogger.error("Exception Occured while importing the BlackListEntry", e);