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

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

Source:DisableEnvironment.java Github

copy

Full Screen

...60 * @param response servlet response61 * @throws ServletException if a servlet-specific error occurs62 * @throws IOException if an I/O error occurs63 */64 protected void processRequest(HttpServletRequest request, HttpServletResponse response)65 throws ServletException, IOException, JSONException {66 JSONObject jsonResponse = new JSONObject();67 AnswerItem answerItem = new AnswerItem();68 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);69 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));70 answerItem.setResultMessage(msg);71 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);72 response.setContentType("application/json");73 /**74 * Parsing and securing all required parameters.75 */76 String system = policy.sanitize(request.getParameter("system"));77 String country = policy.sanitize(request.getParameter("country"));78 String env = policy.sanitize(request.getParameter("environment"));79 // Init Answer with potencial error from Parsing parameter.80// AnswerItem answer = new AnswerItem(msg);81 String eMailContent = "";82 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());83 IEmailService emailService = appContext.getBean(IEmailService.class);84 ICountryEnvParamService countryEnvParamService = appContext.getBean(ICountryEnvParamService.class);85 ICountryEnvParam_logService countryEnvParam_logService = appContext.getBean(ICountryEnvParam_logService.class);86 ILogEventService logEventService = appContext.getBean(LogEventService.class);87 if (request.getParameter("system") == null) {88 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);89 msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM)90 .replace("%OPERATION%", OPERATION)91 .replace("%REASON%", "System name is missing!"));92 answerItem.setResultMessage(msg);93 } else if (request.getParameter("country") == null) {94 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);95 msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM)96 .replace("%OPERATION%", OPERATION)97 .replace("%REASON%", "Country is missing!"));98 answerItem.setResultMessage(msg);99 } else if (request.getParameter("environment") == null) {100 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);101 msg.setDescription(msg.getDescription().replace("%ITEM%", ITEM)102 .replace("%OPERATION%", OPERATION)103 .replace("%REASON%", "Environment is missing!"));104 answerItem.setResultMessage(msg);105 } else { // All parameters are OK we can start performing the operation.106 // Getting the contryEnvParam based on the parameters.107 answerItem = countryEnvParamService.readByKey(system, country, env);108 if (!(answerItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerItem.getItem() != null)) {109 /**110 * Object could not be found. We stop here and report the error.111 */112 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);113 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)114 .replace("%OPERATION%", OPERATION)115 .replace("%REASON%", OBJECT_NAME + " ['" + system + "','" + country + "','" + env + "'] does not exist. Cannot disable it!"));116 answerItem.setResultMessage(msg);117 } else {118 /**119 * The service was able to perform the query and confirm the120 * object exist, then we can update it.121 */122 CountryEnvParam cepData = (CountryEnvParam) answerItem.getItem();123 cepData.setActive(false);124 Answer answer = countryEnvParamService.update(cepData);125 if (!(answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()))) {126 /**127 * Object could not be updated. We stop here and report the128 * error.129 */130 answerItem.setResultMessage(answer.getResultMessage());131 } else {132 /**133 * Update was successful.134 */135 // Adding Log entry.136 logEventService.createForPrivateCalls("/DisableEnvironment", "UPDATE", "Updated CountryEnvParam : ['" + system + "','" + country + "','" + env + "']", request);137 // Adding CountryEnvParam Log entry.138 countryEnvParam_logService.createLogEntry(system, country, env, "", "", "Disabled.", request.getUserPrincipal().getName());139 /**140 * Email notification.141 */142 String OutputMessage = "";143 MessageEvent me = emailService.generateAndSendDisableEnvEmail(system, country, env);144 if (!"OK".equals(me.getMessage().getCodeString())) {145 LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched." + me.getMessage().getDescription());146 logEventService.createForPrivateCalls("/DisableEnvironment", "DISABLE", "Warning on Disable environment : ['" + system + "','" + country + "','" + env + "'] " + me.getMessage().getDescription(), request);147 OutputMessage = me.getMessage().getDescription();148 }149 if (OutputMessage.equals("")) {150 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);151 msg.setDescription(msg.getDescription().replace("%ITEM%", "Environment")152 .replace("%OPERATION%", OPERATION));153 answerItem.setResultMessage(msg);154 } else {155 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);156 msg.setDescription(msg.getDescription().replace("%ITEM%", "Environment")157 .replace("%OPERATION%", OPERATION).concat(" Just one warning : ").concat(OutputMessage));158 answerItem.setResultMessage(msg);159 }160 }161 }162 }163 /**164 * Formating and returning the json result.165 */166 jsonResponse.put(167 "messageType", answerItem.getResultMessage().getMessage().getCodeString());168 jsonResponse.put(169 "message", answerItem.getResultMessage().getDescription());170 response.getWriter()171 .print(jsonResponse);172 response.getWriter()173 .flush();174 }175 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">176 /**177 * Handles the HTTP <code>GET</code> method.178 *179 * @param request servlet request180 * @param response servlet response181 * @throws ServletException if a servlet-specific error occurs182 * @throws IOException if an I/O error occurs183 */184 @Override185 protected void doGet(HttpServletRequest request, HttpServletResponse response)186 throws ServletException, IOException {187 try {188 processRequest(request, response);189 } catch (JSONException ex) {190 LOG.warn(ex);191 }192 }193 /**194 * Handles the HTTP <code>POST</code> method.195 *196 * @param request servlet request197 * @param response servlet response198 * @throws ServletException if a servlet-specific error occurs199 * @throws IOException if an I/O error occurs200 */201 @Override202 protected void doPost(HttpServletRequest request, HttpServletResponse response)203 throws ServletException, IOException {204 try {205 processRequest(request, response);206 } catch (JSONException ex) {207 LOG.warn(ex);208 }209 }210 /**211 * Returns a short description of the servlet.212 *213 * @return a String containing servlet description214 */215 @Override216 public String getServletInfo() {217 return "Short description";218 }// </editor-fold>219}...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var options = {3 'headers': {4 },5 body: JSON.stringify({"env":"1"})6};7request(options, function (error, response) {8 if (error) throw new Error(error);9 console.log(response.body);10});11{"message":"Environment disabled","httpCode":200}

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 DisableEnvironment

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful