Best Cerberus-source code snippet using org.cerberus.util.ParameterParserUtil.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:AbstractCrudTestCase.java
...23import org.cerberus.crud.entity.TestCase;24import org.cerberus.engine.entity.MessageGeneral;25import org.cerberus.enums.MessageGeneralEnum;26import org.cerberus.exception.CerberusException;27import org.cerberus.util.ParameterParserUtil;28import org.json.JSONException;29import org.springframework.beans.factory.config.AutowireCapableBeanFactory;30import org.springframework.web.context.WebApplicationContext;31import org.springframework.web.context.support.WebApplicationContextUtils;32import javax.servlet.ServletConfig;33import javax.servlet.ServletException;34import javax.servlet.http.HttpServlet;35import javax.servlet.http.HttpServletRequest;36import javax.servlet.http.HttpServletResponse;37import java.io.IOException;38import org.json.JSONArray;39public abstract class AbstractCrudTestCase extends HttpServlet {40 private WebApplicationContext springContext;41 private static final Logger LOG = LogManager.getLogger(AbstractCrudTestCase.class);42 protected abstract void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException, JSONException;43 /**44 * Handles the HTTP <code>POST</code> method.45 *46 * @param request servlet request47 * @param response servlet response48 * @throws ServletException if a servlet-specific error occurs49 * @throws IOException if an I/O error occurs50 */51 @Override52 protected void doPost(HttpServletRequest request, HttpServletResponse response)53 throws ServletException, IOException {54 try {55 processRequest(request, response);56 } catch (CerberusException | JSONException ex) {57 LOG.warn(ex, ex);58 } // FIXME where Exception is managed ?59 }60 /**61 * Handles the HTTP <code>GET</code> method.62 *63 * @param request servlet request64 * @param response servlet response65 * @throws ServletException if a servlet-specific error occurs66 * @throws IOException if an I/O error occurs67 */68 @Override69 protected void doGet(HttpServletRequest request, HttpServletResponse response)70 throws ServletException, IOException {71 try {72 processRequest(request, response);73 } catch (CerberusException | JSONException ex) {74 LOG.warn(ex, ex);75 }76 }77 /**78 * Returns a short description of the servlet.79 *80 * @return a String containing servlet description81 */82 @Override83 public String getServletInfo() {84 return "Short description";85 }86 @Override87 public void init(final ServletConfig config) throws ServletException {88 super.init(config);89 springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());90 final AutowireCapableBeanFactory beanFactory = springContext.getAutowireCapableBeanFactory();91 beanFactory.autowireBean(this);92 }93 protected TestCase getTestCaseFromRequest(HttpServletRequest request, TestCase tc) throws CerberusException {94 try {95 String charset = request.getCharacterEncoding() == null ? "UTF-8" : request.getCharacterEncoding();96 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them97 tc.setImplementer(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("implementer"), tc.getImplementer(), charset));98 tc.setExecutor(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("executor"), tc.getExecutor(), charset));99 tc.setExecutor(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("executor"), tc.getExecutor(), charset));100 tc.setUsrCreated(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getUserPrincipal().getName(), "", charset));101 tc.setApplication(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("application"), tc.getApplication(), charset));102 tc.setActiveQA(ParameterParserUtil.parseBooleanParam(request.getParameter("isActiveQA"), tc.isActiveQA()));103 tc.setActiveUAT(ParameterParserUtil.parseBooleanParam(request.getParameter("isActiveUAT"), tc.isActiveUAT()));104 tc.setActivePROD(ParameterParserUtil.parseBooleanParam(request.getParameter("isActivePROD"), tc.isActivePROD()));105 tc.setFromMajor(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("fromMajor"), tc.getFromMajor(), charset));106 tc.setFromMinor(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("fromMinor"), tc.getFromMinor(), charset));107 tc.setToMajor(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("toMajor"), tc.getToMajor(), charset));108 tc.setToMinor(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("toMinor"), tc.getToMinor(), charset));109 tc.setActive(ParameterParserUtil.parseBooleanParam(request.getParameter("isActive"), tc.isActive()));110 tc.setTargetMajor(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("targetMajor"), tc.getTargetMajor(), charset));111 tc.setTargetMinor(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("targetMinor"), tc.getTargetMinor(), charset));112 tc.setPriority(ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("priority"), tc.getPriority(), charset));113 tc.setTest(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("test"), tc.getTest(), charset));114 tc.setTestCase(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("testCase"), tc.getTestCase(), charset));115 tc.setOrigine(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("origin"), tc.getOrigine(), charset));116 tc.setType(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("type"), tc.getType(), charset));117 tc.setStatus(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("status"), tc.getStatus(), charset));118 tc.setDescription(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("description"), tc.getDescription(), charset));119 String bug = tc.getBugs() == null ? "" : tc.getBugs().toString();120 String bugsString = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("bugs"), bug, charset);121 JSONArray bugs = new JSONArray();122 try {123 bugs = new JSONArray(bugsString);124 } catch (JSONException ex) {125 LOG.error("Could not convert '" + bugsString + "' to JSONArray.", ex);126 }127 tc.setBugs(bugs);128 tc.setComment(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("comment"), tc.getComment(), charset));129 tc.setUserAgent(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("userAgent"), tc.getUserAgent(), charset));130 tc.setScreenSize(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("screenSize"), tc.getScreenSize(), charset));131 tc.setDetailedDescription(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("detailedDescription"), tc.getDetailedDescription(), charset));132 // TODO verify, this setteer was not call on "create test case"133 tc.setConditionOperator(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("conditionOperator"), tc.getConditionOperator(), charset));134 // Parameter that we cannot secure as we need the html --> We DECODE them135 tc.setConditionVal1(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("conditionVal1"), tc.getConditionVal1(), charset));136 tc.setConditionVal2(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("conditionVal2"), tc.getConditionVal2(), charset));137 tc.setConditionVal3(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("conditionVal3"), tc.getConditionVal3(), charset));138 return tc;139 } catch (UnsupportedOperationException e) {140 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.GENERIC_ERROR), e);141 }142 }143}...
ParameterParserUtil
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2public class 3 {3public static void main(String[] args) {4System.out.println(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(args[0], ""));5}6}7import org.cerberus.util.ParameterParserUtil;8public class 4 {9public static void main(String[] args) {10System.out.println(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(args[0], "", true));11}12}13import org.cerberus.util.ParameterParserUtil;14public class 5 {15public static void main(String[] args) {16System.out.println(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(args[0], "", true, true));17}18}19import org.cerberus.util.ParameterParserUtil;20public class 6 {21public static void main(String[] args) {22System.out.println(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(args[0], "", true, true, false));23}24}25import org.cerberus.util.ParameterParserUtil;26public class 7 {27public static void main(String[] args) {28System.out.println(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(args[0], "", true, true, false, false));29}30}31import org.cerberus.util.ParameterParserUtil;32public class 8 {33public static void main(String[] args) {34System.out.println(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(args[0], "", true, true, false, false, false));35}36}37import org.cerberus.util.ParameterParserUtil;38public class 9 {39public static void main(String[] args) {40System.out.println(ParameterParser
ParameterParserUtil
Using AI Code Generation
1package org.cerberus.util;2import java.util.*;3public class ParameterParserUtil {4 public static String parseStringParamAndDecodeAndSanitize(String parameter, String defaultValue) {5 if (parameter != null && !parameter.isEmpty()) {6 return StringEscapeUtils.escapeHtml4(parameter);7 }8 return defaultValue;9 }10 public static String parseStringParamAndDecodeAndSanitize(String parameter) {11 return parseStringParamAndDecodeAndSanitize(parameter, "");12 }13}14package org.cerberus.util;15import java.util.*;16public class ParameterParserUtil {17 public static String parseStringParamAndDecodeAndSanitize(String parameter, String defaultValue) {18 if (parameter != null && !parameter.isEmpty()) {19 return StringEscapeUtils.escapeHtml4(parameter);20 }21 return defaultValue;22 }23 public static String parseStringParamAndDecodeAndSanitize(String parameter) {24 return parseStringParamAndDecodeAndSanitize(parameter, "");25 }26}27package org.cerberus.util;28import java.util.*;29public class ParameterParserUtil {30 public static String parseStringParamAndDecodeAndSanitize(String parameter, String defaultValue) {31 if (parameter != null && !parameter.isEmpty()) {32 return StringEscapeUtils.escapeHtml4(parameter);33 }34 return defaultValue;35 }36 public static String parseStringParamAndDecodeAndSanitize(String parameter) {37 return parseStringParamAndDecodeAndSanitize(parameter, "");38 }39}40package org.cerberus.util;41import java.util.*;42public class ParameterParserUtil {43 public static String parseStringParamAndDecodeAndSanitize(String parameter, String defaultValue) {44 if (parameter != null && !parameter.isEmpty()) {45 return StringEscapeUtils.escapeHtml4(parameter);46 }47 return defaultValue;48 }49 public static String parseStringParamAndDecodeAndSanitize(String parameter) {50 return parseStringParamAndDecodeAndSanitize(parameter, "");51 }52}
ParameterParserUtil
Using AI Code Generation
1package org.cerberus.util;2import java.util.Date;3import java.util.HashMap;4import java.util.Map;5public class ParameterParserUtil {6 public static Map<String, String> parseParameters(String urlParameters) {7 Map<String, String> parameters = new HashMap<String, String>();8 if (urlParameters != null) {9 String[] parameterArray = urlParameters.split("&");10 for (String parameter : parameterArray) {11 String[] parameterEntry = parameter.split("=");12 if (parameterEntry.length == 2) {13 parameters.put(parameterEntry[0], parameterEntry[1]);14 }15 }16 }17 return parameters;18 }19 public static String getParameterValue(Map<String, String> parameters, String parameterName) {20 String parameterValue = null;21 if (parameters.containsKey(parameterName)) {22 parameterValue = parameters.get(parameterName);23 }24 return parameterValue;25 }26 public static int getParameterIntegerValue(Map<String, String> parameters, String parameterName) {27 int parameterValue = 0;28 if (parameters.containsKey(parameterName)) {29 try {30 parameterValue = Integer.parseInt(parameters.get(parameterName));31 } catch (NumberFormatException e) {32 parameterValue = 0;33 }34 }35 return parameterValue;36 }37 public static long getParameterLongValue(Map<String, String> parameters, String parameterName) {38 long parameterValue = 0;39 if (parameters.containsKey(parameterName)) {40 try {41 parameterValue = Long.parseLong(parameters.get(parameterName));42 } catch (NumberFormatException e) {43 parameterValue = 0;44 }45 }46 return parameterValue;47 }
ParameterParserUtil
Using AI Code Generation
1package com.mycompany.myapp;2import java.io.IOException;3import java.util.Map;4import javax.servlet.ServletException;5import javax.servlet.http.HttpServlet;6import javax.servlet.http.HttpServletRequest;7import javax.servlet.http.HttpServletResponse;8import org.cerberus.util.ParameterParserUtil;9public class 3 extends HttpServlet {10 private static final long serialVersionUID = 1L;11 public void doGet(HttpServletRequest request, HttpServletResponse response) throws12ServletException, IOException {13 Map<String, String[]> params = ParameterParserUtil.parseParamters(request);14 }15 public void doPost(HttpServletRequest request, HttpServletResponse response) throws16ServletException, IOException {17 Map<String, String[]> params = ParameterParserUtil.parseParamters(request);18 }19}20package com.mycompany.myapp;21import java.io.IOException;22import java.util.Map;23import javax.servlet.ServletException;24import javax.servlet.http.HttpServlet;25import javax.servlet.http.HttpServletRequest;26import javax.servlet.http.HttpServletResponse;27import org.cerberus.util.ParameterParserUtil;28public class 4 extends HttpServlet {29 private static final long serialVersionUID = 1L;30 public void doGet(HttpServletRequest request, HttpServletResponse response) throws31ServletException, IOException {32 Map<String, String[]> params = ParameterParserUtil.parseParamters(request);33 }34 public void doPost(HttpServletRequest request, HttpServletResponse response) throws35ServletException, IOException {36 Map<String, String[]> params = ParameterParserUtil.parseParamters(request);37 }38}
ParameterParserUtil
Using AI Code Generation
1package org.cerberus.util;2import java.io.IOException;3import javax.servlet.ServletException;4import javax.servlet.http.HttpServlet;5import javax.servlet.http.HttpServletRequest;6import javax.servlet.http.HttpServletResponse;7public class 3 extends HttpServlet {8 protected void processRequest(HttpServletRequest request, HttpServletResponse response)9 throws ServletException, IOException {10 response.setContentType("text/html;charset=UTF-8");11 try (PrintWriter out = response.getWriter()) {12 String param1 = request.getParameter("param1");13 if (ParameterParserUtil.parseStringParamAndSanitize(param1, 10) == null) {14 out.println("Parameter is not valid");15 } else {16 out.println("Parameter is valid");17 }18 }19 }20 protected void doGet(HttpServletRequest request, HttpServletResponse response)21 throws ServletException, IOException {22 processRequest(request, response);23 }24 protected void doPost(HttpServletRequest request, HttpServletResponse response)25 throws ServletException, IOException {26 processRequest(request, response);27 }28 public String getServletInfo() {29 return "Short description";30}31package org.cerberus.util;32import java.io.IOException;33import javax.servlet.ServletException;34import javax.servlet.http.HttpServlet;35import javax.servlet.http.HttpServletRequest;36import javax.servlet.http.HttpServletResponse;37public class 4 extends HttpServlet {38 protected void processRequest(HttpServletRequest request, HttpServletResponse response)39 throws ServletException, IOException {40 response.setContentType("text/html;charset=UTF-8");41 try (PrintWriter out = response.getWriter()) {42 String param1 = request.getParameter("param1");43 if (ParameterParserUtil.parseStringParamAndSanitize(param1, 10, true) == null) {44 out.println("Parameter is not valid");45 } else {46 out.println("Parameter is valid");47 }48 }49 }50 protected void doGet(HttpServletRequest request, HttpServletResponse response)51 throws ServletException, IOException {52 processRequest(request, response);53 }54 protected void doPost(HttpServletRequest request, HttpServletResponse response)55 throws ServletException, IOException {56 processRequest(request, response);57 }58 public String getServletInfo() {59 return "Short description";60}
ParameterParserUtil
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2public class 3 {3public static void main(String[] args) {4ParameterParserUtil pp = new ParameterParserUtil();5String[] myArray = pp.parseParam("a,b,c,d,e", ",");6for (int i = 0; i < myArray.length; i++) {7System.out.println(myArray[i]);8}9}10}
ParameterParserUtil
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2public class 3 {3 public static void main(String[] args) {4 String[] param = {"1", "2", "3", "4", "5"};5 String[] result = ParameterParserUtil.parseStringArrayParam(param, ",");6 for (int i = 0; i < result.length; i++) {7 System.out.println(result[i]);8 }9 }10}11import org.cerberus.util.ParameterParserUtil;12public class 4 {13 public static void main(String[] args) {14 String[] param = {"1", "2", "3", "4", "5"};15 String[] result = ParameterParserUtil.parseStringArrayParam(param, "-");16 for (int i = 0; i < result.length; i++) {17 System.out.println(result[i]);18 }19 }20}21import org.cerberus.util.ParameterParserUtil;22public class 5 {23 public static void main(String[] args) {24 String[] param = {"1", "2", "3", "4", "5"};25 String[] result = ParameterParserUtil.parseStringArrayParam(param, " ");26 for (int i = 0; i < result.length; i++) {27 System.out.println(result[i]);28 }29 }30}31import org.cerberus.util.ParameterParserUtil;32public class 6 {33 public static void main(String[] args) {34 String[] param = {"1", "2", "3", "4", "5"};35 String[] result = ParameterParserUtil.parseStringArrayParam(param, "A");36 for (int i = 0; i < result.length; i++) {37 System.out.println(result[i]);38 }39 }40}
ParameterParserUtil
Using AI Code Generation
1package org.cerberus.util;2public class ParameterParserUtil {3 public static String parseStringParam(String param, String defaultValue) {4 if (param != null && !param.isEmpty()) {5 return param;6 } else {7 return defaultValue;8 }9 }10}11package org.cerberus.util;12public class ParameterParserUtil {13 public static String parseStringParam(String param, String defaultValue) {14 if (param != null && !param.isEmpty()) {15 return param;16 } else {17 return defaultValue;18 }19 }20}21package org.cerberus.util;22public class ParameterParserUtil {23 public static String parseStringParam(String param, String defaultValue) {24 if (param != null && !param.isEmpty()) {25 return param;26 } else {27 return defaultValue;28 }29 }30}31package org.cerberus.util;32public class ParameterParserUtil {33 public static String parseStringParam(String param, String defaultValue) {34 if (param != null && !param.isEmpty()) {35 return param;36 } else {37 return defaultValue;38 }39 }40}41package org.cerberus.util;42public class ParameterParserUtil {43 public static String parseStringParam(String param, String defaultValue) {44 if (param != null && !param.isEmpty()) {45 return param;46 } else {47 return defaultValue;48 }49 }50}51package org.cerberus.util;52public class ParameterParserUtil {53 public static String parseStringParam(String param, String defaultValue) {54 if (param != null && !
ParameterParserUtil
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2public class 3 {3 public static void main(String[] args) {4 String[] params = {"-f", "file_name", "-v", "version", "-u", "user_name", "-p", "password", "-d", "directory"};5 ParameterParserUtil parser = new ParameterParserUtil();6 parser.parse(params);7 System.out.println(parser.getOptionValue("f"));8 System.out.println(parser.getOptionValue("v"));9 System.out.println(parser.getOptionValue("u"));10 System.out.println(parser.getOptionValue("p"));11 System.out.println(parser.getOptionValue("d"));12 }13}
ParameterParserUtil
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2public class 3 {3 public static void main(String[] args) {4 String param1 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(args, "param1", "defaultValue");5 System.out.println(param1);6 }7}8import org.cerberus.util.ParameterParserUtil;9public class 4 {10 public static void main(String[] args) {11 String param1 = ParameterParserUtil.parseStringParam(args, "param1", "defaultValue");12 System.out.println(param1);13 }14}15import org.cerberus.util.ParameterParserUtil;16public class 5 {17 public static void main(String[] args) {18 String param1 = ParameterParserUtil.parseStringParamAndDecode(args, "param1", "defaultValue");19 System.out.println(param1);20 }21}22import org.cerberus.util.ParameterParserUtil;23public class 6 {24 public static void main(String[] args) {25 String param1 = ParameterParserUtil.parseStringParamAndSanitize(args, "param1", "defaultValue");26 System.out.println(param1);27 }28}29import org.cerberus.util.ParameterParserUtil;30public class 7 {31 public static void main(String[] args) {32 String param1 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(args, "param1", "defaultValue");33 System.out.println(param1);34 }35}
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!!