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

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

Source:UpdateSqlLibrary.java Github

copy

Full Screen

...58 * @param response servlet response59 * @throws ServletException if a servlet-specific error occurs60 * @throws IOException if an I/O error occurs61 */62 protected void processRequest(HttpServletRequest request, HttpServletResponse response)63 throws ServletException, IOException, CerberusException, JSONException {64 JSONObject jsonResponse = new JSONObject();65 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());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 response.setContentType("text/html;charset=UTF-8");71 PrintWriter out = response.getWriter();72 String charset = request.getCharacterEncoding() == null ? "UTF-8" : request.getCharacterEncoding();73 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them74 // Parameter that needs to be secured --> We SECURE+DECODE them75 String name = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("name"), null, charset);76 String type = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("type"), null, charset);77 String database = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("database"), null, charset);78 String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), null, charset);79 // Parameter that we cannot secure as we need the html --> We DECODE them80 String script = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("script"), null, charset);81 82 // Prepare the final answer.83 MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);84 Answer finalAnswer = new Answer(msg1);85 /**86 * Checking all constrains before calling the services.87 */88 if (StringUtil.isNullOrEmpty(name)) {89 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);90 msg.setDescription(msg.getDescription().replace("%ITEM%", "SqlLibrary")91 .replace("%OPERATION%", "Update")92 .replace("%REASON%", "SqlLibrary ID (name) is missing."));93 finalAnswer.setResultMessage(msg);94 } else {95 /**96 * All data seems cleans so we can call the services.97 */98 ISqlLibraryService sqlLibraryService = appContext.getBean(ISqlLibraryService.class);99 AnswerItem resp = sqlLibraryService.readByKey(name);100 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {101 /**102 * Object could not be found. We stop here and report the error.103 */104 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, resp);105 } else {106 /**107 * The service was able to perform the query and confirm the108 * object exist, then we can update it.109 */110 SqlLibrary sqlLib = (SqlLibrary) resp.getItem();111 sqlLib.setType(type);112 sqlLib.setDescription(description);113 sqlLib.setDatabase(database);114 sqlLib.setScript(script);115 ans = sqlLibraryService.update(sqlLib);116 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, ans);117 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {118 /**119 * Update was successful. Adding Log entry.120 */121 ILogEventService logEventService = appContext.getBean(LogEventService.class);122 logEventService.createForPrivateCalls("/UpdateSqlLibrary", "UPDATE", "Updated SqlLibrary : ['" + name + "']", request);123 }124 }125 }126 /**127 * Formating and returning the json result.128 */129 jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());130 jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());131 response.getWriter().print(jsonResponse);132 response.getWriter().flush();133 }134 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">135 /**136 * Handles the HTTP <code>GET</code> method.137 *138 * @param request servlet request139 * @param response servlet response140 * @throws ServletException if a servlet-specific error occurs141 * @throws IOException if an I/O error occurs142 */143 @Override144 protected void doGet(HttpServletRequest request, HttpServletResponse response)145 throws ServletException, IOException {146 try {147 processRequest(request, response);148 } catch (CerberusException ex) {149 LOG.warn(ex);150 } catch (JSONException ex) {151 LOG.warn(ex);152 }153 }154 /**155 * Handles the HTTP <code>POST</code> method.156 *157 * @param request servlet request158 * @param response servlet response159 * @throws ServletException if a servlet-specific error occurs160 * @throws IOException if an I/O error occurs161 */162 @Override163 protected void doPost(HttpServletRequest request, HttpServletResponse response)164 throws ServletException, IOException {165 try {166 String t = request.getParameter("value");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 UpdateSqlLibrary

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful