How to use processRequest method of org.cerberus.servlet.crud.transversaltables.CreateLabel class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.transversaltables.CreateLabel.processRequest

Source:CreateLabel.java Github

copy

Full Screen

...64 * @throws IOException if an I/O error occurs65 * @throws org.cerberus.exception.CerberusException66 * @throws org.json.JSONException67 */68 protected void processRequest(HttpServletRequest request, HttpServletResponse response)69 throws ServletException, IOException, CerberusException, JSONException {70 JSONObject jsonResponse = new JSONObject();71 Answer ans = new Answer();72 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);73 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));74 ans.setResultMessage(msg);75 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);76 String charset = request.getCharacterEncoding();77 response.setContentType("application/json");78 // Calling Servlet Transversal Util.79 ServletUtil.servletStart(request);80 81 /**82 * Parsing and securing all required parameters.83 */84 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them85 String id = policy.sanitize(request.getParameter("id"));86 String system = policy.sanitize(request.getParameter("system"));87 String type = policy.sanitize(request.getParameter("type"));88 String longDesc = policy.sanitize(request.getParameter("longdesc"));89 String reqtype = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("reqtype"), "", charset);90 String reqstatus = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("reqstatus"), "", charset);91 String reqcriticity = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("reqcriticity"), "", charset);92 // Parameter that needs to be secured --> We SECURE+DECODE them93 String label = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("label"), "", charset);94 String color = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("color"), "", charset);95 String parentLabel = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("parentLabel"), "", charset);96 String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);97 String usr = request.getUserPrincipal().getName();98 99 /**100 * Checking all constrains before calling the services.101 */102 if (StringUtil.isNullOrEmpty(label)) {103 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);104 msg.setDescription(msg.getDescription().replace("%ITEM%", "Label")105 .replace("%OPERATION%", "Create")106 .replace("%REASON%", "Label is missing!"));107 ans.setResultMessage(msg);108 } else {109 /**110 * All data seems cleans so we can call the services.111 */112 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());113 ILabelService labelService = appContext.getBean(ILabelService.class);114 IFactoryLabel factoryLabel = appContext.getBean(IFactoryLabel.class);115 Timestamp creationDate = new Timestamp(new Date().getTime());116 Label labelData = factoryLabel.create(0, system, label, type, color, parentLabel, reqtype, reqstatus, reqcriticity, description, longDesc, usr,creationDate, usr, creationDate);117 ans = labelService.create(labelData);118 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {119 /**120 * Object created. Adding Log entry.121 */122 ILogEventService logEventService = appContext.getBean(LogEventService.class);123 logEventService.createForPrivateCalls("/CreateLabel", "CREATE", "Create Label : ['" + label + "'] for System : ["+system+"]", request);124 }125 }126 /**127 * Formating and returning the json result.128 */129 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());130 jsonResponse.put("message", ans.getResultMessage().getDescription());131 response.getWriter().print(jsonResponse);132 response.getWriter().flush();133 }134 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">135 /**136 * Handles the HTTP <code>GET</code> method.137 *138 * @param request servlet request139 * @param response servlet response140 * @throws ServletException if a servlet-specific error occurs141 * @throws IOException if an I/O error occurs142 */143 @Override144 protected void doGet(HttpServletRequest request, HttpServletResponse response)145 throws ServletException, IOException {146 try {147 processRequest(request, response);148 } catch (CerberusException ex) {149 LOG.warn(ex);150 } catch (JSONException ex) {151 LOG.warn(ex);152 }153 }154 /**155 * Handles the HTTP <code>POST</code> method.156 *157 * @param request servlet request158 * @param response servlet response159 * @throws ServletException if a servlet-specific error occurs160 * @throws IOException if an I/O error occurs161 */162 @Override163 protected void doPost(HttpServletRequest request, HttpServletResponse response)164 throws ServletException, IOException {165 try {166 processRequest(request, response);167 } catch (CerberusException ex) {168 LOG.warn(ex);169 } catch (JSONException ex) {170 LOG.warn(ex);171 }172 }173 /**174 * Returns a short description of the servlet.175 *176 * @return a String containing servlet description177 */178 @Override179 public String getServletInfo() {180 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 CreateLabel

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful