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

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

Source:DeleteApplicationObject.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 application = policy.sanitize(request.getParameter("application"));79 String object = policy.sanitize(request.getParameter("object"));80 /**81 * Checking all constrains before calling the services.82 */83 if (StringUtil.isNullOrEmpty(application)) {84 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);85 msg.setDescription(msg.getDescription().replace("%ITEM%", "ApplicationObject")86 .replace("%OPERATION%", "Delete")87 .replace("%REASON%", "Application name is missing!"));88 ans.setResultMessage(msg);89 } else if (StringUtil.isNullOrEmpty(object)) {90 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);91 msg.setDescription(msg.getDescription().replace("%ITEM%", "ApplicationObject")92 .replace("%OPERATION%", "Delete")93 .replace("%REASON%", "Object name is missing!"));94 ans.setResultMessage(msg);95 } else {96 /**97 * All data seems cleans so we can call the services.98 */99 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());100 IApplicationObjectService applicationObjectService = appContext.getBean(IApplicationObjectService.class);101 AnswerItem resp = applicationObjectService.readByKey(application, object);102 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem()!=null)) {103 /**104 * Object could not be found. We stop here and report the error.105 */106 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);107 msg.setDescription(msg.getDescription().replace("%ITEM%", "ApplicationObject")108 .replace("%OPERATION%", "Delete")109 .replace("%REASON%", "Application Object does not exist."));110 ans.setResultMessage(msg);111 } else {112 /**113 * The service was able to perform the query and confirm the114 * object exist, then we can delete it.115 */116 ApplicationObject applicationData = (ApplicationObject) resp.getItem();117 ans = applicationObjectService.delete(applicationData);118 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {119 /**120 * Delete was successful. Adding Log entry.121 */122 ILogEventService logEventService = appContext.getBean(LogEventService.class);123 logEventService.createForPrivateCalls("/DeleteApplicationObject", "DELETE", "Delete Application Object: ['" + application + "'|'" + object + "']", request);124 }125 }126 }127 /**128 * Formating and returning the json result.129 */130 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());131 jsonResponse.put("message", ans.getResultMessage().getDescription());132 response.getWriter().print(jsonResponse.toString());133 response.getWriter().flush();134 }135// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">136 /**137 * Handles the HTTP <code>GET</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 doGet(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 * Handles the HTTP <code>POST</code> method.157 *158 * @param request servlet request159 * @param response servlet response160 * @throws ServletException if a servlet-specific error occurs161 * @throws IOException if an I/O error occurs162 */163 @Override164 protected void doPost(HttpServletRequest request, HttpServletResponse response)165 throws ServletException, IOException {166 try {167 processRequest(request, response);168 } catch (CerberusException ex) {169 LOG.warn(ex);170 } catch (JSONException ex) {171 LOG.warn(ex);172 }173 }174 /**175 * Returns a short description of the servlet.176 *177 * @return a String containing servlet description178 */179 @Override180 public String getServletInfo() {181 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 DeleteApplicationObject

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful