Best Cerberus-source code snippet using org.cerberus.util.ParameterParserUtil
Source:UpdateTestCase.java
...44import org.cerberus.crud.service.ITestCaseService;45import org.cerberus.crud.service.impl.LogEventService;46import org.cerberus.enums.MessageEventEnum;47import org.cerberus.exception.CerberusException;48import org.cerberus.util.ParameterParserUtil;49import org.cerberus.util.StringUtil;50import org.cerberus.util.answer.Answer;51import org.cerberus.util.answer.AnswerItem;52import org.cerberus.util.answer.AnswerUtil;53import org.cerberus.util.servlet.ServletUtil;54import org.json.JSONArray;55import org.json.JSONException;56import org.json.JSONObject;57import org.owasp.html.PolicyFactory;58import org.owasp.html.Sanitizers;59import org.springframework.context.ApplicationContext;60import org.springframework.web.context.support.WebApplicationContextUtils;61/**62 *63 * @author cerberus64 */65@WebServlet(name = "UpdateTestCase", urlPatterns = {"/UpdateTestCase"})66public class UpdateTestCase extends HttpServlet {67 private static final Logger LOG = LogManager.getLogger(UpdateTestCase.class);68 private ITestCaseLabelService testCaseLabelService;69 private IFactoryTestCaseLabel testCaseLabelFactory;70 private ITestCaseCountryService testCaseCountryService;71 private IFactoryTestCaseCountry testCaseCountryFactory;72 private ITestCaseService testCaseService;73 /**74 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>75 * methods.76 *77 * @param request servlet request78 * @param response servlet response79 * @throws ServletException if a servlet-specific error occurs80 * @throws IOException if an I/O error occurs81 * @throws org.json.JSONException82 * @throws org.cerberus.exception.CerberusException83 */84 protected void processRequest(HttpServletRequest request, HttpServletResponse response)85 throws ServletException, IOException, JSONException, CerberusException {86 JSONObject jsonResponse = new JSONObject();87 Answer ans = new Answer();88 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);89 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));90 ans.setResultMessage(msg);91 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);92 response.setContentType("application/json");93 // Calling Servlet Transversal Util.94 ServletUtil.servletStart(request);95 /**96 * Parsing and securing all required parameters.97 */98 String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), "");99 String testCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("testCase"), null);100 String keyTest = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTest"), "");101 String keyTestCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTestCase"), null);102 // Prepare the final answer.103 MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);104 Answer finalAnswer = new Answer(msg1);105 /**106 * Checking all constrains before calling the services.107 */108 if ((StringUtil.isNullOrEmpty(test)) || (StringUtil.isNullOrEmpty(testCase)) || (StringUtil.isNullOrEmpty(keyTest)) || (StringUtil.isNullOrEmpty(keyTestCase))) {109 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);110 msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Case")111 .replace("%OPERATION%", "Update")112 .replace("%REASON%", "mandatory fields (test, testcase) are missing."));113 finalAnswer.setResultMessage(msg);114 } else {115 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());116 testCaseService = appContext.getBean(ITestCaseService.class);117 testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);118 testCaseLabelFactory = appContext.getBean(IFactoryTestCaseLabel.class);119 testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);120 testCaseCountryFactory = appContext.getBean(IFactoryTestCaseCountry.class);121 AnswerItem resp = testCaseService.readByKey(keyTest, keyTestCase);122 TestCase tc = (TestCase) resp.getItem();123 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {124 /**125 * Object could not be found. We stop here and report the error.126 */127 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);128 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")129 .replace("%OPERATION%", "Update")130 .replace("%REASON%", "TestCase does not exist."));131 finalAnswer.setResultMessage(msg);132 } else /**133 * The service was able to perform the query and confirm the object134 * exist, then we can update it.135 */136 {137 if (!testCaseService.hasPermissionsUpdate(tc, request)) { // We cannot update the testcase if the user is not at least in Test role.138 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);139 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")140 .replace("%OPERATION%", "Update")141 .replace("%REASON%", "Not enought privilege to update the testcase. You must belong to Test Privilege or even TestAdmin in case the test is in WORKING status."));142 finalAnswer.setResultMessage(msg);143 } else {144 tc = getTestCaseFromRequest(request, tc);145 tc.setTestCaseVersion(tc.getTestCaseVersion()+1);146 // Update testcase147 ans = testCaseService.update(keyTest, keyTestCase, tc);148 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);149 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {150 /**151 * Update was successful. Adding Log entry.152 */153 ILogEventService logEventService = appContext.getBean(LogEventService.class);154 logEventService.createForPrivateCalls("/UpdateTestCase", "UPDATE", "Update testcase : ['" + keyTest + "'|'" + keyTestCase + "'] " + "version : "+tc.getTestCaseVersion(), request);155 // Update labels156 if (request.getParameter("labelList") != null) {157 JSONArray objLabelArray = new JSONArray(request.getParameter("labelList"));158 List<TestCaseLabel> labelList = new ArrayList();159 labelList = getLabelListFromRequest(request, appContext, test, testCase, objLabelArray);160 // Update the Database with the new list.161 ans = testCaseLabelService.compareListAndUpdateInsertDeleteElements(tc.getTest(), tc.getTestCase(), labelList);162 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);163 }164 // Update Countries165 if (request.getParameter("countryList") != null) {166 JSONArray objCountryArray = new JSONArray(request.getParameter("countryList"));167 List<TestCaseCountry> tccList = new ArrayList();168 tccList = getCountryListFromRequest(request, appContext, test, testCase, objCountryArray);169 // Update the Database with the new list.170 ans = testCaseCountryService.compareListAndUpdateInsertDeleteElements(tc.getTest(), tc.getTestCase(), tccList);171 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);172 }173 }174 }175 }176 }177 /**178 * Formating and returning the json result.179 */180 jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());181 jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());182 response.getWriter().print(jsonResponse);183 response.getWriter().flush();184 }185 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">186 /**187 * Handles the HTTP <code>GET</code> method.188 *189 * @param request servlet request190 * @param response servlet response191 * @throws ServletException if a servlet-specific error occurs192 * @throws IOException if an I/O error occurs193 */194 @Override195 protected void doGet(HttpServletRequest request, HttpServletResponse response)196 throws ServletException, IOException {197 try {198 try {199 processRequest(request, response);200 } catch (CerberusException ex) {201 LOG.warn(ex);202 }203 } catch (JSONException ex) {204 LOG.warn(ex);205 }206 }207 /**208 * Handles the HTTP <code>POST</code> method.209 *210 * @param request servlet request211 * @param response servlet response212 * @throws ServletException if a servlet-specific error occurs213 * @throws IOException if an I/O error occurs214 */215 @Override216 protected void doPost(HttpServletRequest request, HttpServletResponse response)217 throws ServletException, IOException {218 try {219 try {220 processRequest(request, response);221 } catch (CerberusException ex) {222 LOG.warn(ex);223 }224 } catch (JSONException ex) {225 LOG.warn(ex);226 }227 }228 /**229 * Returns a short description of the servlet.230 *231 * @return a String containing servlet description232 */233 @Override234 public String getServletInfo() {235 return "Short description";236 }// </editor-fold>237 private TestCase getTestCaseFromRequest(HttpServletRequest request, TestCase tc) throws CerberusException, JSONException, UnsupportedEncodingException {238 String charset = request.getCharacterEncoding();239 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them240 tc.setImplementer(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("implementer"), tc.getImplementer()));241 tc.setUsrModif(request.getUserPrincipal().getName());242 if (!Strings.isNullOrEmpty(request.getParameter("project"))) {243 tc.setProject(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("project"), tc.getProject()));244 } else if (request.getParameter("project") != null && request.getParameter("project").isEmpty()) {245 tc.setProject(null);246 } else {247 tc.setProject(tc.getProject());248 }249 tc.setTest(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), tc.getTest()));250 tc.setApplication(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("application"), tc.getApplication()));251 tc.setActiveQA(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("activeQA"), tc.getActiveQA()));252 tc.setActiveUAT(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("activeUAT"), tc.getActiveUAT()));253 tc.setActivePROD(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("activeProd"), tc.getActivePROD()));254 tc.setTcActive(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("active"), tc.getTcActive()));255 tc.setFromBuild(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("fromSprint"), tc.getFromBuild()));256 tc.setFromRev(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("fromRev"), tc.getFromRev()));257 tc.setToBuild(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("toSprint"), tc.getToBuild()));258 tc.setToRev(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("toRev"), tc.getToRev()));259 tc.setTargetBuild(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("targetSprint"), tc.getTargetBuild()));260 tc.setTargetRev(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("targetRev"), tc.getTargetRev()));261 tc.setConditionOper(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("conditionOper"), tc.getConditionOper()));262 tc.setPriority(ParameterParserUtil.parseIntegerParam(request.getParameter("priority"), tc.getPriority()));263 // Parameter that needs to be secured --> We SECURE+DECODE them264 tc.setTestCase(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("testCase"), tc.getTestCase(), charset));265 tc.setTicket(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("ticket"), tc.getTicket(), charset));266 tc.setOrigine(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("origin"), tc.getOrigine(), charset));267 tc.setGroup(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("group"), tc.getGroup(), charset));268 tc.setStatus(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("status"), tc.getStatus(), charset));269 // Parameter that we cannot secure as we need the html --> We DECODE them270 tc.setDescription(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("shortDesc"), tc.getDescription(), charset));271 tc.setBehaviorOrValueExpected(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("behaviorOrValueExpected"), tc.getBehaviorOrValueExpected(), charset));272 tc.setHowTo(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("howTo"), tc.getHowTo(), charset));273 tc.setBugID(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("bugId"), tc.getBugID(), charset));274 tc.setComment(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("comment"), tc.getComment(), charset));275 tc.setFunction(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("function"), tc.getFunction(), charset));276 tc.setUserAgent(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("userAgent"), tc.getUserAgent(), charset));277 tc.setScreenSize(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("screenSize"), tc.getScreenSize(), charset));278 tc.setConditionVal1(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("conditionVal1"), tc.getConditionVal1(), charset));279 tc.setConditionVal2(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("conditionVal2"), tc.getConditionVal2(), charset));280 return tc;281 }282 private List<TestCaseCountry> getCountryListFromRequest(HttpServletRequest request, ApplicationContext appContext, String test, String testCase, JSONArray json) throws CerberusException, JSONException, UnsupportedEncodingException {283 List<TestCaseCountry> tdldList = new ArrayList();284 for (int i = 0; i < json.length(); i++) {285 JSONObject objectJson = json.getJSONObject(i);286 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them287 boolean delete = objectJson.getBoolean("toDelete");288 String country = objectJson.getString("country");289 // Parameter that needs to be secured --> We SECURE+DECODE them290 // NONE291 // Parameter that we cannot secure as we need the html --> We DECODE them292 if (!delete) {293 TestCaseCountry tcc = testCaseCountryFactory.create(test, testCase, country);...
Source:UpdateTestCaseExecutionQueue.java
...34import org.cerberus.engine.entity.MessageEvent;35import org.cerberus.engine.threadpool.IExecutionThreadPoolService;36import org.cerberus.enums.MessageEventEnum;37import org.cerberus.exception.CerberusException;38import org.cerberus.util.ParameterParserUtil;39import org.cerberus.util.StringUtil;40import org.cerberus.util.answer.Answer;41import org.cerberus.util.answer.AnswerItem;42import org.cerberus.util.answer.AnswerUtil;43import org.cerberus.util.servlet.ServletUtil;44import org.json.JSONException;45import org.json.JSONObject;46import org.owasp.html.PolicyFactory;47import org.owasp.html.Sanitizers;48import org.springframework.context.ApplicationContext;49import org.springframework.web.context.support.WebApplicationContextUtils;50/**51 *52 * @author bcivel53 */54@WebServlet(name = "UpdateTestCaseExecutionQueue", urlPatterns = {"/UpdateTestCaseExecutionQueue"})55public class UpdateTestCaseExecutionQueue extends HttpServlet {56 private static final Logger LOG = LogManager.getLogger(UpdateTestCaseExecutionQueue.class);57 /**58 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>59 * methods.60 *61 * @param request servlet request62 * @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....
Source:CreateBuildRevisionParameters.java
...33import org.cerberus.exception.CerberusException;34import org.cerberus.crud.service.IBuildRevisionParametersService;35import org.cerberus.crud.service.ILogEventService;36import org.cerberus.crud.service.impl.LogEventService;37import org.cerberus.util.ParameterParserUtil;38import org.cerberus.util.answer.Answer;39import org.cerberus.util.servlet.ServletUtil;40import org.json.JSONException;41import org.json.JSONObject;42import org.springframework.context.ApplicationContext;43import org.springframework.web.context.support.WebApplicationContextUtils;44import org.owasp.html.PolicyFactory;45import org.owasp.html.Sanitizers;46/**47 *48 * @author bcivel49 */50@WebServlet(name = "CreateBuildRevisionParameters", urlPatterns = {"/CreateBuildRevisionParameters"})51public class CreateBuildRevisionParameters extends HttpServlet {52 private static final Logger LOG = LogManager.getLogger(CreateBuildRevisionParameters.class);53 private final String OBJECT_NAME = "BuildRevisionParameters";54 /**55 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>56 * methods.57 *58 * @param request servlet request59 * @param response servlet response60 * @throws ServletException if a servlet-specific error occurs61 * @throws IOException if an I/O error occurs62 * @throws org.cerberus.exception.CerberusException63 * @throws org.json.JSONException64 */65 protected void processRequest(HttpServletRequest request, HttpServletResponse response)66 throws ServletException, IOException, CerberusException, JSONException {67 JSONObject jsonResponse = new JSONObject();68 Answer ans = new Answer();69 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);70 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));71 ans.setResultMessage(msg);72 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);73 String charset = request.getCharacterEncoding();74 response.setContentType("application/json");75 // Calling Servlet Transversal Util.76 ServletUtil.servletStart(request);77 78 /**79 * Parsing and securing all required parameters.80 */81 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them82 // Parameter that needs to be secured --> We SECURE+DECODE them83 String build = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("build"), "", charset);84 String revision = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("revision"), "", charset);85 String release = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("release"), "", charset);86 String application = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("application"), "", charset);87 String project = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("project"), "", charset);88 String ticketidfixed = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("ticketidfixed"), "", charset);89 String bugidfixed = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("bugidfixed"), "", charset);90 String releaseowner = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("releaseowner"), "", charset);91 String subject = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("subject"), "", charset);92 String jenkinsbuildid = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("jenkinsbuildid"), "", charset);93 String mavenGroupID = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavengroupid"), "", charset);94 String mavenArtifactID = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavenartifactid"), "", charset);95 String mavenVersion = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavenversion"), "", charset);96 // Parameter that we cannot secure as we need the html --> We DECODE them97 String link = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("link"), "", charset);98 String repositoryUrl = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("repositoryurl"), "", charset);99 /**100 * Checking all constrains before calling the services.101 */102 if (false) {103 // No constrain on that Create operation.104 } else {105 /**106 * All data seems cleans so we can call the services.107 */108 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());109 IBuildRevisionParametersService buildRevisionParametersService = appContext.getBean(IBuildRevisionParametersService.class);110 IFactoryBuildRevisionParameters buildRevisionParametersFactory = appContext.getBean(IFactoryBuildRevisionParameters.class);111 BuildRevisionParameters brpData = buildRevisionParametersFactory.create(0, build, revision, release, application, project, ticketidfixed, bugidfixed, link, releaseowner, subject, null, jenkinsbuildid, mavenGroupID, mavenArtifactID, mavenVersion, repositoryUrl);112 ans = buildRevisionParametersService.create(brpData);...
ParameterParserUtil
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2import org.cerberus.util.ParameterParserUtil;3import org.cerberus.util.ParameterParserUtil;4public class 3 {5 public static void main(String[] args) {6 ParameterParserUtil parameterParserUtil = new ParameterParserUtil();7 parameterParserUtil.parseArguments(args);8 System.out.println(parameterParserUtil.getParameterValue("param1"));9 System.out.println(parameterParserUtil.getParameterValue("param2"));10 System.out.println(parameterParserUtil.getParameterValue("param3"));11 }12}13import org.cerberus.util.ParameterParserUtil;14public class 4 {15 public static void main(String[] args) {16 ParameterParserUtil parameterParserUtil = new ParameterParserUtil();17 parameterParserUtil.parseArguments(args);18 System.out.println(parameterParserUtil.getParameterValue("param1"));19 System.out.println(parameterParserUtil.getParameterValue("param2"));20 System.out.println(parameterParserUtil.getParameterValue("param3"));21 }22}23import org.cerberus.util.ParameterParserUtil;24public class 5 {25 public static void main(String[] args) {26 ParameterParserUtil parameterParserUtil = new ParameterParserUtil();27 parameterParserUtil.parseArguments(args);28 System.out.println(parameterParserUtil.getParameterValue("param1"));29 System.out.println(parameterParserUtil.getParameterValue("param2"));30 System.out.println(parameterParserUtil.getParameterValue("param3"));31 }32}33import org.cerberus.util.ParameterParserUtil;34public class 6 {35 public static void main(String[] args) {36 ParameterParserUtil parameterParserUtil = new ParameterParserUtil();37 parameterParserUtil.parseArguments(args);38 System.out.println(parameterParserUtil.getParameterValue("param1"));39 System.out.println(parameterParserUtil.getParameterValue("param2"));40 System.out.println(parameterParserUtil.getParameterValue("param3"));41 }42}43import org.cerberus.util.ParameterParserUtil;44public class 7 {45 public static void main(String[] args
ParameterParserUtil
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2import java.io.*;3import javax.servlet.*;4import javax.servlet.http.*;5public class 3 extends HttpServlet {6 public void doGet(HttpServletRequest request, HttpServletResponse response)7 throws ServletException, IOException {8 response.setContentType("text/html");9 PrintWriter out = response.getWriter();10 String title = "Using ParameterParserUtil Class";11 out.println(12 + ParameterParserUtil.getParameterValue(request, "first_name")13 + ParameterParserUtil.getParameterValue(request, "last_name")14 + "</body></html>");15 }16}17In the above code, we have used the getParameterValue() method of the ParameterParserUtil class to get the parameter value from the request object. The method takes two parameters:18<%@ page language="java" contentType="text/html; charset=ISO-8859-1"19<%@ page import="org.cerberus.util.ParameterParserUtil"%>
ParameterParserUtil
Using AI Code Generation
1package org.cerberus;2import org.cerberus.util.ParameterParserUtil;3import java.io.*;4import javax.servlet.*;5import javax.servlet.http.*;6public class 3 extends HttpServlet {7 public void doGet(HttpServletRequest request, HttpServletResponse response)8 throws IOException, ServletException {9 String name = ParameterParserUtil.parseStringParam(request, "name", "");10 String age = ParameterParserUtil.parseStringParam(request, "age", "");11 response.setContentType("text/html");12 PrintWriter out = response.getWriter();13 out.println("<html><body>");14 out.println("Name: " + name + "<br>");15 out.println("Age: " + age + "<br>");16 out.println("</body></html>");17 }18}19package org.cerberus;20import org.cerberus.util.ParameterParserUtil;21import java.io.*;22import javax.servlet.*;23import javax.servlet.http.*;24public class 4 extends HttpServlet {25 public void doGet(HttpServletRequest request, HttpServletResponse response)26 throws IOException, ServletException {27 String name = ParameterParserUtil.parseStringParam(request, "name", "");28 String age = ParameterParserUtil.parseStringParam(request, "age", "");29 response.setContentType("text/html");30 PrintWriter out = response.getWriter();31 out.println("<html><body>");32 out.println("Name: " + name + "<br>");33 out.println("Age: " + age + "<br>");34 out.println("</body></html>");35 }36}37package org.cerberus;38import org.cerberus.util.ParameterParserUtil;39import java.io.*;40import javax.servlet.*;41import javax.servlet.http.*;42public class 5 extends HttpServlet {43 public void doGet(HttpServletRequest request, HttpServletResponse response)44 throws IOException, ServletException {45 String name = ParameterParserUtil.parseStringParam(request, "name", "");46 String age = ParameterParserUtil.parseStringParam(request, "age", "");47 response.setContentType("text/html");48 PrintWriter out = response.getWriter();
ParameterParserUtil
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2import java.util.Date;3import java.text.SimpleDateFormat;4public class 3 {5 public static void main(String[] args) {6 ParameterParserUtil parser = new ParameterParserUtil();7 String date = "2017-01-01";8 Date d = parser.parseStringToDate(date, "yyyy-MM-dd");9 SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");10 String formattedDate = sdf.format(d);11 System.out.println(formattedDate);12 }13}
ParameterParserUtil
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2import javax.servlet.http.HttpServletRequest;3import javax.servlet.http.HttpServletResponse;4import javax.servlet.http.HttpServlet;5import javax.servlet.ServletException;6import java.io.IOException;7import java.io.PrintWriter;8public class 3 extends HttpServlet {9 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {10 response.setContentType("text/html");11 PrintWriter out = response.getWriter();12 String name = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("name"), "");13 String age = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("age"), "");14 out.println("<html><body>");15 out.println("<form method=\"post\">");16 out.println("Name: <input type=\"text\" name=\"name\" value=\"" + name + "\" /><br />");17 out.println("Age: <input type=\"text\" name=\"age\" value=\"" + age + "\" /><br />");18 out.println("<input type=\"submit\" value=\"Submit\" />");19 out.println("</form>");20 out.println("</body></html>");21 }22 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {23 response.setContentType("text/html");24 PrintWriter out = response.getWriter();25 String name = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("name"), "");26 String age = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("age"), "");27 out.println("<html><body>");28 out.println("Name: " + name + "<br />");29 out.println("Age: " + age + "<br />");30 out.println("</body></html>");31 }32}33import org.cerberus.util.ParameterParser
ParameterParserUtil
Using AI Code Generation
1import java.io.*;2import javax.servlet.*;3import javax.servlet.http.*;4import org.cerberus.util.ParameterParserUtil;5public class 3 extends HttpServlet {6 public void doGet(HttpServletRequest req, HttpServletResponse res)7 throws ServletException, IOException {8 res.setContentType("text/html");9 PrintWriter out = res.getWriter();10 String paramValue = ParameterParserUtil.parseStringParam(req,"id",null);11 out.println("<html><body>");12 out.println("<table border=1>");13 out.println("<tr><td>Parameter Name:</td><td>id</td></tr>");14 out.println("<tr><td>Parameter Value:</td><td>"+paramValue+"</td></tr>");15 out.println("</table>");16 out.println("</body></html>");17 }18}19import java.io.*;20import javax.servlet.*;21import javax.servlet.http.*;22import org.cerberus.util.ParameterParserUtil;23public class 4 extends HttpServlet {24 public void doGet(HttpServletRequest req, HttpServletResponse res)25 throws ServletException, IOException {26 res.setContentType("text/html");27 PrintWriter out = res.getWriter();28 HttpSession session = req.getSession(true);29 String paramValue = ParameterParserUtil.parseStringParam(req,"id",null);30 session.setAttribute("id",paramValue);31 out.println("<html><body>");32 out.println("<table border=1>");33 out.println("<tr><td>Parameter Name:</td><td>id</td></tr>");34 out.println("<tr><td>Parameter Value:</td><td>"+paramValue+"</td></tr>");35 out.println("<tr><td>Session Variable Name:</td><td>id</td></tr>");36 out.println("<tr><td>Session Variable Value:</td><td>"+(
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!