How to use processRequest method of org.cerberus.servlet.integration.GetNotification class

Best Cerberus-source code snippet using org.cerberus.servlet.integration.GetNotification.processRequest

Source:GetNotification.java Github

copy

Full Screen

...53 * @throws ServletException if a servlet-specific error occurs54 * @throws IOException if an I/O error occurs55 * @throws org.cerberus.exception.CerberusException56 */57 protected void processRequest(HttpServletRequest request, HttpServletResponse response)58 throws ServletException, IOException, CerberusException, JSONException {59 JSONObject jsonResponse = new JSONObject();60 Answer answer = new Answer();61 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);62 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));63 answer.setResultMessage(msg);64 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);65 response.setContentType("application/json");66 /**67 * Parsing and securing all required parameters.68 */69 String system = policy.sanitize(request.getParameter("system"));70 String country = policy.sanitize(request.getParameter("country"));71 String env = policy.sanitize(request.getParameter("environment"));72 String build = policy.sanitize(request.getParameter("build"));73 String revision = policy.sanitize(request.getParameter("revision"));74 String chain = policy.sanitize(request.getParameter("chain"));75 // Init Answer with potencial error from Parsing parameter.76// AnswerItem answer = new AnswerItem(msg);77 String eMailContent = "";78 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());79 IEmailGenerationService emailService = appContext.getBean(IEmailGenerationService.class);80 if (request.getParameter("system") == null) {81 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);82 msg.setDescription(msg.getDescription().replace("%ITEM%", "GetNotification")83 .replace("%OPERATION%", "Get")84 .replace("%REASON%", "System name is missing!"));85 answer.setResultMessage(msg);86 } else if (request.getParameter("event") == null) {87 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);88 msg.setDescription(msg.getDescription().replace("%ITEM%", "GetNotification")89 .replace("%OPERATION%", "Get")90 .replace("%REASON%", "event is missing!"));91 answer.setResultMessage(msg);92 } else if (request.getParameter("event").equals("newbuildrevision")) {93 try {94 // ID parameter is specified so we return the unique record of object.95 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);96 msg.setDescription(msg.getDescription().replace("%ITEM%", "GetNotification")97 .replace("%OPERATION%", "Get"));98 answer.setResultMessage(msg);99 Email email = emailService.generateRevisionChangeEmail(system, country, env, build, revision);100 jsonResponse.put("notificationTo", email.getTo());101 jsonResponse.put("notificationCC", email.getCc());102 jsonResponse.put("notificationSubject", email.getSubject());103 jsonResponse.put("notificationBody", email.getBody());104 } catch (Exception ex) {105 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);106 msg.setDescription(msg.getDescription().replace("%ITEM%", "GetNotification")107 .replace("%OPERATION%", "Get")108 .replace("%REASON%", ex.toString()));109 answer.setResultMessage(msg);110 }111 } else if (request.getParameter("event").equals("disableenvironment")) {112 try {113 // ID parameter is specified so we return the unique record of object.114 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);115 msg.setDescription(msg.getDescription().replace("%ITEM%", "GetNotification")116 .replace("%OPERATION%", "Get"));117 answer.setResultMessage(msg);118 Email email = emailService.generateDisableEnvEmail(system, country, env);119 jsonResponse.put("notificationTo", email.getTo());120 jsonResponse.put("notificationCC", email.getCc());121 jsonResponse.put("notificationSubject", email.getSubject());122 jsonResponse.put("notificationBody", email.getBody());123 } catch (Exception ex) {124 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);125 msg.setDescription(msg.getDescription().replace("%ITEM%", "GetNotification")126 .replace("%OPERATION%", "Get")127 .replace("%REASON%", ex.toString()));128 answer.setResultMessage(msg);129 }130 } else if (request.getParameter("event").equals("newchain")) {131 try {132 // ID parameter is specified so we return the unique record of object.133 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);134 msg.setDescription(msg.getDescription().replace("%ITEM%", "GetNotification")135 .replace("%OPERATION%", "Get"));136 answer.setResultMessage(msg);137 Email email = emailService.generateNewChainEmail(system, country, env, chain);138 jsonResponse.put("notificationTo", email.getTo());139 jsonResponse.put("notificationCC", email.getCc());140 jsonResponse.put("notificationSubject", email.getSubject());141 jsonResponse.put("notificationBody", email.getBody());142 } catch (Exception ex) {143 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);144 msg.setDescription(msg.getDescription().replace("%ITEM%", "GetNotification")145 .replace("%OPERATION%", "Get")146 .replace("%REASON%", ex.toString()));147 answer.setResultMessage(msg);148 }149 } else {150 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);151 msg.setDescription(msg.getDescription().replace("%ITEM%", "GetNotification")152 .replace("%OPERATION%", "Get")153 .replace("%REASON%", "Unknown invalidityReason!"));154 answer.setResultMessage(msg);155 }156 /**157 * Formating and returning the json result.158 */159 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());160 jsonResponse.put("message", answer.getResultMessage().getDescription());161 response.getWriter().print(jsonResponse);162 response.getWriter().flush();163 }164 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">165 /**166 * Handles the HTTP <code>GET</code> method.167 *168 * @param request servlet request169 * @param response servlet response170 * @throws ServletException if a servlet-specific error occurs171 * @throws IOException if an I/O error occurs172 */173 @Override174 protected void doGet(HttpServletRequest request, HttpServletResponse response)175 throws ServletException, IOException {176 try {177 processRequest(request, response);178 } catch (CerberusException ex) {179 LOG.warn(ex);180 } catch (JSONException ex) {181 LOG.warn(ex);182 }183 }184 /**185 * Handles the HTTP <code>POST</code> method.186 *187 * @param request servlet request188 * @param response servlet response189 * @throws ServletException if a servlet-specific error occurs190 * @throws IOException if an I/O error occurs191 */192 @Override193 protected void doPost(HttpServletRequest request, HttpServletResponse response)194 throws ServletException, IOException {195 try {196 processRequest(request, response);197 } catch (CerberusException ex) {198 LOG.warn(ex);199 } catch (JSONException ex) {200 LOG.warn(ex);201 }202 }203 /**204 * Returns a short description of the servlet.205 *206 * @return a String containing servlet description207 */208 @Override209 public String getServletInfo() {210 return "Short description";...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1String result = new org.cerberus.servlet.integration.GetNotification().processRequest(url);2System.out.println(result);3String result = new org.cerberus.servlet.integration.GetExecutionQueue().processRequest(url);4System.out.println(result);5String result = new org.cerberus.servlet.integration.GetExecutionQueue().processRequest(url);6System.out.println(result);7String result = new org.cerberus.servlet.integration.GetExecutionQueue().processRequest(url);8System.out.println(result);9String result = new org.cerberus.servlet.integration.GetExecutionQueue().processRequest(url);10System.out.println(result);11String result = new org.cerberus.servlet.integration.GetExecutionQueue().processRequest(url);12System.out.println(result);

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1result = org.cerberus.servlet.integration.GetNotification.processRequest(request);2response = result;3result = org.cerberus.servlet.integration.GetNotification.processRequest(request);4response = result;5result = org.cerberus.servlet.integration.GetNotification.processRequest(request);6response = result;7result = org.cerberus.servlet.integration.GetNotification.processRequest(request);8response = result;9result = org.cerberus.servlet.integration.GetNotification.processRequest(request);10response = result;11result = org.cerberus.servlet.integration.GetNotification.processRequest(request);12response = result;13result = org.cerberus.servlet.integration.GetNotification.processRequest(request);14response = result;15result = org.cerberus.servlet.integration.GetNotification.processRequest(request);16response = result;17result = org.cerberus.servlet.integration.GetNotification.processRequest(request);18response = result;

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1String data = "application=MyApplication&country=FR&environment=QA&tag=MyTag";2String result = processRequest(url, data);3String data = "application=MyApplication&country=FR&environment=QA&tag=MyTag";4String result = processRequest(url, data);5String data = "application=MyApplication&country=FR&environment=QA&tag=MyTag";6String result = processRequest(url, data);7String data = "application=MyApplication&country=FR&environment=QA&tag=MyTag";8String result = processRequest(url, data);9String data = "application=MyApplication&country=FR&environment=QA&tag=MyTag";10String result = processRequest(url, data);

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import com.fasterxml.jackson.databind.ObjectMapper;2import org.apache.logging.log4j.LogManager;3import org.apache.logging.log4j.Logger;4import org.cerberus.servlet.integration.GetNotification;5import org.cerberus.servlet.integration.GetNotificationResponse;6import javax.servlet.ServletException;7import javax.servlet.http.HttpServlet;8import javax.servlet.http.HttpServletRequest;9import javax.servlet.http.HttpServletResponse;10import java.io.IOException;11import java.io.PrintWriter;12import java.util.Arrays;13import java.util.Collections;14import java.util.List;15public class SendNotification extends HttpServlet {16 private static final Logger LOG = LogManager.getLogger(SendNotification.class);17 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {18 try {19 String url = req.getParameter("url");20 if (url == null) {21 resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);22 return;23 }24 GetNotificationResponse notificationResponse = new GetNotification().processRequest(req);25 if (notificationResponse != null) {26 String json = new ObjectMapper().writeValueAsString(notificationResponse);27 LOG.debug(json);28 List<String> urls = Arrays.asList(url.split(","));29 for (String u : urls) {30 new GetNotification().processResponse(u, json);31 }32 }33 } catch (Exception e) {34 LOG.error("Error sending notification", e);35 }36 }37}

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.integration.GetNotification;2import org.cerberus.servlet.integration.GetNotificationResult;3import org.cerberus.servlet.integration.Notification;4import java.util.ArrayList;5import java.util.List;6import com.fasterxml.jackson.core.JsonProcessingException;7import com.fasterxml.jackson.databind.ObjectMapper;8import java.io.IOException;9import java.io.PrintWriter;10import javax.servlet.ServletException;11import javax.servlet.annotation.WebServlet;12import javax.servlet.http.HttpServlet;13import javax.servlet.http.HttpServletRequest;14import javax.servlet.http.HttpServletResponse;15@WebServlet(name = "GetNotification", urlPatterns = {"/GetNotification"})16public class GetNotification extends HttpServlet {17 private static final long serialVersionUID = 1L;18 protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {19 response.setContentType("application/json;charset=UTF-8");20 try (PrintWriter out = response.getWriter()) {21 String tag = request.getParameter("tag");22 GetNotificationResult result = GetNotification.processRequest(tag);23 if (result == null) {24 out.println("[]");25 } else {26 List<Notification> notifications = result.getNotifications();27 if (notifications == null) {28 out.println("[]");29 } else {30 List<Notification> notificationsFiltered = new ArrayList<Notification>();31 for (Notification notification : notifications) {32 if (notification.getNotificationDate() != null) {33 notificationsFiltered.add(notification);34 }35 }36 ObjectMapper mapper = new ObjectMapper();37 out.println(mapper.writeValueAsString(notificationsFiltered));38 }39 }40 }41 }42 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {43 processRequest(request, response);44 }45 protected void doPost(HttpServletRequest request,

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 GetNotification

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful