/*------------------------------------------------------------------------------------------------*
     *  A P P L I C A T I O N   W I L L   L A U N C H                     [ N O T I F I C A T I O N ]
     *------------------------------------------------------------------------------------------------*/
    public void appWillLaunch(NSNotification notification) {
      LOG.info("[-NOTIFY-] appWillLaunch");

      NSNotificationCenter.defaultCenter()
          .removeObserver(
              this,
              com.webobjects.appserver.WOApplication.ApplicationWillFinishLaunchingNotification,
              null);

      NSArray<EOModel> modelArray = ERXModelGroup.defaultGroup().models();
      for (EOModel model : modelArray) {
        LOG.info("[OBSERVER] modelName={} ({})", model.name(), model.adaptorName());
      }

      if (ERXProperties.booleanForKey("pachy.exitBeforeLaunching")) {
        LOG.info("[APPLICATION] EXIT BEFORE LAUNCHING [pachy.exitBeforeLaunching == true]");
        System.exit(0);
        /* ######################################### MIGHT STOP HERE (pachy.exitBeforeLaunching) #### */
      }

      if (ERXProperties.booleanForKeyWithDefault("pachy.optionEnableTimers", false)) {
        startTenMinuteTimerTask();
        startDayChangeTimerTask();
      }
    }
  public Application() {
    super();

    PachySanity.adjustEnvironment();

    if (isFirstTime()) {

      PachySanity.showEnvironment();

    } else {

      if (ERXProperties.booleanForKeyWithDefault("pachy.CreateEnvironment", false)) {
        PachySanity.createEnvironment();
      }

      if (ERXProperties.booleanForKeyWithDefault("pachy.ShowEnvironment", true)) {
        PachySanity.showEnvironment();
      }

      PachySanity.testEnvironment();

      if (ERXProperties.booleanForKey("pachy.exitAfterInitialize")) {
        LOG.info("[APPLICATION] EXIT AFTER INITIALIZING [pachy.exitAfterInitialize == true]");
        System.exit(0);
        /* ############################################# MIGHT STOP HERE (pachy.exitAfterInitialize) #### */
      }
    }

    er.extensions.ERXExtensions.setAdaptorLogging(
        ERXProperties.booleanForKeyWithDefault("pachy.optionEnableAdaptorLog", false));

    /*------------------------------------------------------------------------------------------------*
     *  ... add the metadata database to the objectStores (why does EOModel not do this?)
     *------------------------------------------------------------------------------------------------*/
    try {
      CXObjectStoreCoordinator.getDefaultCoordinator()
          .addObjectStore(
              "org.pachyderm.assetdb", ERXProperties.stringForKey("dbConnectURLGLOBAL"));
      LOG.info("org.pachyderm.assetdb registered.");
    } catch (Exception x) {
      LOG.error("org.pachyderm.assetdb not registered.", x);
    }

    /*------------------------------------------------------------------------------------------------*
     *  add the English and French locales to the locale array ...
     *------------------------------------------------------------------------------------------------*/
    locales = new NSMutableArray<Locale>();
    locales.addObject(Locale.ENGLISH);
    locales.addObject(Locale.FRENCH);

    /*------------------------------------------------------------------------------------------------*
     *  loading this class, causes "UTRuntimeProvider" to scan for UTI definitions which can take
     *  a long time (~10 seconds on a good day).  Rather than have the first unfortunate user incur
     *  that penalty unpredictably, we get it over with now, before anyone logs in ...
     *------------------------------------------------------------------------------------------------*/
    UTType.loadThisClassNow();
  }
Exemple #3
0
  /**
   * <span class="en"> This method is used to initialize ERJavaMail from System properties. Later,
   * we will implement a way to initialize those properties everytime the propertis are changed. The
   * observer will call this method whenever appropriate. </span>
   *
   * <p><span class="ja"> このメソッドは ERJavaMail をシステム・プロパティより初期化するためにあります。
   * 後でプロパティが変更される度にこのメソッドが実行される処理を追加実装します。 </span>
   */
  public void initializeFrameworkFromSystemProperties() {
    // Centralize mails ?
    boolean centralize = ERXProperties.booleanForKey("er.javamail.centralize");
    setCentralize(centralize);
    log.debug("er.javamail.centralize: " + centralize);

    String adminEmail = System.getProperty("er.javamail.adminEmail");
    if (isValidEmail(adminEmail)) {
      setAdminEmail(adminEmail);
      log.debug("er.javamail.adminEmail: " + _adminEmail);
    } else if (centralize) {
      throw new IllegalArgumentException(
          "When 'er.javamail.centralize' is true (default),"
              + " all outgoing mails will get sent to 'er.javamail.adminEmail'"
              + " instead of the normal TO addresses, but you did not provide a valid email for that property.");
    }

    // JavaMail Debug Enabled ?
    boolean debug = ERXProperties.booleanForKey("er.javamail.debugEnabled");
    setDebugEnabled(debug);
    log.debug("er.javamail.debugEnabled: " + debug);

    // Number of messages that the sender queue can hold at a time
    int queueSize = ERXProperties.intForKey("er.javamail.senderQueue.size");
    if (queueSize >= 1) setSenderQueueSize(queueSize);
    log.debug("er.javamail.senderQueue.size: " + queueSize);

    // Time to wait when sender if overflowed
    int milliswait = ERXProperties.intForKey("er.javamail.milliSecondsWaitIfSenderOverflowed");
    if (milliswait > 1000) setMilliSecondsWaitIfSenderOverflowed(milliswait);
    log.debug("er.javamail.milliSecondsWaitIfSenderOverflowed: " + milliswait);

    // Smtp host
    setupSmtpHostSafely();

    setDefaultSession(newSession());

    if (defaultSession() == null) log.warn("Unable to create default mail session!");

    // Default X-Mailer header
    setDefaultXMailerHeader(System.getProperty("er.javamail.XMailerHeader"));
    log.debug("er.javamail.XMailHeader: " + defaultXMailerHeader());
  }
    /*------------------------------------------------------------------------------------------------*
     *  A L L   N O T I F I C A T I O N S                                 [ N O T I F I C A T I O N ]
     *------------------------------------------------------------------------------------------------*/
    public void allNotifications(NSNotification notification) {
      if (!ERXProperties.booleanForKey("pachy.logAllNotifications")) return;
      if (notification.name().equalsIgnoreCase("EOEditingContextDidCreate")) {
        EOEditingContext eo = (EOEditingContext) notification.object();
        EOObjectStore eos = eo.rootObjectStore();
        LOG.info("[-NOTIFY-] {} rootCoordinator={}", notification.name(), eos);
        NSArray<EOCooperatingObjectStore> storeArray =
            ((EOObjectStoreCoordinator) eos).cooperatingObjectStores();
        if (storeArray.count() > 0) {
          for (EOCooperatingObjectStore store : storeArray) {
            LOG.info("[OBSERVER] rootCoordinator contains={}", store);
          }
        } else LOG.info("[OBSERVER] rootCoordinator contains no cooperatingObjectStores");

      } else {
        LOG.info(
            "[-NOTIFY-] "
                + notification.name()
                + ((notification.name().equalsIgnoreCase("EOEntityLoadedNotification")
                        || (notification.name().equalsIgnoreCase("EOModelAddedNotification")))
                    ? ""
                    : " [" + notification.object() + "]"));
      }
    }
Exemple #5
0
  protected void setupSmtpProperties(Properties properties, String contextString) {
    String contextSuffix = contextString == null ? "" : ("." + contextString);

    // Smtp host
    String smtpProtocol = smtpProtocolForContext(contextString);

    String smtpHost =
        ERXProperties.stringForKeyWithDefault(
            "er.javamail.smtpHost" + contextSuffix,
            ERXProperties.stringForKey("er.javamail.smtpHost"));
    if ((smtpHost == null) || (smtpHost.length() == 0)) {
      // Try to fail back to default java config
      smtpHost = ERXProperties.stringForKey("mail." + smtpProtocol + ".host");

      if ((smtpHost == null) || (smtpHost.length() == 0)) {
        // use the standard WO host
        smtpHost = ERXProperties.stringForKey("WOSMTPHost");
        if ((smtpHost == null) || (smtpHost.length() == 0)) {
          throw new RuntimeException(
              "ERJavaMail: You must specify a SMTP host for outgoing mail with the property 'er.javamail.smtpHost'");
        }
        // ... and then maybe actually do what the docs say this method is supposed to do
        properties.setProperty("mail." + smtpProtocol + ".host", smtpHost);
        properties.setProperty("er.javamail.smtpHost", smtpHost);
      } else {
        properties.setProperty("er.javamail.smtpHost", smtpHost);
      }
    } else {
      properties.setProperty("mail." + smtpProtocol + ".host", smtpHost);
    }
    log.debug("er.javamail.smtpHost: " + smtpHost);

    String port =
        ERXProperties.stringForKeyWithDefault(
            "er.javamail.smtpPort" + contextSuffix,
            ERXProperties.stringForKey("er.javamail.smtpPort"));
    if (port != null && port.length() > 0) {
      properties.setProperty("mail." + smtpProtocol + ".port", port);
      log.debug("ERJavaMail will use smtp port: " + port);
    }

    boolean smtpAuth =
        ERXProperties.booleanForKeyWithDefault(
            "er.javamail.smtpAuth" + contextSuffix,
            ERXProperties.booleanForKey("er.javamail.smtpAuth"));
    log.debug("ERJavaMail will use authenticated SMTP connections.");
    if (smtpAuth) {
      properties.setProperty("mail." + smtpProtocol + ".auth", String.valueOf(smtpAuth));
      String user =
          ERXProperties.stringForKeyWithDefault(
              "er.javamail.smtpUser" + contextSuffix,
              ERXProperties.stringForKey("er.javamail.smtpUser"));
      if (user == null || user.length() == 0) {
        throw new RuntimeException(
            "You specified er.javamail.smtpAuth=true, but you didn't specify an er.javamail.smtpUser to use as the login name.");
      }
      properties.setProperty("mail." + smtpProtocol + ".user", user);
      String password =
          ERXProperties.stringForKeyWithDefault(
              "er.javamail.smtpPassword" + contextSuffix,
              ERXProperties.stringForKey("er.javamail.smtpPassword"));
      if (password == null || password.length() == 0) {
        log.warn(
            "You specified er.javamail.smtpAuth=true, but you didn't set er.javamail.smtpPassword for the "
                + user
                + " mail user.");
      }
      if (password != null) {
        properties.setProperty("mail." + smtpProtocol + ".password", password);
      }
    }
    if ("smtps".equals(smtpProtocol)) {
      properties.setProperty("mail.smtps.socketFactory.fallback", "false");
    }
  }