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

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

Source:CreateApplication.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 /**80 * Parsing and securing all required parameters.81 */82 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them83 String system = policy.sanitize(request.getParameter("system"));84 String type = policy.sanitize(request.getParameter("type"));85 String deployType = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("deploytype"), "", charset);86 // Parameter that needs to be secured --> We SECURE+DECODE them87 String application = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("application"), null, charset);88 String subSystem = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("subsystem"), "", charset);89 String mavenGpID = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavengroupid"), "", charset);90 String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);91 // Parameter that we cannot secure as we need the html --> We DECODE them92 String svnURL = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("svnurl"), "", charset);93 String bugTrackerURL = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("bugtrackerurl"), "", charset);94 String newBugURL = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("bugtrackernewurl"), "", charset);95 Integer sort = 10;96 boolean sort_error = false;97 try {98 if (request.getParameter("sort") != null && !request.getParameter("sort").equals("")) {99 sort = Integer.valueOf(policy.sanitize(request.getParameter("sort")));100 }101 } catch (Exception ex) {102 sort_error = true;103 }104 /**105 * Checking all constrains before calling the services.106 */107 if (StringUtil.isNullOrEmpty(application)) {108 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);109 msg.setDescription(msg.getDescription().replace("%ITEM%", "Application")110 .replace("%OPERATION%", "Create")111 .replace("%REASON%", "Application name is missing!"));112 ans.setResultMessage(msg);113 } else if (StringUtil.isNullOrEmpty(system)) {114 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);115 msg.setDescription(msg.getDescription().replace("%ITEM%", "Application")116 .replace("%OPERATION%", "Create")117 .replace("%REASON%", "System is missing!"));118 ans.setResultMessage(msg);119 } else if (sort_error) {120 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);121 msg.setDescription(msg.getDescription().replace("%ITEM%", "Application")122 .replace("%OPERATION%", "Create")123 .replace("%REASON%", "Could not manage to convert sort to an integer value!"));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 IApplicationService applicationService = appContext.getBean(IApplicationService.class);131 IFactoryApplication factoryApplication = appContext.getBean(IFactoryApplication.class);132 Application applicationData = factoryApplication.create(application, description, sort, type, system, 133 subSystem, svnURL, deployType, mavenGpID, bugTrackerURL, newBugURL, request.getRemoteUser(), null, null, null);134 ans = applicationService.create(applicationData);135 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {136 /**137 * Object created. Adding Log entry.138 */139 ILogEventService logEventService = appContext.getBean(LogEventService.class);140 logEventService.createForPrivateCalls("/CreateApplication", "CREATE", "Create Application : ['" + application + "']", request);141 }142 }143 /**144 * Formating and returning the json result.145 */146 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());147 jsonResponse.put("message", ans.getResultMessage().getDescription());148 response.getWriter().print(jsonResponse);149 response.getWriter().flush();150 }151 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">152 /**153 * Handles the HTTP <code>GET</code> method.154 *155 * @param request servlet request156 * @param response servlet response157 * @throws ServletException if a servlet-specific error occurs158 * @throws IOException if an I/O error occurs159 */160 @Override161 protected void doGet(HttpServletRequest request, HttpServletResponse response)162 throws ServletException, IOException {163 try {164 processRequest(request, response);165 } catch (CerberusException ex) {166 LOG.warn(ex);167 } catch (JSONException ex) {168 LOG.warn(ex);169 }170 }171 /**172 * Handles the HTTP <code>POST</code> method.173 *174 * @param request servlet request175 * @param response servlet response176 * @throws ServletException if a servlet-specific error occurs177 * @throws IOException if an I/O error occurs178 */179 @Override180 protected void doPost(HttpServletRequest request, HttpServletResponse response)181 throws ServletException, IOException {182 try {183 processRequest(request, response);184 } catch (CerberusException ex) {185 LOG.warn(ex);186 } catch (JSONException ex) {187 LOG.warn(ex);188 }189 }190 /**191 * Returns a short description of the servlet.192 *193 * @return a String containing servlet description194 */195 @Override196 public String getServletInfo() {197 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 CreateApplication

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful