Exemplo n.º 1
0
public class SentMail {

  // ****************************************************************
  // ** Variables
  // ****************************************************************
  private static String To;
  private static String From;
  private static String BearFrom;
  private static String SMTPHost;
  private static Properties props = USFEnv.getProperties();

  /** Sends the message to the respective incharge */
  public static void SendMessage(String msgsubject, String msgText, String msgTo) {
    try {
      From = props.getProperty("FROM");
      // To = props.getProperty("TO");
      SMTPHost = props.getProperty("SMTPHOST");
      Properties mailprops = new Properties();
      mailprops.put("mail.smtp.host", SMTPHost);

      // create some properties and get the default Session
      Session session = Session.getDefaultInstance(mailprops, null);

      // create a message
      Message msg = new MimeMessage(session);

      // set the from
      InternetAddress from = new InternetAddress(From);
      msg.setFrom(from);
      InternetAddress[] address = InternetAddress.parse(msgTo);
      msg.setRecipients(Message.RecipientType.TO, address);
      msg.setSubject(msgsubject);
      msg.setContent(msgText, "text/plain");
      Transport.send(msg);
    } // end try
    catch (MessagingException mex) {
      USFEnv.getLog().writeCrit("Message not sent", null, null);
    } catch (Exception ex) {
      USFEnv.getLog().writeCrit("Message not sent", null, null);
    }
  } // end SendMessage

  /** Sends Emails to Customers who have not submitted their Bears */
  public static void BearEmailSendMessage(String msgsubject, String msgText, String msgTo) {
    try {
      BearFrom = props.getProperty("BEARFROM");
      // To = props.getProperty("TO");
      SMTPHost = props.getProperty("SMTPHOST");
      Properties mailprops = new Properties();
      mailprops.put("mail.smtp.host", SMTPHost);

      // create some properties and get the default Session
      Session session = Session.getDefaultInstance(mailprops, null);

      // create a message
      Message msg = new MimeMessage(session);

      // set the from
      InternetAddress from = new InternetAddress(BearFrom);
      msg.setFrom(from);
      InternetAddress[] address = InternetAddress.parse(msgTo);
      msg.setRecipients(Message.RecipientType.TO, address);
      msg.setSubject(msgsubject);
      msg.setContent(msgText, "text/plain");
      Transport.send(msg);
    } // end try
    catch (MessagingException mex) {
      USFEnv.getLog().writeCrit("Message not sent", null, null);
    } catch (Exception ex) {
      USFEnv.getLog().writeCrit("Message not sent", null, null);
    }
  } // end BearEmailSendMessage
} // end class
public class RhccInvviewServlet extends RhccBaseServlet {

  RhccInvviewRemote invviewEJBean = null;
  RhccInvgenRemote invgenEJBean = null;
  Properties props = USFEnv.getProperties();

  public void init(ServletConfig config) throws ServletException {
    super.init(config);

    try {
      RhccInvviewHome invviewhome = (RhccInvviewHome) USFEnv.ic.lookup(RHCCINVVIEW_EJBEAN);
      invviewEJBean = invviewhome.create();
      RhccInvgenHome invgenhome = (RhccInvgenHome) USFEnv.ic.lookup(RHCCINVGEN_EJBEAN);
      invgenEJBean = invgenhome.create();
    } catch (NamingException e) {
      USFEnv.getLog().writeDebug("RhccInvviewServlet: Inside Naming Exception", this, null);
    } catch (CreateException e) {
      USFEnv.getLog().writeDebug("RhccInvviewServlet: Inside Create Exception", this, null);
    } catch (RemoteException e) {
      USFEnv.getLog().writeDebug("RhccInvviewServlet: Inside Remote Exception", this, null);
    }
  }

  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    USFEnv.getLog().writeWarn("RhccInvviewServlet: Inside RhccInvviewServlet", this, null);
    doPost(request, response);
  }

  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      String jsppath = "rhccinvoice";
      String year = "";
      String spin = "";
      String frn = "";
      String invid = "";
      String invno = "";
      String spinnm = "";
      String frame = "";
      String user = "";
      Vector vector = new Vector();
      HttpSession session = request.getSession(false);

      if (session == null) {
        jsppath = "login";
        USFEnv.getLog().writeCrit("RhccInvviewServlet: Inside Session is null", this, null);
        USFEnv.getLog()
            .writeWarn("RhccInvviewServlet: Inside frame session calling JSP Login", this, null);
        includeJSP(request, response, jsppath, "Login");
      } else {

        jsppath = "rhccinvoice";
        frame = request.getParameter("frame");
        user = (String) session.getValue("cuid");
        USFEnv.getLog()
            .writeDebug("RhccInvviewServlet: Inside doPost Login CUID is: " + user, this, null);
        USFEnv.getLog()
            .writeWarn("RhccInvviewServlet: Inside InvreconServlet Frame is:" + frame, this, null);

        if (frame.equals("iview_frn")) {
          boolean discountview_flag = false;
          if ((request.getParameter("idiscountview") != null)
              && (request.getParameter("idiscountview").equals("TRUE"))) {
            year = request.getParameter("iyear");
            session.putValue("Iyear", year);
            discountview_flag = true;
          }

          if ((discountview_flag) || (session.getValue("Iyear") != null)) {

            if ((request.getParameter("ifrn")) != null) {
              frn = request.getParameter("ifrn");
              USFEnv.getLog().writeDebug("RhccInvviewServlet: FRN Value :" + frn, this, null);
              if (!(discountview_flag)) {
                year = (String) session.getValue("Iyear");
              }
              Vector frninvnos = new Vector();
              Vector invnolist = new Vector();
              Vector invpending = new Vector();
              boolean frn_flag = false;
              String frnerrmsg = "";

              try {
                invviewEJBean.connect();
                USFEnv.getLog()
                    .writeWarn(
                        "RhccInvviewServlet: Inside frame rhcciview_frn connected to RhccInvviewBean",
                        this,
                        null);

                if (discountview_flag) {
                  frn_flag = true;
                } else {
                  frn_flag = invviewEJBean.validateFRN(frn, year);
                  USFEnv.getLog()
                      .writeWarn(
                          "RhccInvviewServlet:Inside frame rhcciview_frn data from validateFRN"
                              + frn_flag,
                          this,
                          null);
                }

                if (frn_flag) {
                  frninvnos = invviewEJBean.getFrninvnos(year, frn);
                  USFEnv.getLog().writeWarn("ouside the block", this, null);

                  invviewEJBean.release();
                  USFEnv.getLog()
                      .writeWarn(
                          "RhccInvviewServlet: Inside frame Rhcciview_frn released RhccInvviewBean",
                          this,
                          null);
                } else {
                  USFEnv.getLog()
                      .writeWarn(
                          "RhccInvviewServlet: Inside frame iview_frn Inside the else block",
                          this,
                          null);

                  frnerrmsg = invviewEJBean.setErrmsg();

                  invviewEJBean.release();
                  USFEnv.getLog()
                      .writeWarn(
                          "RhccInvviewServlet: Inside frame iview_frn released RhccInvviewBean"
                              + frnerrmsg,
                          this,
                          null);
                  invgenEJBean.connect();
                  USFEnv.getLog()
                      .writeWarn(
                          "RhccInvviewServlet: Inside frame iview_frn connected to RhccInvgenBean"
                              + invnolist,
                          this,
                          null);
                  invnolist = invgenEJBean.getRhccInvnos(year);
                  USFEnv.getLog().writeWarn("outside of this " + invnolist, this, null);

                  invgenEJBean.release();
                  USFEnv.getLog()
                      .writeWarn(
                          "RhccInvviewServlet: Inside frame iview_frn released RhccInvgenBean",
                          this,
                          null);
                }
                USFEnv.getLog()
                    .writeWarn(
                        "RhccInvviewServlet: Inside frame iview_frn Inside the else block--2--",
                        this,
                        null);

                if (discountview_flag) {
                  USFEnv.getLog()
                      .writeWarn(
                          "RhccInvviewServlet: Inside -3---" + discountview_flag, this, null);
                  USFEnv.getLog().writeWarn("RhccInvviewServlet: Inside -3---" + frn, this, null);
                  USFEnv.getLog().writeWarn("RhccInvviewServlet: Inside -3---" + year, this, null);
                  session.putValue("Ifrn", frn);
                  invgenEJBean.connect();
                  USFEnv.getLog()
                      .writeWarn("RhccInvviewServlet: Inside frame----88 " + frn, this, null);
                  invpending = invgenEJBean.getRhccInvpending(null, year, frn);
                  USFEnv.getLog()
                      .writeWarn(
                          "RhccInvviewServlet: Inside frame iview_frn connected to InvgenBean",
                          this,
                          null);
                  invgenEJBean.release();
                  USFEnv.getLog()
                      .writeWarn(
                          "RhccInvviewServlet: Inside frame iview_frn released InvgenBean",
                          this,
                          null);
                }

              } catch (RemoteException e) {

                USFEnv.getLog().writeCrit("I m here", this, null);

                USFEnv.getLog()
                    .writeCrit(
                        "RhccInvviewServlet: Inside Remote Exception of getFrninvnos ", this, null);
              }

              if (frn_flag) {
                USFEnv.getLog()
                    .writeWarn(
                        "RhccInvviewServlet: Inside frame iview_frn calling JSP RhccIInvviewfrn"
                            + frn_flag,
                        this,
                        null);

                request.setAttribute("frn", frn);
                request.setAttribute("frninv", frninvnos);
                USFEnv.getLog()
                    .writeWarn(
                        "RhccInvviewServlet: Inside frame iview_frn calling JSP RhccIInvviewfrn",
                        this,
                        null);

                if (discountview_flag) {
                  if ((request.getParameter("invrejn") != null)
                      && (request.getParameter("invrejn").equals("true")))
                    request.setAttribute("invrejn", "true");

                  request.setAttribute("frnpend", invpending);
                  includeJSP(request, response, jsppath, "RhccIDiscountview");
                } else {
                  USFEnv.getLog()
                      .writeWarn(
                          "RhccInvviewServlet:  Inside frame iview_frn calling JSP RhccIInvviewfrn inside else",
                          this,
                          null);

                  includeJSP(request, response, jsppath, "RhccIInvviewfrn");
                }
              } else {
                request.setAttribute("invnolist", invnolist);
                request.setAttribute("invviewmsg", frnerrmsg);
                USFEnv.getLog()
                    .writeWarn(
                        "RhccInvviewServlet: Inside frame iview_frn calling JSP IMenu", this, null);
                includeJSP(request, response, jsppath, "RhccIMenu");
              }
            }
          }
        }

        if (frame.equals("iview_file")) {
          boolean discountview_flag = false;
          frn = request.getParameter("ifrn");
          invid = request.getParameter("iview_no");
          USFEnv.getLog()
              .writeWarn(
                  "RhccInvviewServlet: Inside frame iview_file released InvviewBean" + frn,
                  this,
                  null);
          USFEnv.getLog()
              .writeWarn(
                  "RhccInvviewServlet: Inside frame iview_file released InvviewBean" + invid,
                  this,
                  null);

          Vector invfil = new Vector();

          if ((request.getParameter("idiscountview") != null)
              && (request.getParameter("idiscountview").equals("TRUE"))) {
            year = request.getParameter("iyear");
            session.putValue("Iyear", year);
            discountview_flag = true;
          }

          if (invid != null) {
            if (session.getValue("Iyear") != null) {
              year = (String) session.getValue("Iyear");

              try {
                invviewEJBean.connect();
                USFEnv.getLog()
                    .writeWarn(
                        "RhccInvviewServlet: Inside frame iview_file connected to RhccInvviewBean",
                        this,
                        null);
                invno = invviewEJBean.getInvno(invid);
                spinnm = invviewEJBean.getSPINname(invid);
                invfil = invviewEJBean.getFiledetails(frn, invid, year);
                invviewEJBean.release();
                USFEnv.getLog()
                    .writeWarn(
                        "RhccInvviewServlet: Inside frame iview_file released RhccInvviewBean",
                        this,
                        null);
              } catch (RemoteException e) {
                USFEnv.getLog()
                    .writeCrit("RhccInvviewServlet: Inside Remote Exception for Inv ", this, null);
              }
            }
          }

          if (discountview_flag) {
            request.setAttribute("vdsflag", "TRUE");
          }
          if ((request.getParameter("invrejn") != null)
              && (request.getParameter("invrejn").equals("true")))
            request.setAttribute("invrejn", "true");

          request.setAttribute("frn", frn);
          request.setAttribute("invno", invno);
          request.setAttribute("spinnm", spinnm);
          request.setAttribute("invfil", invfil);
          USFEnv.getLog()
              .writeWarn(
                  "RhccInvviewServlet: Inside frame iview_file calling JSP RhccIInvviewfil",
                  this,
                  null);
          includeJSP(request, response, jsppath, "RhccIInvviewfil");
        }
      }
    } catch (Exception e) {
      if (invviewEJBean != null) {
        // calling bean release method
        try {
          invviewEJBean.release();
        } catch (Exception ex) {
          USFEnv.getLog().writeCrit(" Exception in calling release() method ", this, e);
        }
      }
      USFEnv.getLog().writeCrit("RhccInvviewServlet: Inside Exception" + e, this, null);
      USFEnv.getLog()
          .writeWarn("RhccInvviewServlet: Inside Exception calling JSP Login", this, null);
      includeJSP(request, response, "login", "Login");
    }
  }
}