How to use processRequest method of org.cerberus.servlet.crud.countryenvironment.UpdateDeployType class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.countryenvironment.UpdateDeployType.processRequest

Source:UpdateDeployType.java Github

copy

Full Screen

...59 * @param response servlet response60 * @throws ServletException if a servlet-specific error occurs61 * @throws IOException if an I/O error occurs62 */63 protected void processRequest(HttpServletRequest request, HttpServletResponse response)64 throws ServletException, IOException, CerberusException, JSONException {65 JSONObject jsonResponse = new JSONObject();66 Answer ans = new Answer();67 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);68 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));69 ans.setResultMessage(msg);70 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);71 response.setContentType("application/json");72 // Calling Servlet Transversal Util.73 ServletUtil.servletStart(request);74 75 /**76 * Parsing and securing all required parameters.77 */78 String deployType = policy.sanitize(request.getParameter("deploytype"));79 String description = policy.sanitize(request.getParameter("description"));80 /**81 * Checking all constrains before calling the services.82 */83 if (StringUtil.isNullOrEmpty(deployType)) {84 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);85 msg.setDescription(msg.getDescription().replace("%ITEM%", "Deploy Type")86 .replace("%OPERATION%", "Update")87 .replace("%REASON%", "Deploy Type (deploytype) is missing"));88 ans.setResultMessage(msg);89 } else {90 /**91 * All data seems cleans so we can call the services.92 */93 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());94 IDeployTypeService deployTypeService = appContext.getBean(IDeployTypeService.class);95 AnswerItem resp = deployTypeService.readByKey(deployType);96 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem()!=null)) {97 /**98 * Object could not be found. We stop here and report the error.99 */100 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);101 msg.setDescription(msg.getDescription().replace("%ITEM%", "Deploy Type")102 .replace("%OPERATION%", "Update")103 .replace("%REASON%", "Deploy Type does not exist."));104 ans.setResultMessage(msg);105 } else {106 /**107 * The service was able to perform the query and confirm the108 * object exist, then we can update it.109 */110 DeployType deployTypeData = (DeployType) resp.getItem();111 deployTypeData.setDescription(description);112 ans = deployTypeService.update(deployTypeData);113 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {114 /**115 * Update was successful. Adding Log entry.116 */117 ILogEventService logEventService = appContext.getBean(LogEventService.class);118 logEventService.createForPrivateCalls("/UpdateDeployType", "UPDATE", "Updated Deploy Type : ['" + deployType + "']", request);119 }120 }121 }122 /**123 * Formating and returning the json result.124 */125 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());126 jsonResponse.put("message", ans.getResultMessage().getDescription());127 response.getWriter().print(jsonResponse);128 response.getWriter().flush();129 }130 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">131 /**132 * Handles the HTTP <code>GET</code> method.133 *134 * @param request servlet request135 * @param response servlet response136 * @throws ServletException if a servlet-specific error occurs137 * @throws IOException if an I/O error occurs138 */139 @Override140 protected void doGet(HttpServletRequest request, HttpServletResponse response)141 throws ServletException, IOException {142 try {143 processRequest(request, response);144 } catch (CerberusException ex) {145 LOG.warn(ex);146 } catch (JSONException ex) {147 LOG.warn(ex);148 }149 }150 /**151 * Handles the HTTP <code>POST</code> method.152 *153 * @param request servlet request154 * @param response servlet response155 * @throws ServletException if a servlet-specific error occurs156 * @throws IOException if an I/O error occurs157 */158 @Override159 protected void doPost(HttpServletRequest request, HttpServletResponse response)160 throws ServletException, IOException {161 try {162 processRequest(request, response);163 } catch (CerberusException ex) {164 LOG.warn(ex);165 } catch (JSONException ex) {166 LOG.warn(ex);167 }168 }169 /**170 * Returns a short description of the servlet.171 *172 * @return a String containing servlet description173 */174 @Override175 public String getServletInfo() {176 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 UpdateDeployType

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful