Best Cerberus-source code snippet using org.cerberus.servlet.zzpublic.NewEnvironmentEventV000.processRequest
Source:NewEnvironmentEventV000.java
...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 {64 PrintWriter out = response.getWriter();65 String charset = request.getCharacterEncoding();66 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());67 /**68 * Adding Log entry.69 */70 ILogEventService logEventService = appContext.getBean(ILogEventService.class);71 logEventService.createForPublicCalls("/NewEnvironmentEventV000", "CALL", "NewEnvironmentEventV000 called : " + request.getRequestURL(), request);72 ICountryEnvParamService countryEnvParamService = appContext.getBean(ICountryEnvParamService.class);73 IInvariantService invariantService = appContext.getBean(IInvariantService.class);74 IBatchInvariantService batchInvariantService = appContext.getBean(IBatchInvariantService.class);75 IBuildRevisionBatchService buildRevisionBatchService = appContext.getBean(IBuildRevisionBatchService.class);76 IEmailService emailService = appContext.getBean(IEmailService.class);77 // Parsing all parameters.78 String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);79 String country = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("country"), "", charset);80 String environment = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("environment"), "", charset);81 String event = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("event"), "", charset);82 String helpMessage = "\nThis servlet is used to inform Cerberus about an event that occured on a given environment. For example when a treatment has been executed.\n\nParameter list :\n"83 + "- system [mandatory] : the system where the Build Revision has been deployed. [" + system + "]\n"84 + "- country [mandatory] : the country where the Build Revision has been deployed. You can use ALL if you want to perform the action for all countries that exist for the given system and environement. [" + country + "]\n"85 + "- environment [mandatory] : the environment where the Build Revision has been deployed. [" + environment + "]\n"86 + "- event [mandatory] : the event that should be recorded.. [" + event + "]\n";87 boolean error = false;88 // Checking the parameter validity. If application has been entered, does it exist ?89 if (system.equalsIgnoreCase("")) {90 out.println("Error - Parameter system is mandatory.");91 error = true;92 }93 if (!system.equalsIgnoreCase("") && !invariantService.isInvariantExist("SYSTEM", system)) {94 out.println("Error - System does not exist : " + system);95 error = true;96 }97 if (environment.equalsIgnoreCase("")) {98 out.println("Error - Parameter environment is mandatory.");99 error = true;100 }101 if (!environment.equalsIgnoreCase("") && !invariantService.isInvariantExist("ENVIRONMENT", environment)) {102 out.println("Error - Environment does not exist : " + environment);103 error = true;104 }105 if (country.equalsIgnoreCase("")) {106 out.println("Error - Parameter country is mandatory.");107 error = true;108 } else if (!country.equalsIgnoreCase(PARAMETERALL)) {109 if (!invariantService.isInvariantExist("COUNTRY", country)) {110 out.println("Error - Country does not exist : " + country);111 error = true;112 }113 if (!error) {114 if (!countryEnvParamService.exist(system, country, environment)) {115 out.println("Error - System/Country/Environment does not exist : " + system + "/" + country + "/" + environment);116 error = true;117 }118 }119 }120 if (event.equalsIgnoreCase("")) {121 out.println("Error - Parameter event is mandatory.");122 error = true;123 }124 if (!event.equalsIgnoreCase("") && !batchInvariantService.exist(event)) {125 out.println("Error - Event does not exist : " + event);126 error = true;127 }128 // Starting the database update only when no blocking error has been detected.129 if (error == false) {130 /**131 * Getting the list of objects to treat.132 */133 MessageEvent msg = new MessageEvent(MessageEventEnum.GENERIC_OK);134 Answer finalAnswer = new Answer(msg);135 AnswerList answerList = new AnswerList();136 if (country.equalsIgnoreCase(PARAMETERALL)) {137 country = null;138 }139 answerList = countryEnvParamService.readByVarious(system, country, environment, null, null, "Y");140 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) answerList);141 for (CountryEnvParam cepData : (List<CountryEnvParam>) answerList.getDataList()) {142 /**143 * For each object, we can update it.144 */145 // Adding CountryEnvParam Log entry.146 buildRevisionBatchService.create(cepData.getSystem(), cepData.getCountry(), cepData.getEnvironment(), cepData.getBuild(), cepData.getRevision(), event);147 /**148 * Email notification.149 */150 String OutputMessage = "";151 MessageEvent me = emailService.generateAndSendNewChainEmail(cepData.getSystem(), cepData.getCountry(), cepData.getEnvironment(), event);152 if (!"OK".equals(me.getMessage().getCodeString())) {153 LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched." + me.getMessage().getDescription());154 logEventService.createForPrivateCalls("/NewEnvironmentEventV000", "NEW", "Warning on New environment event : ['" + cepData.getSystem() + "','" + cepData.getCountry() + "','" + cepData.getEnvironment() + "'] " + me.getMessage().getDescription(), request);155 OutputMessage = me.getMessage().getDescription();156 }157 if (OutputMessage.equals("")) {158 msg = new MessageEvent(MessageEventEnum.GENERIC_OK);159 Answer answerSMTP = new AnswerList(msg);160 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerSMTP);161 } else {162 msg = new MessageEvent(MessageEventEnum.GENERIC_WARNING);163 msg.setDescription(msg.getDescription().replace("%REASON%", OutputMessage + " when sending email for " + cepData.getSystem() + "/" + cepData.getCountry() + "/" + cepData.getEnvironment()));164 Answer answerSMTP = new AnswerList(msg);165 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerSMTP);166 }167 }168 /**169 * Formating and returning the result.170 */171 out.println(finalAnswer.getResultMessage().getMessage().getCodeString() + " - " + finalAnswer.getResultMessage().getDescription());172 } else {173 // In case of errors, we display the help message.174 out.println(helpMessage);175 }176 }177 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">178 /**179 * Handles the HTTP <code>GET</code> method.180 *181 * @param request servlet request182 * @param response servlet response183 * @throws ServletException if a servlet-specific error occurs184 * @throws IOException if an I/O error occurs185 */186 @Override187 protected void doGet(HttpServletRequest request, HttpServletResponse response)188 throws ServletException, IOException {189 processRequest(request, response);190 }191 /**192 * Handles the HTTP <code>POST</code> method.193 *194 * @param request servlet request195 * @param response servlet response196 * @throws ServletException if a servlet-specific error occurs197 * @throws IOException if an I/O error occurs198 */199 @Override200 protected void doPost(HttpServletRequest request, HttpServletResponse response)201 throws ServletException, IOException {202 processRequest(request, response);203 }204 /**205 * Returns a short description of the servlet.206 *207 * @return a String containing servlet description208 */209 @Override210 public String getServletInfo() {211 return "Short description";212 }// </editor-fold>213}...
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!!