How to use processRequest method of org.cerberus.servlet.crud.testexecution.UpdateTestCaseExecutionQueue class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.testexecution.UpdateTestCaseExecutionQueue.processRequest

Source:UpdateTestCaseExecutionQueue.java Github

copy

Full Screen

...62 * @param response servlet response63 * @throws ServletException if a servlet-specific error occurs64 * @throws IOException if an I/O error occurs65 */66 protected void processRequest(HttpServletRequest request, HttpServletResponse response)67 throws ServletException, IOException, CerberusException, JSONException {68 JSONObject jsonResponse = new JSONObject();69 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());70 Answer ans = new Answer();71 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);72 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));73 ans.setResultMessage(msg);74 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);75 String charset = request.getCharacterEncoding();76 response.setContentType("application/json");77 // Calling Servlet Transversal Util.78 ServletUtil.servletStart(request);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 actionState = policy.sanitize(request.getParameter("actionState"));84 String actionSave = policy.sanitize(request.getParameter("actionSave"));85 String environment = policy.sanitize(request.getParameter("environment"));86 String country = policy.sanitize(request.getParameter("country"));87 String manualEnvData = policy.sanitize(request.getParameter("manualEnvData"));88 // Parameter that needs to be secured --> We SECURE+DECODE them89 String test = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("test"), null, charset);90 String testcase = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("testCase"), null, charset);91 int manualURL = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("manualURL"), 0, charset);92 String manualHost = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("manualHost"), null, charset);93 String manualContextRoot = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("manualContextRoot"), "", charset);94 String manualLoginRelativeURL = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("manualLoginRelativeURL"), "", charset);95 String tag = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("tag"), null, charset);96 String robot = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("robot"), null, charset);97 String robotIP = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("robotIP"), null, charset);98 String robotPort = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("robotPort"), null, charset);99 String browser = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("browser"), null, charset);100 String browserVersion = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("browserVersion"), null, charset);101 String platform = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("platform"), null, charset);102 String screenSize = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("screenSize"), null, charset);103 int verbose = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("verbose"), 1, charset);104 int screenshot = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("screenshot"), 0, charset);105 int pageSource = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("pageSource"), 0, charset);106 int seleniumLog = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("seleniumLog"), 0, charset);107 String timeout = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("timeout"), "", charset);108 int retries = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("retries"), 0, charset);109 String manualExecution = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("manualExecution"), "", charset);110 String debugFlag = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("debugFlag"), "N", charset);111 Integer priority = TestCaseExecutionQueue.PRIORITY_DEFAULT;112 boolean prio_error = false;113 try {114 if (request.getParameter("priority") != null && !request.getParameter("priority").equals("")) {115 priority = Integer.valueOf(policy.sanitize(request.getParameter("priority")));116 }117 } catch (Exception ex) {118 prio_error = true;119 }120 // Parameter that we cannot secure as we need the html --> We DECODE them121 String[] myIds = request.getParameterValues("id");122 long id = 0;123 // Create Tag when exist.124 if (!StringUtil.isNullOrEmpty(tag)) {125 // We create or update it.126 ITagService tagService = appContext.getBean(ITagService.class);127 tagService.createAuto(tag, "", request.getRemoteUser());128 }129 // Prepare the final answer.130 MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);131 Answer finalAnswer = new Answer(msg1);132 boolean id_error = false;133 for (String myId : myIds) {134 id_error = false;135 try {136 id = Long.valueOf(myId);137 } catch (NumberFormatException ex) {138 id_error = true;139 }140 /**141 * Checking all constrains before calling the services.142 */143 if (id_error) {144 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);145 msg.setDescription(msg.getDescription().replace("%ITEM%", "Execution Queue")146 .replace("%OPERATION%", "Update")147 .replace("%REASON%", "Could not manage to convert id to an integer value."));148 ans.setResultMessage(msg);149 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);150 } else if (prio_error || priority > 2147483647 || priority < -2147483648) {151 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);152 msg.setDescription(msg.getDescription().replace("%ITEM%", "Execution Queue")153 .replace("%OPERATION%", "Update")154 .replace("%REASON%", "Could not manage to convert priority to an integer value."));155 ans.setResultMessage(msg);156 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);157 } else {158 /**159 * All data seems cleans so we can call the services.160 */161 ITestCaseExecutionQueueService executionQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);162 IExecutionThreadPoolService executionThreadPoolService = appContext.getBean(IExecutionThreadPoolService.class);163 AnswerItem resp = executionQueueService.readByKey(id);164 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {165 /**166 * Object could not be found. We stop here and report the167 * error.168 */169 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) resp);170 } else {171 TestCaseExecutionQueue executionQueueData = (TestCaseExecutionQueue) resp.getItem();172 if (actionSave.equals("save")) {173 /**174 * The service was able to perform the query and confirm175 * the object exist, then we can update it.176 */177 executionQueueData.setTest(ParameterParserUtil.parseStringParam(test, executionQueueData.getTest()));178 executionQueueData.setTestCase(ParameterParserUtil.parseStringParam(testcase, executionQueueData.getTestCase()));179 executionQueueData.setTag(ParameterParserUtil.parseStringParam(tag, executionQueueData.getTag()));180 executionQueueData.setEnvironment(ParameterParserUtil.parseStringParam(environment, executionQueueData.getEnvironment()));181 executionQueueData.setCountry(ParameterParserUtil.parseStringParam(country, executionQueueData.getCountry()));182 executionQueueData.setManualURL(ParameterParserUtil.parseIntegerParam(manualURL, executionQueueData.getManualURL()));183 executionQueueData.setManualHost(ParameterParserUtil.parseStringParam(manualHost, executionQueueData.getManualHost()));184 executionQueueData.setManualContextRoot(ParameterParserUtil.parseStringParam(manualContextRoot, executionQueueData.getManualContextRoot()));185 executionQueueData.setManualLoginRelativeURL(ParameterParserUtil.parseStringParam(manualLoginRelativeURL, executionQueueData.getManualLoginRelativeURL()));186 executionQueueData.setManualEnvData(ParameterParserUtil.parseStringParam(manualEnvData, executionQueueData.getManualEnvData()));187 executionQueueData.setRobot(ParameterParserUtil.parseStringParam(robot, executionQueueData.getRobot()));188 executionQueueData.setRobotIP(ParameterParserUtil.parseStringParam(robotIP, executionQueueData.getRobotIP()));189 executionQueueData.setRobotPort(ParameterParserUtil.parseStringParam(robotPort, executionQueueData.getRobotPort()));190 executionQueueData.setBrowser(ParameterParserUtil.parseStringParam(browser, executionQueueData.getBrowser()));191 executionQueueData.setBrowserVersion(ParameterParserUtil.parseStringParam(browserVersion, executionQueueData.getBrowserVersion()));192 executionQueueData.setPlatform(ParameterParserUtil.parseStringParam(platform, executionQueueData.getPlatform()));193 executionQueueData.setScreenSize(ParameterParserUtil.parseStringParam(screenSize, executionQueueData.getScreenSize()));194 executionQueueData.setVerbose(ParameterParserUtil.parseIntegerParam(verbose, executionQueueData.getVerbose()));195 executionQueueData.setScreenshot(screenshot);196 executionQueueData.setPageSource(pageSource);197 executionQueueData.setSeleniumLog(seleniumLog);198 executionQueueData.setTimeout(timeout);199 executionQueueData.setRetries(retries);200 executionQueueData.setManualExecution(manualExecution);201 executionQueueData.setDebugFlag(debugFlag);202 executionQueueData.setPriority(priority);203 executionQueueData.setUsrModif(request.getRemoteUser());204 ans = executionQueueService.update(executionQueueData);205 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);206 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {207 /**208 * Update was successfull. Adding Log entry.209 */210 ILogEventService logEventService = appContext.getBean(LogEventService.class);211 logEventService.createForPrivateCalls("/UpdateTestCaseExecutionQueue", "UPDATE", "Updated ExecutionQueue : ['" + id + "']", request);212 }213 }214 // Update is done, we now check what action needs to be performed.215 if (actionState.equals("toQUEUED")) {216 LOG.debug("toQUEUED");217 ans = executionQueueService.updateToQueued(id, "Trigered by user " + request.getRemoteUser() + ".");218 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);219 executionThreadPoolService.executeNextInQueueAsynchroneously(false);220 }221 // Priority Update.222 if (actionSave.equals("priority")) {223 executionQueueData.setPriority(priority);224 ans = executionQueueService.update(executionQueueData);225 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);226 }227 // Update is done, we now check what action needs to be performed.228 if (actionState.equals("toCANCELLED")) {229 LOG.debug("toCANCELLED");230 ans = executionQueueService.updateToCancelled(id, "Cancelled by user " + request.getRemoteUser() + ".");231 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);232 }233 // Update is done, we now check what action needs to be performed.234 if (actionState.equals("toCANCELLEDForce")) {235 LOG.debug("toCANCELLEDForce");236 ans = executionQueueService.updateToCancelledForce(id, "Forced Cancelled by user " + request.getRemoteUser() + ".");237 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);238 }239 // Update is done, we now check what action needs to be performed.240 if (actionState.equals("toERRORForce")) {241 LOG.debug("toERRORForce");242 ans = executionQueueService.updateToErrorForce(id, "Forced Eroor by user " + request.getRemoteUser() + ".");243 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);244 }245 }246 }247 }248 /**249 * Formating and returning the json result.250 */251 jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());252 jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());253 response.getWriter().print(jsonResponse);254 response.getWriter().flush();255 }256 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">257 /**258 * Handles the HTTP <code>GET</code> method.259 *260 * @param request servlet request261 * @param response servlet response262 * @throws ServletException if a servlet-specific error occurs263 * @throws IOException if an I/O error occurs264 */265 @Override266 protected void doGet(HttpServletRequest request, HttpServletResponse response)267 throws ServletException, IOException {268 try {269 processRequest(request, response);270 } catch (CerberusException ex) {271 LOG.warn(ex);272 } catch (JSONException ex) {273 LOG.warn(ex);274 }275 }276 /**277 * Handles the HTTP <code>POST</code> method.278 *279 * @param request servlet request280 * @param response servlet response281 * @throws ServletException if a servlet-specific error occurs282 * @throws IOException if an I/O error occurs283 */284 @Override285 protected void doPost(HttpServletRequest request, HttpServletResponse response)286 throws ServletException, IOException {287 try {288 processRequest(request, response);289 } catch (CerberusException ex) {290 LOG.warn(ex);291 } catch (JSONException ex) {292 LOG.warn(ex);293 }294 }295 /**296 * Returns a short description of the servlet.297 *298 * @return a String containing servlet description299 */300 @Override301 public String getServletInfo() {302 return "Short description";...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1importPackage(java.io);2importPackage(java.net);3var connection = url.openConnection();4connection.setRequestMethod("POST");5connection.setDoOutput(true);6connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");7connection.setRequestProperty("charset", "utf-8");8connection.setRequestProperty("Content-Length", "0");9connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0");10connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");11connection.setRequestProperty("Accept-Language", "en-US,en;q=0.5");12connection.setRequestProperty("Accept-Encoding", "gzip, deflate");

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 UpdateTestCaseExecutionQueue

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful