How to use processRequest method of org.cerberus.servlet.crud.buildrevisionchange.CreateBuildRevisionInvariant class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.buildrevisionchange.CreateBuildRevisionInvariant.processRequest

Source:CreateBuildRevisionInvariant.java Github

copy

Full Screen

...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";...

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 CreateBuildRevisionInvariant

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful