Java Code Examples for org.apache.commons.configuration2.HierarchicalConfiguration#getLong()

The following examples show how to use org.apache.commons.configuration2.HierarchicalConfiguration#getLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LMTPServer.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Override
public void doConfigure(HierarchicalConfiguration<ImmutableNode> configuration) throws ConfigurationException {
    super.doConfigure(configuration);
    if (isEnabled()) {

        // get the message size limit from the conf file and multiply
        // by 1024, to put it in bytes
        maxMessageSize = configuration.getLong("maxmessagesize", maxMessageSize) * 1024;
        if (maxMessageSize > 0) {
            LOGGER.info("The maximum allowed message size is {} bytes.", maxMessageSize);
        } else {
            LOGGER.info("No maximum message size is enforced for this server.");
        }

        // get the lmtpGreeting
        lmtpGreeting = configuration.getString("lmtpGreeting", null);

    }
}
 
Example 2
Source File: FetchScheduler.java    From james-project with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() throws Exception {
    enabled = conf.getBoolean("[@enabled]", false);
    if (enabled) {
        int numThreads = conf.getInt("threads", 5);
        String jmxName = conf.getString("jmxName", "fetchmail");
        String jmxPath = "org.apache.james:type=component,name=" + jmxName + ",sub-type=threadpool";

        /*
  The scheduler service that is used to trigger fetch tasks.
 */
        ScheduledExecutorService scheduler = new JMXEnabledScheduledThreadPoolExecutor(numThreads, jmxPath, "scheduler");
        queue = queueFactory.createQueue(MailQueueFactory.SPOOL);

        List<HierarchicalConfiguration<ImmutableNode>> fetchConfs = conf.configurationsAt("fetch");
        for (HierarchicalConfiguration<ImmutableNode> fetchConf : fetchConfs) {
            // read configuration
            Long interval = fetchConf.getLong("interval");

            FetchMail fetcher = new FetchMail();

            fetcher.setDNSService(dns);
            fetcher.setUsersRepository(urepos);
            fetcher.setMailQueue(queue);
            fetcher.setDomainList(domainList);

            fetcher.configure(fetchConf);

            // initialize scheduling
            schedulers.add(scheduler.scheduleWithFixedDelay(fetcher, 0, interval, TimeUnit.MILLISECONDS));
        }

        LOGGER.info("FetchMail Started");
    } else {
        LOGGER.info("FetchMail Disabled");
    }
}
 
Example 3
Source File: LdapRepositoryConfiguration.java    From james-project with Apache License 2.0 4 votes vote down vote up
public static LdapRepositoryConfiguration from(HierarchicalConfiguration<ImmutableNode> configuration) throws ConfigurationException {
    String ldapHost = configuration.getString("[@ldapHost]", "");
    String principal = configuration.getString("[@principal]", "");
    String credentials = configuration.getString("[@credentials]", "");
    String userBase = configuration.getString("[@userBase]");
    String userIdAttribute = configuration.getString("[@userIdAttribute]");
    String userObjectClass = configuration.getString("[@userObjectClass]");
    // Default is to use connection pooling
    boolean useConnectionPool = configuration.getBoolean("[@useConnectionPool]", USE_CONNECTION_POOL);
    int connectionTimeout = configuration.getInt("[@connectionTimeout]", NO_CONNECTION_TIMEOUT);
    int readTimeout = configuration.getInt("[@readTimeout]", NO_READ_TIME_OUT);
    // Default maximum retries is 1, which allows an alternate connection to
    // be found in a multi-homed environment
    int maxRetries = configuration.getInt("[@maxRetries]", 1);
    boolean supportsVirtualHosting = configuration.getBoolean(SUPPORTS_VIRTUAL_HOSTING, !ENABLE_VIRTUAL_HOSTING);
    // Default retry start interval is 0 second
    long retryStartInterval = configuration.getLong("[@retryStartInterval]", 0);
    // Default maximum retry interval is 60 seconds
    long retryMaxInterval = configuration.getLong("[@retryMaxInterval]", 60);
    int scale = configuration.getInt("[@retryIntervalScale]", 1000); // seconds

    HierarchicalConfiguration<ImmutableNode> restrictionConfig = null;
    // Check if we have a restriction we can use
    // See JAMES-1204
    if (configuration.containsKey("restriction[@memberAttribute]")) {
        restrictionConfig = configuration.configurationAt("restriction");
    }
    ReadOnlyLDAPGroupRestriction restriction = new ReadOnlyLDAPGroupRestriction(restrictionConfig);

    //see if there is a filter argument
    String filter = configuration.getString("[@filter]");

    Optional<String> administratorId = Optional.ofNullable(configuration.getString("[@administratorId]"));

    return new LdapRepositoryConfiguration(
        ldapHost,
        principal,
        credentials,
        userBase,
        userIdAttribute,
        userObjectClass,
        useConnectionPool,
        connectionTimeout,
        readTimeout,
        maxRetries,
        supportsVirtualHosting,
        retryStartInterval,
        retryMaxInterval,
        scale,
        restriction,
        filter,
        administratorId);
}
 
Example 4
Source File: SMTPServer.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public void doConfigure(HierarchicalConfiguration<ImmutableNode> configuration) throws ConfigurationException {
    super.doConfigure(configuration);
    if (isEnabled()) {
        String authRequiredString = configuration.getString("authRequired", "false").trim().toLowerCase(Locale.US);
        if (authRequiredString.equals("true")) {
            authRequired = AUTH_REQUIRED;
        } else if (authRequiredString.equals("announce")) {
            authRequired = AUTH_ANNOUNCE;
        } else {
            authRequired = AUTH_DISABLED;
        }
        if (authRequired != AUTH_DISABLED) {
            LOGGER.info("This SMTP server requires authentication.");
        } else {
            LOGGER.info("This SMTP server does not require authentication.");
        }

        authorizedAddresses = configuration.getString("authorizedAddresses", null);
        if (authRequired == AUTH_DISABLED && authorizedAddresses == null) {
            /*
             * if SMTP AUTH is not required then we will use
             * authorizedAddresses to determine whether or not to relay
             * e-mail. Therefore if SMTP AUTH is not required, we will not
             * relay e-mail unless the sending IP address is authorized.
             * 
             * Since this is a change in behavior for James v2, create a
             * default authorizedAddresses network of 0.0.0.0/0, which
             * matches all possible addresses, thus preserving the current
             * behavior.
             * 
             * James v3 should require the <authorizedAddresses> element.
             */
            authorizedAddresses = "0.0.0.0/0.0.0.0";
        }

      
        if (authorizedNetworks != null) {
            LOGGER.info("Authorized addresses: {}", authorizedNetworks);
        }

        // get the message size limit from the conf file and multiply
        // by 1024, to put it in bytes
        maxMessageSize = configuration.getLong("maxmessagesize", maxMessageSize) * 1024;
        if (maxMessageSize > 0) {
            LOGGER.info("The maximum allowed message size is {} bytes.", maxMessageSize);
        } else {
            LOGGER.info("No maximum message size is enforced for this server.");
        }

        heloEhloEnforcement = configuration.getBoolean("heloEhloEnforcement", true);

        if (authRequiredString.equals("true")) {
            authRequired = AUTH_REQUIRED;
        }

        // get the smtpGreeting
        smtpGreeting = configuration.getString("smtpGreeting", null);

        addressBracketsEnforcement = configuration.getBoolean("addressBracketsEnforcement", true);

        verifyIdentity = configuration.getBoolean("verifyIdentity", true);

    }
}