How to use processRequest method of org.cerberus.servlet.integration.NewBuildRev class

Best Cerberus-source code snippet using org.cerberus.servlet.integration.NewBuildRev.processRequest

Source:NewBuildRev.java Github

copy

Full Screen

...63 * @param response servlet response64 * @throws ServletException if a servlet-specific error occurs65 * @throws IOException if an I/O error occurs66 */67 protected void processRequest(HttpServletRequest request, HttpServletResponse response)68 throws ServletException, IOException, JSONException {69 JSONObject jsonResponse = new JSONObject();70 AnswerItem answerItem = new AnswerItem();71 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);72 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));73 answerItem.setResultMessage(msg);74 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);75 response.setContentType("application/json");76 /**77 * Parsing and securing all required parameters.78 */79 String system = policy.sanitize(request.getParameter("system"));80 String country = policy.sanitize(request.getParameter("country"));81 String env = policy.sanitize(request.getParameter("environment"));82 String build = policy.sanitize(request.getParameter("build"));83 String revision = policy.sanitize(request.getParameter("revision"));84 // Init Answer with potencial error from Parsing parameter.85// AnswerItem answer = new AnswerItem(msg);86 String eMailContent;87 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());88 IEmailService emailService = appContext.getBean(IEmailService.class);89 IEmailGenerationService emailGenerationService = appContext.getBean(IEmailGenerationService.class);90 IParameterService parameterService = appContext.getBean(IParameterService.class);91 ICountryEnvParamService countryEnvParamService = appContext.getBean(ICountryEnvParamService.class);92 ICountryEnvParam_logService countryEnvParam_logService = appContext.getBean(ICountryEnvParam_logService.class);93 ILogEventService logEventService = appContext.getBean(LogEventService.class);94 if (request.getParameter("system") == null) {95 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);96 msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM)97 .replace("%OPERATION%", OPERATION)98 .replace("%REASON%", "System name is missing!"));99 answerItem.setResultMessage(msg);100 } else if (request.getParameter("country") == null) {101 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);102 msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM)103 .replace("%OPERATION%", OPERATION)104 .replace("%REASON%", "Country is missing!"));105 answerItem.setResultMessage(msg);106 } else if (request.getParameter("environment") == null) {107 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);108 msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM)109 .replace("%OPERATION%", OPERATION)110 .replace("%REASON%", "Environment is missing!"));111 answerItem.setResultMessage(msg);112 } else if (request.getParameter("build") == null) {113 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);114 msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM)115 .replace("%OPERATION%", OPERATION)116 .replace("%REASON%", "Build is missing!"));117 answerItem.setResultMessage(msg);118 } else if (request.getParameter("revision") == null) {119 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);120 msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM)121 .replace("%OPERATION%", OPERATION)122 .replace("%REASON%", "Revision is missing!"));123 answerItem.setResultMessage(msg);124 } else { // All parameters are OK we can start performing the operation.125 // Getting the contryEnvParam based on the parameters.126 answerItem = countryEnvParamService.readByKey(system, country, env);127 if (!(answerItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerItem.getItem() != null)) {128 /**129 * Object could not be found. We stop here and report the error.130 */131 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);132 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)133 .replace("%OPERATION%", OPERATION)134 .replace("%REASON%", OBJECT_NAME + " ['" + system + "','" + country + "','" + env + "'] does not exist. Cannot activate it!"));135 answerItem.setResultMessage(msg);136 } else {137 /**138 * The service was able to perform the query and confirm the139 * object exist, then we can update it.140 */141 // Email Calculation. Email must be calcuated before we update the Build and revision in order to have the old build revision still available in the mail.142 String OutputMessage = "";143 Email email = null;144 try {145 email = emailGenerationService.generateRevisionChangeEmail(system, country, env, build, revision);146 } catch (Exception ex) {147 LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched.", ex);148 logEventService.createForPrivateCalls("/NewBuildRev", "NEWBUILDREV", "Warning on New Build/Revision environment : ['" + system + "','" + country + "','" + env + "'] " + ex.getMessage(), request);149 OutputMessage = ex.getMessage();150 }151 // We update the object.152 CountryEnvParam cepData = (CountryEnvParam) answerItem.getItem();153 cepData.setBuild(build);154 cepData.setRevision(revision);155 cepData.setActive(true);156 Answer answer = countryEnvParamService.update(cepData);157 if (!(answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()))) {158 /**159 * Object could not be updated. We stop here and report the160 * error.161 */162 answerItem.setResultMessage(answer.getResultMessage());163 } else {164 /**165 * Update was successful.166 */167 // Adding Log entry.168 logEventService.createForPrivateCalls("/NewBuildRev", "UPDATE", "Updated CountryEnvParam : ['" + system + "','" + country + "','" + env + "']", request);169 // Adding CountryEnvParam Log entry.170 countryEnvParam_logService.createLogEntry(system, country, env, build, revision, "New Build Revision.", request.getUserPrincipal().getName());171 /**172 * Email notification.173 */174 try {175 emailService.sendHtmlMail(email);176 } catch (Exception e) {177 LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched.", e);178 logEventService.createForPrivateCalls("/NewBuildRev", "NEWBUILDREV", "Warning on New Build/Revision environment : ['" + system + "','" + country + "','" + env + "'] " + e.getMessage(), request);179 OutputMessage = e.getMessage();180 }181 if (OutputMessage.equals("")) {182 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);183 msg.setDescription(msg.getDescription().replace("%ITEM%", "Environment")184 .replace("%OPERATION%", OPERATION));185 answerItem.setResultMessage(msg);186 } else {187 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);188 msg.setDescription(msg.getDescription().replace("%ITEM%", "Environment")189 .replace("%OPERATION%", OPERATION).concat(" Just one warning : ").concat(OutputMessage));190 answerItem.setResultMessage(msg);191 }192 }193 }194 }195 /**196 * Formating and returning the json result.197 */198 jsonResponse.put("messageType", answerItem.getResultMessage().getMessage().getCodeString());199 jsonResponse.put("message", answerItem.getResultMessage().getDescription());200 response.getWriter().print(jsonResponse);201 response.getWriter().flush();202 }203 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">204 /**205 * Handles the HTTP <code>GET</code> method.206 *207 * @param request servlet request208 * @param response servlet response209 * @throws ServletException if a servlet-specific error occurs210 * @throws IOException if an I/O error occurs211 */212 @Override213 protected void doGet(HttpServletRequest request, HttpServletResponse response)214 throws ServletException, IOException {215 try {216 processRequest(request, response);217 } catch (JSONException ex) {218 LOG.warn(ex);219 }220 }221 /**222 * Handles the HTTP <code>POST</code> method.223 *224 * @param request servlet request225 * @param response servlet response226 * @throws ServletException if a servlet-specific error occurs227 * @throws IOException if an I/O error occurs228 */229 @Override230 protected void doPost(HttpServletRequest request, HttpServletResponse response)231 throws ServletException, IOException {232 try {233 processRequest(request, response);234 } catch (JSONException ex) {235 LOG.warn(ex);236 }237 }238 /**239 * Returns a short description of the servlet.240 *241 * @return a String containing servlet description242 */243 @Override244 public String getServletInfo() {245 return "Short description";246 }// </editor-fold>247}...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.integration.NewBuildRev2import org.cerberus.servlet.integration.NewBuildRevResponse3import org.cerberus.servlet.integration.NewBuildRevRequest4NewBuildRev n = new NewBuildRev()5NewBuildRevRequest r = new NewBuildRevRequest()6r.setApplication("app")7r.setBuild("build")8r.setRevision("rev")9r.setSystem("sys")10r.setCountry("country")11r.setEnvironment("env")12r.setVerbose("true")13NewBuildRevResponse response = n.processRequest(r)14println response.getCode()15println response.getMessage()16println response.getVerboseMessage()17import org.cerberus.servlet.integration.GetRevisionLastBuild18import org.cerberus.servlet.integration.GetRevisionLastBuildResponse19import org.cerberus.servlet.integration.GetRevisionLastBuildRequest20GetRevisionLastBuild n = new GetRevisionLastBuild()21GetRevisionLastBuildRequest r = new GetRevisionLastBuildRequest()22r.setApplication("app")23r.setRevision("rev")24r.setSystem("sys")25r.setCountry("country")26r.setEnvironment("env")27r.setVerbose("true")28GetRevisionLastBuildResponse response = n.processRequest(r)29println response.getCode()30println response.getMessage()31println response.getVerboseMessage()32println response.getBuild()33import org.cerberus.servlet.integration.GetRevisionLastBuild34import org.cerberus.servlet.integration.GetRevisionLastBuildResponse35import org.cerberus.servlet.integration.GetRevisionLastBuildRequest36GetRevisionLastBuild n = new GetRevisionLastBuild()37GetRevisionLastBuildRequest r = new GetRevisionLastBuildRequest()38r.setApplication("app")39r.setRevision("rev")40r.setSystem("sys")41r.setCountry("country")42r.setEnvironment("env")43r.setVerbose("true")44GetRevisionLastBuildResponse response = n.processRequest(r)45println response.getCode()46println response.getMessage()47println response.getVerboseMessage()48println response.getBuild()49import org.cerberus.servlet.integration.GetRevisionLastBuild50import org.c

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 NewBuildRev

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful