Best Cerberus-source code snippet using org.cerberus.servlet.crud.buildrevisionchange.CreateBuildRevisionInvariant.processRequest
...62 * @throws IOException if an I/O error occurs63 * @throws org.cerberus.exception.CerberusException64 * @throws org.json.JSONException65 */66 protected void processRequest(HttpServletRequest request, HttpServletResponse response)67 throws ServletException, IOException, CerberusException, JSONException {68 JSONObject jsonResponse = new JSONObject();69 Answer ans = new Answer();70 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);71 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));72 ans.setResultMessage(msg);73 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);74 String charset = request.getCharacterEncoding();75 response.setContentType("application/json");76 // Calling Servlet Transversal Util.77 ServletUtil.servletStart(request);78 79 /**80 * Parsing and securing all required parameters.81 */82 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them83 Integer seq = -1;84 boolean seq_error = false;85 try {86 if (request.getParameter("seq") != null && !request.getParameter("seq").equals("")) {87 seq = Integer.valueOf(policy.sanitize(request.getParameter("seq")));88 }89 } catch (Exception ex) {90 seq_error = true;91 }92 Integer level = -1;93 boolean level_error = false;94 try {95 if (request.getParameter("level") != null && !request.getParameter("level").equals("")) {96 level = Integer.valueOf(policy.sanitize(request.getParameter("level")));97 }98 } catch (Exception ex) {99 level_error = true;100 }101 // Parameter that needs to be secured --> We SECURE+DECODE them102 String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);103 String versionName = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("versionname"), "", charset);104 // Parameter that we cannot secure as we need the html --> We DECODE them105 /**106 * Checking all constrains before calling the services.107 */108 if (StringUtil.isNullOrEmpty(system)) {109 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);110 msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant")111 .replace("%OPERATION%", "Create")112 .replace("%REASON%", "System name is missing!"));113 ans.setResultMessage(msg);114 } else if (level_error) {115 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);116 msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant")117 .replace("%OPERATION%", "Create")118 .replace("%REASON%", "Could not manage to convert level to an integer value!"));119 ans.setResultMessage(msg);120 } else if (seq_error) {121 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);122 msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant")123 .replace("%OPERATION%", "Create")124 .replace("%REASON%", "Could not manage to convert sequence to an integer value!"));125 ans.setResultMessage(msg);126 } else {127 /**128 * All data seems cleans so we can call the services.129 */130 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());131 IBuildRevisionInvariantService buildRevisionInvariantService = appContext.getBean(IBuildRevisionInvariantService.class);132 IFactoryBuildRevisionInvariant factoryBuildRevisionInvariant = appContext.getBean(IFactoryBuildRevisionInvariant.class);133 BuildRevisionInvariant buildRevisionInvariantData = factoryBuildRevisionInvariant.create(system, level, seq, versionName);134 ans = buildRevisionInvariantService.create(buildRevisionInvariantData);135 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {136 /**137 * Object created. Adding Log entry.138 */139 ILogEventService logEventService = appContext.getBean(LogEventService.class);140 logEventService.createForPrivateCalls("/CreateBuildRevisionInvariant", "CREATE", "Create BuildRevisionInvariant : ['" + system + "'|'" + level + "'|'" + seq + "']", request);141 }142 }143 /**144 * Formating and returning the json result.145 */146 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());147 jsonResponse.put("message", ans.getResultMessage().getDescription());148 response.getWriter().print(jsonResponse);149 response.getWriter().flush();150 }151 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">152 /**153 * Handles the HTTP <code>GET</code> method.154 *155 * @param request servlet request156 * @param response servlet response157 * @throws ServletException if a servlet-specific error occurs158 * @throws IOException if an I/O error occurs159 */160 @Override161 protected void doGet(HttpServletRequest request, HttpServletResponse response)162 throws ServletException, IOException {163 try {164 processRequest(request, response);165 } catch (CerberusException ex) {166 LOG.warn(ex);167 } catch (JSONException ex) {168 LOG.warn(ex);169 }170 }171 /**172 * Handles the HTTP <code>POST</code> method.173 *174 * @param request servlet request175 * @param response servlet response176 * @throws ServletException if a servlet-specific error occurs177 * @throws IOException if an I/O error occurs178 */179 @Override180 protected void doPost(HttpServletRequest request, HttpServletResponse response)181 throws ServletException, IOException {182 try {183 processRequest(request, response);184 } catch (CerberusException ex) {185 LOG.warn(ex);186 } catch (JSONException ex) {187 LOG.warn(ex);188 }189 }190 /**191 * Returns a short description of the servlet.192 *193 * @return a String containing servlet description194 */195 @Override196 public String getServletInfo() {197 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!!