/**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {

      ApplicationContext appContext =
          WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
      ceaService = appContext.getBean(ICountryEnvironmentApplicationService.class);
      factoryCea = appContext.getBean(IFactoryCountryEnvironmentApplication.class);
      PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);

      String id = policy.sanitize(request.getParameter("id"));
      String system = id.split("System&#61;")[1].split("&amp;")[0];
      String country = id.split("Country&#61;")[1].split("&amp;")[0];
      String env = id.split("Env&#61;")[1].split("&amp;")[0];
      String app = id.split("App&#61;")[1].split("&amp;")[0];

      response.setContentType("text/html");
      ceaService.delete(factoryCea.create(system, country, env, app, null, null, null, null));
    } catch (CerberusException ex) {
      Logger.getLogger(DeleteCountryEnvironmentParameter.class.getName())
          .log(Level.SEVERE, null, ex);
    }
  }
예제 #2
0
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    ApplicationContext appContext =
        WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    campaignService = appContext.getBean(ICampaignService.class);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);

    String pk = policy.sanitize(request.getParameter("id"));
    String name = policy.sanitize(request.getParameter("columnName"));
    String value = policy.sanitize(request.getParameter("value"));

    response.setContentType("text/html");
    try {
      CampaignParameter campaignParameter =
          campaignService.findCampaignParameterByKey(Integer.parseInt(pk));
      if (name != null && "Value".equals(name.trim())) {
        campaignParameter.setValue(value);
      } else {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NOT_IMPLEMEMTED));
      }
      campaignService.updateCampaignParameter(campaignParameter);
      response.getWriter().print(value);
    } catch (CerberusException ex) {
      response.getWriter().print(ex.getMessageError().getDescription());
    }
  }
예제 #3
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  final void processRequest(final HttpServletRequest request, final HttpServletResponse response)
      throws ServletException, IOException, CerberusException {
    response.setContentType("text/html;charset=UTF-8");
    final PrintWriter out = response.getWriter();
    final PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);

    try {
      final String type = policy.sanitize(request.getParameter("Type"));
      final String name = policy.sanitize(request.getParameter("Name"));
      // CTE - on utilise la méthode utilitaire pour encoder le xml
      final String envelope = request.getParameter("Envelope");
      final String envelopeBDD = HtmlUtils.htmlEscape(envelope);
      final String description = policy.sanitize(request.getParameter("Description"));
      final String servicePath = policy.sanitize(request.getParameter("ServicePath"));
      final String parsingAnswer = policy.sanitize(request.getParameter("ParsingAnswer"));
      final String method = policy.sanitize(request.getParameter("Method"));

      final ApplicationContext appContext =
          WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
      final ISoapLibraryService soapLibraryService = appContext.getBean(ISoapLibraryService.class);
      final IFactorySoapLibrary factorySoapLibrary = appContext.getBean(IFactorySoapLibrary.class);

      final SoapLibrary soapLib =
          factorySoapLibrary.create(
              type, name, envelopeBDD, description, servicePath, parsingAnswer, method);
      soapLibraryService.createSoapLibrary(soapLib);

      /** Adding Log entry. */
      ILogEventService logEventService = appContext.getBean(LogEventService.class);
      IFactoryLogEvent factoryLogEvent = appContext.getBean(FactoryLogEvent.class);
      try {
        logEventService.insertLogEvent(
            factoryLogEvent.create(
                0,
                0,
                request.getUserPrincipal().getName(),
                null,
                "/CreateSoapLibrary",
                "CREATE",
                "Create SoapLibrary : " + name,
                "",
                ""));
      } catch (CerberusException ex) {
        org.apache.log4j.Logger.getLogger(CreateSoapLibrary.class.getName())
            .log(org.apache.log4j.Level.ERROR, null, ex);
      }

      response.sendRedirect("SoapLibrary.jsp");
    } finally {
      out.close();
    }
  }
예제 #4
0
  @Override
  protected void doGet(
      HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
      throws ServletException, IOException {
    ApplicationContext appContext =
        WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    ITestCaseService testService = appContext.getBean(ITestCaseService.class);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);

    String test = policy.sanitize(httpServletRequest.getParameter("test"));
    JSONArray array = new JSONArray();
    JSONObject jsonObject = new JSONObject();
    for (TCase testcase : testService.findTestCaseByTest(test)) {
      array.put(testcase.getTestCase());
    }
    try {
      jsonObject.put("testcasesList", array);

      httpServletResponse.setContentType("application/json");
      httpServletResponse.getWriter().print(jsonObject.toString());
    } catch (JSONException exception) {
      MyLogger.log(GetTestCaseList.class.getName(), Level.WARN, exception.toString());
    }
  }
예제 #5
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException, CerberusException, JSONException {
    JSONObject jsonResponse = new JSONObject();
    Answer ans = new Answer();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    ans.setResultMessage(msg);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);

    response.setContentType("application/json");

    /** Parsing and securing all required parameters. */
    String robot = policy.sanitize(request.getParameter("robot"));
    String host = policy.sanitize(request.getParameter("host"));
    String port = policy.sanitize(request.getParameter("port"));
    String platform = policy.sanitize(request.getParameter("platform"));
    String browser = policy.sanitize(request.getParameter("browser"));
    String version = policy.sanitize(request.getParameter("version"));
    String active = policy.sanitize(request.getParameter("active"));
    String description = policy.sanitize(request.getParameter("description"));
    String userAgent = policy.sanitize(request.getParameter("useragent"));
    Integer robotid = 0;
    boolean robotid_error = true;
    try {
      if (request.getParameter("robotid") != null && !request.getParameter("robotid").equals("")) {
        robotid = Integer.valueOf(policy.sanitize(request.getParameter("robotid")));
        robotid_error = false;
      }
    } catch (Exception ex) {
      robotid_error = true;
    }

    /** Checking all constrains before calling the services. */
    if (StringUtil.isNullOrEmpty(robot)) {
      msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
      msg.setDescription(
          msg.getDescription()
              .replace("%ITEM%", "Robot")
              .replace("%OPERATION%", "Update")
              .replace("%REASON%", "Robot name is missing."));
      ans.setResultMessage(msg);
    } else if (robotid_error) {
      msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
      msg.setDescription(
          msg.getDescription()
              .replace("%ITEM%", "Robot")
              .replace("%OPERATION%", "Update")
              .replace(
                  "%REASON%",
                  "Could not manage to convert robotid to an integer value or robotid is missing."));
      ans.setResultMessage(msg);
    } else {
      /** All data seems cleans so we can call the services. */
      ApplicationContext appContext =
          WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
      IRobotService robotService = appContext.getBean(IRobotService.class);

      AnswerItem resp = robotService.readByKeyTech(robotid);
      if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()))) {
        /** Object could not be found. We stop here and report the error. */
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(
            msg.getDescription()
                .replace("%ITEM%", "Robot")
                .replace("%OPERATION%", "Update")
                .replace("%REASON%", "Robot does not exist."));
        ans.setResultMessage(msg);

      } else {
        /**
         * The service was able to perform the query and confirm the object exist, then we can
         * update it.
         */
        Robot robotData = (Robot) resp.getItem();
        robotData.setRobot(robot);
        robotData.setHost(host);
        robotData.setPort(port);
        robotData.setPlatform(platform);
        robotData.setBrowser(browser);
        robotData.setVersion(version);
        robotData.setActive(active);
        robotData.setDescription(description);
        robotData.setUserAgent(userAgent);
        ans = robotService.update(robotData);

        if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
          /** Update was succesfull. Adding Log entry. */
          ILogEventService logEventService = appContext.getBean(LogEventService.class);
          logEventService.createPrivateCalls(
              "/UpdateRobot",
              "UPDATE",
              "Updated Robot : ['" + robotid + "'|'" + robot + "']",
              request);
        }
      }
    }

    /** Formating and returning the json result. */
    jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
    jsonResponse.put("message", ans.getResultMessage().getDescription());

    response.getWriter().print(jsonResponse);
    response.getWriter().flush();
  }
예제 #6
0
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    ApplicationContext appContext =
        WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    testBatteryService = appContext.getBean(ITestBatteryService.class);
    factoryTestBatteryContent = appContext.getBean(IFactoryTestBatteryContent.class);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);

    String jsonResponse = "-1";
    String testbattery = policy.sanitize(request.getParameter("TestBattery"));
    String testBatteryName;

    String[] testcasesselected = request.getParameterValues("testcaseselected");

    if (testcasesselected == null) {
      response.setStatus(404);
      jsonResponse = "Please select at least one testcase !";
    } else {
      try {
        testBatteryName =
            testBatteryService.findTestBatteryByKey(Integer.parseInt(testbattery)).getTestbattery();
      } catch (CerberusException ex) {
        MyLogger.log(AddTestBatteryContent.class.getName(), Level.DEBUG, ex.getMessage());
        testBatteryName = null;
      }

      if (testBatteryName != null) {
        String test;
        String testcase;

        // response.setContentType("text/html");
        for (String testcaseselect : testcasesselected) {
          test =
              policy.sanitize(
                  URLDecoder.decode(
                      testcaseselect.split("Test=")[1].split("&TestCase=")[0], "UTF-8"));
          testcase =
              policy.sanitize(URLDecoder.decode(testcaseselect.split("&TestCase=")[1], "UTF-8"));
          try {

            testBatteryService.createTestBatteryContent(
                factoryTestBatteryContent.create(null, test, testcase, testBatteryName));
            List<TestBatteryContent> batteryContent =
                testBatteryService.findTestBatteryContentsByCriteria(
                    null, testBatteryName, test, testcase);

            if (batteryContent != null && batteryContent.size() == 1) {
              String newTestBatteryContentId =
                  String.valueOf(
                      testBatteryService
                          .findTestBatteryContentsByCriteria(null, testBatteryName, test, testcase)
                          .get(0)
                          .getTestbatterycontentID());
              jsonResponse = newTestBatteryContentId;
            }
          } catch (CerberusException ex) {
            MyLogger.log(AddTestBatteryContent.class.getName(), Level.DEBUG, ex.getMessage());
            jsonResponse = "-1";
          }
        }
      }
    }
    response.getWriter().append(jsonResponse).close();
  }