Ejemplo n.º 1
0
  @Override
  protected void onRequest(RequestWrapper<WebSession> req) throws IOException {
    req.setRequestEncoding(IO.UTF_8);

    String projectId = req.get("projectId");
    String entityId = req.get("entityId");
    String text = req.get("text");
    String name = Str.cutRight(req.get("name"), 33);
    if (Str.isBlank(name)) name = null;
    String email = Str.cutRight(req.get("email"), 33);
    if (Str.isBlank(email)) email = null;

    log.info("Comment from the internets");
    log.info("    projectId: " + projectId);
    log.info("    entityId: " + entityId);
    log.info("    name: " + name);
    log.info("    email: " + email);
    log.info("    text: " + text);
    log.info("  Request-Data:");
    log.info(Servlet.toString(req.getHttpRequest(), "        "));

    String message;
    try {
      SpamChecker.check(req);
      message = postComment(projectId, entityId, text, name, email);
    } catch (Throwable ex) {
      log.error("Posting comment failed.", "\n" + Servlet.toString(req.getHttpRequest(), "  "), ex);
      message =
          "<h2>Failure</h2><p>Posting your comment failed: <strong>"
              + Str.getRootCauseMessage(ex)
              + "</strong></p><p>We are sorry, please try again later.</p>";
    }

    String returnUrl = req.get("returnUrl");
    if (returnUrl == null) returnUrl = "http://kunagi.org/message.html?#{message}";
    returnUrl = returnUrl.replace("{message}", Str.encodeUrlParameter(message));

    req.sendRedirect(returnUrl);
  }
Ejemplo n.º 2
0
  @Override
  protected void onRequest(RequestWrapper<WebSession> req) throws IOException {

    String projectId = req.get("projectId");
    String subject = req.get("subject");
    String text = req.get("text");
    String additionalInfo = req.get("additionalInfo");
    String externalTrackerId = req.get("externalTrackerId");
    String name = Str.cutRight(req.get("name"), 33);
    if (Str.isBlank(name)) name = null;
    String email = Str.cutRight(req.get("email"), 66);
    if (Str.isBlank(email)) email = null;
    boolean publish = Str.isTrue(req.get("publish"));
    boolean wiki = Str.isTrue(req.get("wiki"));

    log.info("Message from the internets");
    log.info("    projectId: " + projectId);
    log.info("    name: " + name);
    log.info("    email: " + email);
    log.info("    publish: " + publish);
    log.info("    wiki: " + wiki);
    log.info("    subject: " + subject);
    log.info("    text: " + text);
    log.info("    additionalInfo: " + additionalInfo);
    log.info("    externalTrackerId: " + externalTrackerId);
    log.info("  Request-Data:");
    log.info(Servlet.toString(req.getHttpRequest(), "        "));

    String message;
    try {
      SpamChecker.check(text, name, email, req);
      message =
          submitIssue(
              projectId,
              subject,
              text,
              additionalInfo,
              externalTrackerId,
              name,
              email,
              wiki,
              publish,
              req.getRemoteHost());
    } catch (Throwable ex) {
      log.error(
          "Submitting issue failed.", "\n" + Servlet.toString(req.getHttpRequest(), "  "), ex);
      message =
          "<h2>Failure</h2><p>Submitting your feedback failed: <strong>"
              + Utl.getRootCauseMessage(ex)
              + "</strong></p><p>We are sorry, please try again later.</p>";
    }

    String returnUrl = req.get("returnUrl");
    if (returnUrl != null) {
      returnUrl = returnUrl.replace("{message}", Str.encodeUrlParameter(message));
      req.sendRedirect(returnUrl);
      return;
    }

    req.setContentType("text/html");
    PrintWriter out = req.getWriter();
    out.print(message);
  }