Best Cerberus-source code snippet using org.cerberus.servlet.crud.countryenvironment.CreateDeployType.processRequest
Source:CreateDeployType.java
...61 * @throws IOException if an I/O error occurs62 * @throws org.cerberus.exception.CerberusException63 * @throws org.json.JSONException64 */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 response.setContentType("application/json");74 // Calling Servlet Transversal Util.75 ServletUtil.servletStart(request);76 77 /**78 * Parsing and securing all required parameters.79 */80 String deploytype = policy.sanitize(request.getParameter("deploytype"));81 String description = policy.sanitize(request.getParameter("description"));82 /**83 * Checking all constrains before calling the services.84 */85 if (StringUtil.isNullOrEmpty(deploytype)) {86 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);87 msg.setDescription(msg.getDescription().replace("%ITEM%", "Deploy Type")88 .replace("%OPERATION%", "Create")89 .replace("%REASON%", "Deploy Type name is missing!"));90 ans.setResultMessage(msg);91 } else {92 /**93 * All data seems cleans so we can call the services.94 */95 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());96 IDeployTypeService deployTypeService = appContext.getBean(IDeployTypeService.class);97 IFactoryDeployType factoryDeployType = appContext.getBean(IFactoryDeployType.class);98 DeployType deployTypeData = factoryDeployType.create(deploytype, description);99 ans = deployTypeService.create(deployTypeData);100 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {101 /**102 * Object created. Adding Log entry.103 */104 ILogEventService logEventService = appContext.getBean(LogEventService.class);105 logEventService.createForPrivateCalls("/CreateDeployType", "CREATE", "Create DeployType : ['" + deploytype + "']", request);106 }107 }108 /**109 * Formating and returning the json result.110 */111 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());112 jsonResponse.put("message", ans.getResultMessage().getDescription());113 response.getWriter().print(jsonResponse);114 response.getWriter().flush();115 }116 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">117 /**118 * Handles the HTTP <code>GET</code> method.119 *120 * @param request servlet request121 * @param response servlet response122 * @throws ServletException if a servlet-specific error occurs123 * @throws IOException if an I/O error occurs124 */125 @Override126 protected void doGet(HttpServletRequest request, HttpServletResponse response)127 throws ServletException, IOException {128 try {129 processRequest(request, response);130 } catch (CerberusException ex) {131 LOG.warn(ex);132 } catch (JSONException ex) {133 LOG.warn(ex);134 }135 }136 /**137 * Handles the HTTP <code>POST</code> method.138 *139 * @param request servlet request140 * @param response servlet response141 * @throws ServletException if a servlet-specific error occurs142 * @throws IOException if an I/O error occurs143 */144 @Override145 protected void doPost(HttpServletRequest request, HttpServletResponse response)146 throws ServletException, IOException {147 try {148 processRequest(request, response);149 } catch (CerberusException ex) {150 LOG.warn(ex);151 } catch (JSONException ex) {152 LOG.warn(ex);153 }154 }155 /**156 * Returns a short description of the servlet.157 *158 * @return a String containing servlet description159 */160 @Override161 public String getServletInfo() {162 return "Short description";...
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!!