Best Cerberus-source code snippet using org.cerberus.servlet.crud.transversaltables.CreateEventHook.processRequest
Source: CreateEventHook.java
...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";...
Check out the latest blogs from LambdaTest on this topic:
The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.
Hey LambdaTesters! We’ve got something special for you this week. ????
API (Application Programming Interface) is a set of definitions and protocols for building and integrating applications. It’s occasionally referred to as a contract between an information provider and an information user establishing the content required from the consumer and the content needed by the producer.
In general, software testers have a challenging job. Software testing is frequently the final significant activity undertaken prior to actually delivering a product. Since the terms “software” and “late” are nearly synonymous, it is the testers that frequently catch the ire of the whole business as they try to test the software at the end. It is the testers who are under pressure to finish faster and deem the product “release candidate” before they have had enough opportunity to be comfortable. To make matters worse, if bugs are discovered in the product after it has been released, everyone looks to the testers and says, “Why didn’t you spot those bugs?” The testers did not cause the bugs, but they must bear some of the guilt for the bugs that were disclosed.
In some sense, testing can be more difficult than coding, as validating the efficiency of the test cases (i.e., the ‘goodness’ of your tests) can be much harder than validating code correctness. In practice, the tests are just executed without any validation beyond the pass/fail verdict. On the contrary, the code is (hopefully) always validated by testing. By designing and executing the test cases the result is that some tests have passed, and some others have failed. Testers do not know much about how many bugs remain in the code, nor about their bug-revealing efficiency.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!