How to use processRequest method of org.cerberus.servlet.crud.transversaltables.CreateEventHook class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.transversaltables.CreateEventHook.processRequest

Source:CreateEventHook.java Github

copy

Full Screen

...61 * @param response servlet response62 * @throws ServletException if a servlet-specific error occurs63 * @throws IOException if an I/O error occurs64 */65 protected void processRequest(HttpServletRequest request, HttpServletResponse response)66 throws ServletException, IOException, CerberusException, JSONException {67 JSONObject jsonResponse = new JSONObject();68 Answer ans = new Answer();69 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);70 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));71 ans.setResultMessage(msg);72 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);73 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());74 String charset = request.getCharacterEncoding() == null ? "UTF-8" : request.getCharacterEncoding();75 IEventHookService eventHookService = appContext.getBean(IEventHookService.class);76 IFactoryEventHook eventHookFactory = appContext.getBean(IFactoryEventHook.class);77 response.setContentType("application/json");78 // Calling Servlet Transversal Util.79 ServletUtil.servletStart(request);80 /**81 * Parsing and securing all required parameters.82 */83 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them84 Integer id = Integer.valueOf(request.getParameter("id"));85 boolean isActive = (("true".equals(request.getParameter("isActive"))));86 String objectKey1 = ParameterParserUtil.parseStringParamAndDecode(policy.sanitize(request.getParameter("objectKey1")), "", charset);87 String objectKey2 = ParameterParserUtil.parseStringParamAndDecode(policy.sanitize(request.getParameter("objectKey2")), "", charset);88 // Parameter that needs to be secured --> We SECURE+DECODE them89 String eventReference = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("eventReference"), "", charset);90 String description = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("description"), "", charset);91 String hookChannel = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("hookChannel"), "", charset);92 String hookConnector = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("hookConnector"), "", charset);93 String hookRecipient = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("hookRecipient"), "", charset);94 String usr = request.getUserPrincipal().getName();95 /**96 * Checking all constrains before calling the services.97 */98 /**99 * The service was able to perform the query and confirm the object100 * exist, then we can delete it.101 */102 Timestamp updateDate = new Timestamp(new Date().getTime());103 EventHook eh = eventHookFactory.create(id, eventReference, objectKey1, objectKey2, isActive, hookConnector, hookRecipient, hookChannel, description, usr, updateDate, usr, updateDate);104 ans = eventHookService.create(eh);105 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {106 /**107 * Delete was successful. Adding Log entry.108 */109 ILogEventService logEventService = appContext.getBean(LogEventService.class);110 logEventService.createForPrivateCalls("/CreateEventHook", "CREATE", "Create EventHook : ['" + id + "']", request);111 }112 /**113 * Formatting and returning the json result.114 */115 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());116 jsonResponse.put("message", ans.getResultMessage().getDescription());117 response.getWriter().print(jsonResponse);118 response.getWriter().flush();119 }120 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">121 /**122 * Handles the HTTP <code>GET</code> method.123 *124 * @param request servlet request125 * @param response servlet response126 * @throws ServletException if a servlet-specific error occurs127 * @throws IOException if an I/O error occurs128 */129 @Override130 protected void doGet(HttpServletRequest request, HttpServletResponse response)131 throws ServletException, IOException {132 try {133 processRequest(request, response);134 } catch (CerberusException ex) {135 LOG.warn(ex);136 } catch (JSONException ex) {137 LOG.warn(ex);138 }139 }140 /**141 * Handles the HTTP <code>POST</code> method.142 *143 * @param request servlet request144 * @param response servlet response145 * @throws ServletException if a servlet-specific error occurs146 * @throws IOException if an I/O error occurs147 */148 @Override149 protected void doPost(HttpServletRequest request, HttpServletResponse response)150 throws ServletException, IOException {151 try {152 processRequest(request, response);153 } catch (CerberusException ex) {154 LOG.warn(ex);155 } catch (JSONException ex) {156 LOG.warn(ex);157 }158 }159 /**160 * Returns a short description of the servlet.161 *162 * @return a String containing servlet description163 */164 @Override165 public String getServletInfo() {166 return "Short description";...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in CreateEventHook

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful