Package service

Examples of service.BusinessService


  }

  private void performAction(HttpServletRequest request,
      HttpServletResponse response) throws ServletException, IOException {
    String action = request.getParameter("action");
    BusinessService service = new DefaultBusinessServiceImpl();
    response.setContentType("text/plain");
    if ("send".equals(action)) {
      String credentials = request.getParameter("credentials");
      StringTokenizer tokenizer = new StringTokenizer(credentials, ":");
      if (tokenizer.countTokens() == 2) {
        String user = tokenizer.nextToken();
        String pass = tokenizer.nextToken();
        if (config.getInitParameter("sysuser").equals(user) && config.getInitParameter("syspass").equals(pass)) {
          String messageKey = request.getParameter("messageKey");
          String fromMail = request.getParameter("senderId");
          if (fromMail == null) fromMail="empty.server";
          String toMail = request.getParameter("recepientId");
          if (toMail == null) toMail="empty.server";
          String question =  request.getParameter("question");
          String answer = request.getParameter("answer");
          String versionS = request.getParameter("version");
          if (versionS == null) versionS="0";
          float version = Util.convertToFloat(versionS, 0.0F);
          version = version < 0.4 ? 0.0F : version;
          int TTL = Util.convertToInteger(request.getParameter("TTL"), -1);
          if (TTL == -1) {TTL = 120;} // 5 days expiration by default
          Timestamp timeToLive = null;
          Calendar today = GregorianCalendar.getInstance();
          today.add(Calendar.HOUR_OF_DAY, TTL);
          timeToLive = new Timestamp(today.getTime().getTime());
          String messageId = service.send(messageKey, fromMail, toMail, question, answer, timeToLive, version);
          response.getWriter().write(messageId);
          return;
        }
      }
      throw new ServletException("Access Denied");
    }
    else if ("getQuestion".equals(action)) {
      String messageId = request.getParameter("messageId");
      request.getSession().setAttribute("messageId", messageId);
     
      if (service.isMessageExpired(messageId)) {
        response.sendRedirect("jsp/ExpiredMessage.jsp");
        return;
      }
     
      request.getSession().setAttribute("messageId", messageId);
      request.setAttribute("messageQuestion", service.getQuestion(messageId));
      request.getSession().setAttribute("answerTries", 0);
      request.getRequestDispatcher("jsp/MessageQuestion.jsp").forward(request, response);
    }
    else if ("receive".equals(action)) {
      String userAnswer = request.getParameter("userAnswer");
      String messageId = (String) request.getSession().getAttribute("messageId"); // (String) to access it in each .jsp page
      boolean validAnswer = service.isValidAnswer(userAnswer, messageId,false);

      if (validAnswer) {
        request.setAttribute("messageKey", service.receive(userAnswer, messageId, false));
        //request.setAttribute("DecodeURIComponent", service.isver1(messageId));
        request.getRequestDispatcher("jsp/MailContent.jsp").forward(request, response);
      } else {
        String nonCanonicalUserAnswer = null;
        // Try for the non-canonized answer. This can be the case of the
        // message encrypted with the older non-canonized version.
        if (!validAnswer) {
          nonCanonicalUserAnswer = request.getParameter("userAnswer1");
          validAnswer = service.isValidAnswer(nonCanonicalUserAnswer, messageId, true);
        }

        if (validAnswer) {
          request.setAttribute("messageKey", service.receive(nonCanonicalUserAnswer, messageId, true));
          //request.setAttribute("DecodeURIComponent", service.isver1(messageId));
          request.getRequestDispatcher("jsp/MailContent.jsp").forward(request, response);
        } else {
          request.setAttribute("messageQuestion", service.getQuestion(messageId));
          int ansTries = (Integer) request.getSession().getAttribute("answerTries");
          request.getSession().setAttribute("answerTries", ++ansTries);
          request.getRequestDispatcher("jsp/MessageQuestion.jsp").forward(request, response);
        }
      } 
    }
    else if ("requestMessageRevival".equals(action)) {
      String messageId = (String) request.getSession().getAttribute("messageId");

      if (service.isMessageExpired(messageId)) {
       
        String requestorName = request.getParameter("requestorName");
        String requestfromMailR = request.getParameter("fromMailR");
        String requestorEmail = request.getParameter("requestorEmail");       
        String requestReason = request.getParameter("requestReason");         
        service.createRevivalRequest(messageId, requestorName, requestfromMailR, requestorEmail, requestReason);
        response.sendRedirect("html/RevivalRequestSuccess.html");
      }

    } else {
      throw new UnsupportedOperationException("Operation not supported");
View Full Code Here

TOP

Related Classes of service.BusinessService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.