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

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

Source:CreateCountryEnvParam.java Github

copy

Full Screen

...62 * @throws IOException if an I/O error occurs63 * @throws org.cerberus.exception.CerberusException64 * @throws org.json.JSONException65 */66 protected void processRequest(HttpServletRequest request, HttpServletResponse response)67 throws ServletException, IOException, CerberusException, JSONException {68 JSONObject jsonResponse = new JSONObject();69 Answer ans = new Answer();70 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);71 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));72 ans.setResultMessage(msg);73 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);74 String charset = request.getCharacterEncoding();75 response.setContentType("application/json");76 // Calling Servlet Transversal Util.77 ServletUtil.servletStart(request);78 /**79 * Parsing and securing all required parameters.80 */81 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them82 String system = policy.sanitize(request.getParameter("system"));83 String country = policy.sanitize(request.getParameter("country"));84 String environment = policy.sanitize(request.getParameter("environment"));85 String type = policy.sanitize(request.getParameter("type"));86 boolean active = (request.getParameter("active") != null);87 boolean maintenanceAct = "Y".equals(policy.sanitize(request.getParameter("maintenanceAct"))) ? true : false;88 // Parameter that needs to be secured --> We SECURE+DECODE them89 String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);90 String maintenanceStr = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("maintenanceStr"), "01:00:00", charset);91 String maintenanceEnd = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("maintenanceEnd"), "01:00:00", charset);92 maintenanceStr = maintenanceStr.isEmpty() ? "00:00:00" : maintenanceStr;93 maintenanceEnd = maintenanceEnd.isEmpty() ? "00:00:00" : maintenanceEnd;94 String build = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("build"), "", charset);95 if ("ALL".equalsIgnoreCase(build)) build="";96 String revision = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("revision"), "", charset);97 if ("ALL".equalsIgnoreCase(revision)) revision="";98 String chain = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("chain"), "", charset);99 // Parameter that we cannot secure as we need the html --> We DECODE them100 String distribList = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("distribList"), "", charset);101 String emailBodyRevision = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("eMailBodyRevision"), "", charset);102 String emailBodyChain = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("eMailBodyChain"), "", charset);103 String emailBodyDisableEnvironment = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("eMailBodyDisableEnvironment"), "", charset);104 /**105 * Checking all constrains before calling the services.106 */107 if (StringUtil.isNullOrEmpty(system)) {108 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);109 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)110 .replace("%OPERATION%", "Create")111 .replace("%REASON%", "System is missing!"));112 ans.setResultMessage(msg);113 } else if (StringUtil.isNullOrEmpty(country)) {114 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);115 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)116 .replace("%OPERATION%", "Create")117 .replace("%REASON%", "Country is missing!"));118 ans.setResultMessage(msg);119 } else if (StringUtil.isNullOrEmpty(environment)) {120 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);121 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)122 .replace("%OPERATION%", "Create")123 .replace("%REASON%", "Environment is missing!"));124 ans.setResultMessage(msg);125 } else {126 /**127 * All data seems cleans so we can call the services.128 */129 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());130 ICountryEnvParamService countryEnvParamService = appContext.getBean(ICountryEnvParamService.class);131 IFactoryCountryEnvParam factoryCountryEnvParam = appContext.getBean(IFactoryCountryEnvParam.class);132 CountryEnvParam countryEnvParamData = factoryCountryEnvParam.create(system, country, environment, description, build, revision, chain, distribList, emailBodyRevision, type, emailBodyChain, emailBodyDisableEnvironment, active, maintenanceAct, maintenanceStr, maintenanceEnd);133 ans = countryEnvParamService.create(countryEnvParamData);134 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {135 /**136 * Object created. Adding Log entry.137 */138 ILogEventService logEventService = appContext.getBean(LogEventService.class);139 logEventService.createForPrivateCalls("/CreateCountryEnvParam", "CREATE", "Create CountryEnvParam : ['" + system + "'|'" + country + "'|'" + environment + "']", request);140 }141 }142 /**143 * Formating and returning the json result.144 */145 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());146 jsonResponse.put("message", ans.getResultMessage().getDescription());147 response.getWriter().print(jsonResponse);148 response.getWriter().flush();149 }150 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">151 /**152 * Handles the HTTP <code>GET</code> method.153 *154 * @param request servlet request155 * @param response servlet response156 * @throws ServletException if a servlet-specific error occurs157 * @throws IOException if an I/O error occurs158 */159 @Override160 protected void doGet(HttpServletRequest request, HttpServletResponse response)161 throws ServletException, IOException {162 try {163 processRequest(request, response);164 } catch (CerberusException ex) {165 LOG.warn(ex);166 } catch (JSONException ex) {167 LOG.warn(ex);168 }169 }170 /**171 * Handles the HTTP <code>POST</code> method.172 *173 * @param request servlet request174 * @param response servlet response175 * @throws ServletException if a servlet-specific error occurs176 * @throws IOException if an I/O error occurs177 */178 @Override179 protected void doPost(HttpServletRequest request, HttpServletResponse response)180 throws ServletException, IOException {181 try {182 processRequest(request, response);183 } catch (CerberusException ex) {184 LOG.warn(ex);185 } catch (JSONException ex) {186 LOG.warn(ex);187 }188 }189 /**190 * Returns a short description of the servlet.191 *192 * @return a String containing servlet description193 */194 @Override195 public String getServletInfo() {196 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 CreateCountryEnvParam

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful