public void error(Throwable exception) {

    if (++mCount == mMobileThreshold) {

      mCount = 0;
      SMS sms = new SMS();
      sms.setNumber(String.valueOf(mMobile));

      String msg = exception.getMessage();
      if (msg == null) {
        msg = "NullPointerException";
      } else if (msg.length() > 150) {
        msg = msg.substring(0, msg.length());
      }

      sms.setMessage("ERROR: " + msg);
      try {
        mSMSGateway.sendSMS(sms);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    if (mEmail != null) {
      MailEnvelop envelop = new MailEnvelop(mEmail, "WebSite : ERROR", JVM.toString(exception));
      mMailBox.drop(envelop);
    }
  }
  public void setAppService(AppService appService) {
    mMobile = appService.getAppConfig().getMandatoryProperty("app.monitor.mobile.number");
    mMobileThreshold =
        appService.getAppConfig().getMandatoryIntProperty("app.monitor.mobile.threshold");

    mEmail = appService.getAppConfig().getMandatoryProperty("app.monitor.email");

    mMailBox = appService.getMailBox();
    mSMSGateway = appService.getSMSGateway();

    mErrorSMS = new SMS();
    mErrorSMS.setNumber(String.valueOf(mMobileThreshold));
  }
Exemple #3
0
  public void perform() {

    String userName = mHttpServletRequest.getParameter("userName");
    String password = mHttpServletRequest.getParameter("password");
    String rpassword = mHttpServletRequest.getParameter("rpassword");
    String rId = mHttpServletRequest.getParameter("roleId");

    long roleId = Long.parseLong(rId);

    mResponseWriter.append(RESPONSE_HTML_START);

    try {

      if (!password.equals(rpassword)) {
        throw new RuntimeException("Passwords do not match");
      }

      NewUser user = mAccountStore.createTempNewUser(userName, password, roleId);

      UserType userType = UserType.getUserType(userName);

      String url = mHttpServletRequest.getHeader("referer");

      if (url == null || !url.contains("/account/")) {
        url = user.getPrimaryRole().getHome();
      }

      if (userType == UserType.EMAIL) {

        UserData userData = new UserData(user, ExceptionHandler.getHttpsBaseURL());
        String message =
            TemplateEngine.getText(
                "nandhi/app/security/template/ConfirmRegistration.html", userData);

        Email email = new Email();
        email.setTos(user.getName());
        email.setSubject("Confirm Registration");
        email.setMessage(message);
        email.setContentType("text/html");
        email.setReference("user-reg: " + user.getAccessToken());
        email.setSentOn(SystemDate.getUTCCalendar());
        email.setState(MessageState.NEW.getState());

        mAppService.getAppEngine().saveResource(email);

        mResponseWriter
            .append("window.top.postEmailRegistration(")
            .append("\"")
            .append(url)
            .append("\");");
      } else {

        String text =
            FileSystem.readClassPathResource(
                "dewbag/retail/template/sms/UserMobileRegistrationSMS.txt");
        text = text.replace("#{code}", user.getAccessToken());

        SMS sms = new SMS();
        sms.setNumber(user.getName());
        sms.setMessage(text);
        sms.setReference("so:" + user.getId());
        sms.setState(MessageState.DELIVERED.getState());
        mAppService.getAppEngine().saveResource(sms);

        mResponseWriter
            .append("window.top.postMobileRegistration(")
            .append("\"")
            .append(user.getName())
            .append("\");");
      }

    } catch (Throwable ex) {
      mResponseWriter
          .append("window.top.postRegistrationFailure(\"")
          .append(ex.getMessage())
          .append("\");");
      ex.printStackTrace();
    } finally {

      mResponseWriter.append(RESPONSE_HTML_END).flush();
    }
  }