How to use processRequest method of org.cerberus.servlet.crud.testdata.CreateTestDataLib class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.testdata.CreateTestDataLib.processRequest

Source:CreateTestDataLib.java Github

copy

Full Screen

...78 * @param response servlet response79 * @throws ServletException if a servlet-specific error occurs80 * @throws IOException if an I/O error occurs81 */82 protected void processRequest(HttpServletRequest request, HttpServletResponse response)83 throws ServletException, IOException {84 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());85 IFactoryTestDataLibData tdldFactory = appContext.getBean(IFactoryTestDataLibData.class);86 ITestDataLibDataService tdldService = appContext.getBean(ITestDataLibDataService.class);87 IParameterService parameterService = appContext.getBean(IParameterService.class);88 JSONObject jsonResponse = new JSONObject();89 Answer ans = new Answer();90 AnswerItem ansItem = new AnswerItem();91 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);92 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));93 ans.setResultMessage(msg);94 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);95 String charset = request.getCharacterEncoding();96 response.setContentType("application/json");97 Map<String, String> fileData = new HashMap<String, String>();98 FileItem file = null;99 FileItemFactory factory = new DiskFileItemFactory();100 ServletFileUpload upload = new ServletFileUpload(factory);101 try {102 List<FileItem> fields = upload.parseRequest(request);103 Iterator<FileItem> it = fields.iterator();104 if (!it.hasNext()) {105 return;106 }107 while (it.hasNext()) {108 FileItem fileItem = it.next();109 boolean isFormField = fileItem.isFormField();110 if (isFormField) {111 fileData.put(fileItem.getFieldName(), ParameterParserUtil.parseStringParamAndDecode(fileItem.getString("UTF-8"), "", charset));112 } else {113 file = fileItem;114 }115 }116 } catch (FileUploadException e) {117 e.printStackTrace();118 }119 try {120 /**121 * Parsing and securing all required parameters.122 */123 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them124 String type = policy.sanitize(fileData.get("type"));125 String system = policy.sanitize(fileData.get("system"));126 String environment = policy.sanitize(fileData.get("environment"));127 String country = policy.sanitize(fileData.get("country"));128 String database = policy.sanitize(fileData.get("database"));129 String databaseUrl = policy.sanitize(fileData.get("databaseUrl"));130 String databaseCsv = policy.sanitize(fileData.get("databaseCsv"));131 // Parameter that needs to be secured --> We SECURE+DECODE them132 String name = fileData.get("name"); //this is mandatory133 String group = fileData.get("group");134 String description = fileData.get("libdescription");135 String service = fileData.get("service");136 // Parameter that we cannot secure as we need the html --> We DECODE them137 String script = fileData.get("script");138 String servicePath = fileData.get("servicepath");139 String method = fileData.get("method");140 String envelope = fileData.get("envelope");141 String csvUrl = fileData.get("csvUrl");142 String separator = fileData.get("separator");143 String test = fileData.get("subdataCheck");144 /**145 * Checking all constrains before calling the services.146 */147 // Prepare the final answer.148 MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);149 Answer finalAnswer = new Answer(msg1);150 if (StringUtil.isNullOrEmpty(name)) {151 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);152 msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Data Library")153 .replace("%OPERATION%", "Create")154 .replace("%REASON%", "Test data library name is missing! "));155 finalAnswer.setResultMessage(msg);156 } else {157 /**158 * All data seems cleans so we can call the services.159 */160 ITestDataLibService libService = appContext.getBean(ITestDataLibService.class);161 IFactoryTestDataLib factoryLibService = appContext.getBean(IFactoryTestDataLib.class);162 TestDataLib lib = factoryLibService.create(0, name, system, environment, country, group,163 type, database, script, databaseUrl, service, servicePath, method, envelope, databaseCsv, csvUrl, separator, description,164 request.getRemoteUser(), null, "", null, null, null, null, null);165 //Creates the entries and the subdata list166 ansItem = libService.create(lib);167 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ansItem);168 /**169 * Object created. Adding Log entry.170 */171 if (ansItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {172 ILogEventService logEventService = appContext.getBean(LogEventService.class);173 logEventService.createForPrivateCalls("/CreateTestDataLib", "CREATE", "Create TestDataLib : " + request.getParameter("name"), request);174 }175 List<TestDataLibData> tdldList = new ArrayList();176 TestDataLib dataLibWithUploadedFile = (TestDataLib) ansItem.getItem();177 if (file != null) {178 ans = libService.uploadFile(dataLibWithUploadedFile.getTestDataLibID(), file);179 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {180 dataLibWithUploadedFile.setCsvUrl(File.separator + dataLibWithUploadedFile.getTestDataLibID() + File.separator + file.getName());181 libService.update(dataLibWithUploadedFile);182 }183 }184 // Getting list of SubData from JSON Call185 if (fileData.get("subDataList") != null) {186 JSONArray objSubDataArray = new JSONArray(fileData.get("subDataList"));187 tdldList = getSubDataFromParameter(request, appContext, dataLibWithUploadedFile.getTestDataLibID(), objSubDataArray);188 }189 if (file != null && test.equals("1")) {190 String firstLine = "";191 String secondLine = "";192 try(BufferedReader reader = new BufferedReader(new FileReader(parameterService.getParameterStringByKey("cerberus_testdatalibCSV_path", "", null) + lib.getCsvUrl()));) {193 firstLine = reader.readLine();194 secondLine = reader.readLine();195 String[] firstLineSubData = (!dataLibWithUploadedFile.getSeparator().isEmpty()) ? firstLine.split(dataLibWithUploadedFile.getSeparator()) : firstLine.split(",");196 String[] secondLineSubData = (!dataLibWithUploadedFile.getSeparator().isEmpty()) ? secondLine.split(dataLibWithUploadedFile.getSeparator()) : secondLine.split(",");197 int i = 0;198 int y = 1;199 TestDataLibData firstLineLibData = tdldList.get(0);200 tdldList = new ArrayList();201 if (StringUtil.isNullOrEmpty(firstLineLibData.getColumnPosition())) {202 firstLineLibData.setColumnPosition("1");203 }204 if (StringUtil.isNullOrEmpty(firstLineLibData.getValue())) {205 firstLineLibData.setValue(secondLineSubData[0]);206 }207 if (StringUtil.isNullOrEmpty(firstLineLibData.getColumn())) {208 firstLineLibData.setColumn(firstLineSubData[0]);209 }210 tdldList.add(firstLineLibData);211 for (String item : firstLineSubData) {212 TestDataLibData tdld = tdldFactory.create(null, dataLibWithUploadedFile.getTestDataLibID(), item + "_" + y, secondLineSubData[i], item, null, Integer.toString(y), null);213 tdldList.add(tdld);214 i++;215 y++;216 }217 // Update the Database with the new list.218 } finally {219 try {220 file.getInputStream().close();221 } catch (Throwable ignore) {222 }223 }224 }225 ans = tdldService.compareListAndUpdateInsertDeleteElements(dataLibWithUploadedFile.getTestDataLibID(), tdldList);226 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);227 }228 /**229 * Formating and returning the json result.230 */231 //sets the message returned by the operations232 jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());233 jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());234 response.getWriter().print(jsonResponse);235 response.getWriter().flush();236 } catch (JSONException ex) {237 LOG.warn(ex);238 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());239 response.getWriter().flush();240 }241 }242 private List<TestDataLibData> getSubDataFromParameter(HttpServletRequest request, ApplicationContext appContext, int testDataLibId, JSONArray json) throws JSONException {243 List<TestDataLibData> tdldList = new ArrayList();244 IFactoryTestDataLibData tdldFactory = appContext.getBean(IFactoryTestDataLibData.class);245 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);246 String charset = request.getCharacterEncoding();247 for (int i = 0; i < json.length(); i++) {248 JSONObject objectJson = json.getJSONObject(i);249 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them250 boolean delete = objectJson.getBoolean("toDelete");251 Integer testDataLibDataId = objectJson.getInt("testDataLibDataID");252 // Parameter that needs to be secured --> We SECURE+DECODE them253 // NONE254 // Parameter that we cannot secure as we need the html --> We DECODE them255 String subdata = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("subData"), "", charset);256 String value = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("value"), "", charset);257 String column = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("column"), "", charset);258 String parsingAnswer = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("parsingAnswer"), "", charset);259 String columnPosition = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("columnPosition"), "", charset);260 String description = ParameterParserUtil.parseStringParamAndDecode(objectJson.getString("description"), "", charset);261 if (!delete) {262 TestDataLibData tdld = tdldFactory.create(testDataLibDataId, testDataLibId, subdata, value, column, parsingAnswer, columnPosition, description);263 tdldList.add(tdld);264 }265 }266 return tdldList;267 }268 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">269 /**270 * Handles the HTTP <code>GET</code> method.271 *272 * @param request servlet request273 * @param response servlet response274 * @throws ServletException if a servlet-specific error occurs275 * @throws IOException if an I/O error occurs276 */277 @Override278 protected void doGet(HttpServletRequest request, HttpServletResponse response)279 throws ServletException, IOException {280 processRequest(request, response);281 }282 /**283 * Handles the HTTP <code>POST</code> method.284 *285 * @param request servlet request286 * @param response servlet response287 * @throws ServletException if a servlet-specific error occurs288 * @throws IOException if an I/O error occurs289 */290 @Override291 protected void doPost(HttpServletRequest request, HttpServletResponse response)292 throws ServletException, IOException {293 processRequest(request, response);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";303 }// </editor-fold>304}...

Full Screen

Full Screen

Source:BulkRenameDataLib.java Github

copy

Full Screen

...50 * @param response servlet response51 * @throws ServletException if a servlet-specific error occurs52 * @throws IOException if an I/O error occurs53 */54 protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {55 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());56 ITestDataLibService tdls = appContext.getBean(ITestDataLibService.class);57 JSONObject jsonResponse = new JSONObject();58 response.setContentType("application/json");59 response.setCharacterEncoding("utf8");60 Answer ans = new Answer();61 List<Answer> ansList = new ArrayList<>();62 boolean error = true;63 try {64 /**65 * Parsing and securing all required parameters.66 */67 if ((request.getParameter("oldname") != null && !request.getParameter("oldname").isEmpty()) && (request.getParameter("newname") != null && !request.getParameter("newname").isEmpty())) {68 error = false;69 }70 } finally {71 if (error) {72 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_VALIDATIONS_ERROR);73 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "at least one of the two required parameter is empty"));74 ans.setResultMessage(msg);75 } else {76 String oldname = request.getParameter("oldname");77 String newname = request.getParameter("newname");78 ansList = tdls.bulkRename(oldname, newname);79 /**80 * Update operation finished with success, then the logging81 * entry must be added.82 */83 ILogEventService logEventService = appContext.getBean(LogEventService.class);84 logEventService.createForPrivateCalls("/BulkRenameDataLib", "UPDATE", "Rename TestDataLib : ['" + oldname + "'] - new name: '" + newname + "'", request);85 MessageEvent msg = new MessageEvent(MessageEventEnum.GENERIC_OK);86 ans.setResultMessage(msg);87 }88 try {89 //sets the message returned by the operations90 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());91 jsonResponse.put("message", ans.getResultMessage().getDescription());92 if (!error) {93 // Datalib answer management94 String DataLibAnswer = ansList.get(0).getResultMessage().getDescription();95 jsonResponse.put("DataLibAnswer", DataLibAnswer);96 // Testcase Country Properties answer management97 String TestCaseCountryPropertiesAnswer = ansList.get(1).getResultMessage().getDescription();98 jsonResponse.put("TestCasePropertiesAnswer", TestCaseCountryPropertiesAnswer);99 }100 response.getWriter().print(jsonResponse);101 response.getWriter().flush();102 } catch (JSONException ex) {103 LOG.warn(ex);104 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());105 response.getWriter().flush();106 }107 }108 }109 @Override110 protected void doGet(HttpServletRequest request, HttpServletResponse response)111 throws ServletException, IOException {112 processRequest(request, response);113 }114 @Override115 protected void doPost(HttpServletRequest request, HttpServletResponse response)116 throws ServletException, IOException {117 processRequest(request, response);118 }119 @Override120 public String getServletInfo() {121 return "Process a bulk rename for a Datalib name in the Datalib and TestCaseCountryProperties";122 }123}...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1package org.cerberus.servlet.crud.testdata;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 CreateTestDataLib extends HttpServlet {8 protected void processRequest(HttpServletRequest request, HttpServletResponse response)9 throws ServletException, IOException {10 response.setContentType("text/html;charset=UTF-8");11 try {12 String system = request.getParameter("system");13 String environment = request.getParameter("environment");14 String country = request.getParameter("country");15 String group = request.getParameter("group");16 String name = request.getParameter("name");17 String type = request.getParameter("type");18 String database = request.getParameter("database");19 String script = request.getParameter("script");20 String servicePath = request.getParameter("servicePath");21 String method = request.getParameter("method");22 String envelope = request.getParameter("envelope");23 String description = request.getParameter("description");24 String usrCreated = request.getParameter("usrCreated");25 String usrModif = request.getParameter("usrModif");26 String dateCreated = request.getParameter("dateCreated");27 String dateModif = request.getParameter("dateModif");28 String service = request.getParameter("service");29 String subdata = request.getParameter("subdata");30 String parsingAnswer = request.getParameter("parsingAnswer");31 String serviceRequest = request.getParameter("serviceRequest");32 String serviceResponse = request.getParameter("serviceResponse");33 String soapAction = request.getParameter("soapAction");34 String contentType = request.getParameter("contentType");35 String encoding = request.getParameter("encoding");36 String acceptEnv = request.getParameter("acceptEnv");37 String accept = request.getParameter("accept");38 String databaseUrl = request.getParameter("databaseUrl");39 String databaseScript = request.getParameter("databaseScript");40 String databaseCsv = request.getParameter("databaseCsv");41 String databaseJson = request.getParameter("databaseJson");42 String databaseXml = request.getParameter("database

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1package org.cerberus.servlet.crud.testdata;2import org.cerberus.servlet.crud.testdata.CreateTestDataLib;3import org.cerberus.servlet.crud.testdata.CreateTestDataLib;4import java.io.IOException;5import java.io.PrintWriter;6import java.util.logging.Level;7import java.util.logging.Logger;8import javax.servlet.ServletException;9import javax.servlet.http.HttpServlet;10import javax.servlet.http.HttpServletRequest;11import javax.servlet.http.HttpServletResponse;12public class CreateTestDataLib extends HttpServlet {13 private static final Logger LOG = Logger.getLogger(CreateTestDataLib.class.getName());14 protected void processRequest(HttpServletRequest request, HttpServletResponse response)15 throws ServletException, IOException {16 response.setContentType("text/html;charset=UTF-8");17 PrintWriter out = response.getWriter();18 try {19 } finally {20 out.close();21 }22 }23 protected void doGet(HttpServletRequest request, HttpServletResponse response)24 throws ServletException, IOException {25 processRequest(request, response);26 }27 protected void doPost(HttpServletRequest request, HttpServletResponse response)28 throws ServletException, IOException {29 processRequest(request, response);30 }31 public String getServletInfo() {32 return "Short description";33 }34}35package org.cerberus.servlet.crud.testdata;36import org.cerberus.servlet.crud.testdata.CreateTestDataLib;37import org.cerberus.servlet.crud.testdata.CreateTestDataLib;38import java.io.IOException;39import java.io.PrintWriter;40import java.util.logging.Level;41import java.util.logging.Logger;42import javax.servlet.ServletException;43import javax.servlet.http.HttpServlet;44import javax.servlet.http.HttpServletRequest;45import javax.servlet.http.HttpServletResponse;46public class CreateTestDataLib extends HttpServlet {47 private static final Logger LOG = Logger.getLogger(CreateTestDataLib.class.getName());48 protected void processRequest(HttpServletRequest request, HttpServletResponse response)49 throws ServletException, IOException {50 response.setContentType("text/html;charset=UTF-8");51 PrintWriter out = response.getWriter();52 try {53 } finally {54 out.close();55 }56 }57 protected void doGet(HttpServletRequest request, HttpServletResponse response)58 throws ServletException, IOException {59 processRequest(request, response);60 }61 protected void doPost(HttpServletRequest request, HttpServletResponse

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1package org.cerberus.servlet.crud.testdata;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 CreateTestDataLib extends HttpServlet {8 protected void processRequest(HttpServletRequest request, HttpServletResponse response)9 throws ServletException, IOException {10 response.setContentType("text/html;charset=UTF-8");11 try {12 } finally {13 response.sendRedirect("TestDataLib.jsp");14 }15 }16 protected void doGet(HttpServletRequest request, HttpServletResponse response)17 throws ServletException, IOException {18 processRequest(request, response);19 }20 protected void doPost(HttpServletRequest request, HttpServletResponse response)21 throws ServletException, IOException {22 processRequest(request, response);23 }24 public String getServletInfo() {25 return "Short description";26}

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1package org.cerberus.servlet.crud.testdata;2import java.io.IOException;3import java.io.PrintWriter;4import javax.servlet.ServletException;5import javax.servlet.annotation.WebServlet;6import javax.servlet.http.HttpServlet;7import javax.servlet.http.HttpServletRequest;8import javax.servlet.http.HttpServletResponse;9@WebServlet(name = "CreateTestDataLib", urlPatterns = {"/CreateTestDataLib"})10public class CreateTestDataLib extends HttpServlet {11 protected void processRequest(HttpServletRequest request, HttpServletResponse response)12 throws ServletException, IOException {13 response.setContentType("text/html;charset=UTF-8");14 try (PrintWriter out = response.getWriter()) {15 out.println("<!DOCTYPE html>");16 out.println("<html>");17 out.println("<head>");18 out.println("<title>Servlet CreateTestDataLib</title>"); 19 out.println("</head>");20 out.println("<body>");21 out.println("<h1>Servlet CreateTestDataLib at " + request.getContextPath() + "</h1>");22 out.println("</body>");23 out.println("</html>");24 }25 }26 protected void doGet(HttpServletRequest request, HttpServletResponse response)27 throws ServletException, IOException {28 processRequest(request, response);29 }30 protected void doPost(HttpServletRequest request, HttpServletResponse response)31 throws ServletException, IOException {32 processRequest(request, response);33 }34 public String getServletInfo() {35 return "Short description";

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in CreateTestDataLib

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful