org.apache.commons.configuration.ConversionException Java Examples

The following examples show how to use org.apache.commons.configuration.ConversionException. 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: RevealParam.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateConfigsImpl(int fileVersion) {
    // When in ZAP "core"
    if (fileVersion == NO_CONFIG_VERSION) {
        try {
            final String oldKey = "view.reveal";
            boolean oldValue = getConfig().getBoolean(oldKey, false);
            getConfig().clearProperty(oldKey);

            getConfig().setProperty(PARAM_REVEAL_STATE, Boolean.valueOf(oldValue));
        } catch (ConversionException e) {
            logger.error(
                    "Error while updating the reveal state from old version ["
                            + fileVersion
                            + "]",
                    e);
        }
    }
}
 
Example #2
Source File: BrowserViewParam.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
@Override
protected void parse() {
    updateConfigFile();

    try {
        warnOnJavaFXInitError =
                getConfig()
                        .getBoolean(
                                PARAM_WARN_ON_JAVA_FX_INIT_ERROR,
                                PARAM_WARN_ON_JAVA_FX_INIT_ERROR_DEFAULT_VALUE);
    } catch (ConversionException e) {
        LOGGER.error(
                "Error while loading the '" + PARAM_WARN_ON_JAVA_FX_INIT_ERROR + "' option: ",
                e);
        warnOnJavaFXInitError = PARAM_WARN_ON_JAVA_FX_INIT_ERROR_DEFAULT_VALUE;
    }
}
 
Example #3
Source File: SeleniumOptions.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Reads the given {@code systemProperty}, falling back to the option with the given {@code
 * optionKey} if not set.
 *
 * <p>The system property if set, is saved in the file with the given {@code optionKey}. If not
 * set, it's restored with the option if available.
 *
 * @param systemProperty the name of the system property
 * @param optionKey the key of the option used as fallback
 * @return the value of the system property, or if not set, the option read from the
 *     configuration file. If neither the system property nor the option are set it returns an
 *     empty {@code String}.
 */
private String readSystemPropertyWithOptionFallback(String systemProperty, String optionKey) {
    String value = System.getProperty(systemProperty);
    if (value == null) {
        try {
            value = getConfig().getString(optionKey, "");
            if (!value.isEmpty()) {
                System.setProperty(systemProperty, value);
            }
        } catch (ConversionException e) {
            LOGGER.error("Failed to read '" + optionKey + "'", e);
            value = "";
        }
    } else {
        getConfig().setProperty(optionKey, value);
    }
    return value;
}
 
Example #4
Source File: CommandInjectionPlugin.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
/** Initialize the plugin according to the overall environment configuration */
@Override
public void init() {
    try {
        timeSleepSeconds = this.getConfig().getInt(RULE_SLEEP_TIME, DEFAULT_TIME_SLEEP_SEC);
    } catch (ConversionException e) {
        log.debug(
                "Invalid value for '"
                        + RULE_SLEEP_TIME
                        + "': "
                        + this.getConfig().getString(RULE_SLEEP_TIME));
    }
    if (log.isDebugEnabled()) {
        log.debug("Sleep set to " + timeSleepSeconds + " seconds");
    }
}
 
Example #5
Source File: ParametersHelper.java    From vsphere-automation-sdk-java with MIT License 6 votes vote down vote up
private Object getOptionValueFromConfig(
    Option option, Configuration config) {
    Object optionValue = null;
    try {
        if (option.getType().equals(Boolean.class)) {
            optionValue = config.getString(option.getLongOpt());
            if (optionValue != null) {
                optionValue = config.getBoolean(option.getLongOpt());
            }

        } else {
            optionValue = config.getString(option.getLongOpt());
        }
    } catch (ConversionException cex) {
        optionValue = null;
    }
    return optionValue;
}
 
Example #6
Source File: SQLInjectionMsSQL.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void init() {
    if (log.isDebugEnabled()) {
        log.debug("Initialising");
    }

    // set up what we are allowed to do, depending on the attack strength that was set.
    if (this.getAttackStrength() == AttackStrength.LOW) {
        doTimeBased = true;
        doTimeMaxRequests = 3;
    } else if (this.getAttackStrength() == AttackStrength.MEDIUM) {
        doTimeBased = true;
        doTimeMaxRequests = 6;
    } else if (this.getAttackStrength() == AttackStrength.HIGH) {
        doTimeBased = true;
        doTimeMaxRequests = 12;
    } else if (this.getAttackStrength() == AttackStrength.INSANE) {
        doTimeBased = true;
        doTimeMaxRequests = 100;
    }

    // Read the sleep value from the configs
    try {
        this.sleep =
                this.getConfig()
                        .getInt(RuleConfigParam.RULE_COMMON_SLEEP_TIME, DEFAULT_SLEEP_TIME);
    } catch (ConversionException e) {
        log.debug(
                "Invalid value for 'rules.common.sleep': "
                        + this.getConfig().getString(RuleConfigParam.RULE_COMMON_SLEEP_TIME));
    }
    if (log.isDebugEnabled()) {
        log.debug("Sleep set to " + sleep + " seconds");
    }
}
 
Example #7
Source File: Configuration.java    From AisAbnormal with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static boolean isValidPositiveOrZeroFloat(org.apache.commons.configuration.Configuration configuration, String confKey) {
    Float f;
    try {
        f = configuration.getFloat(confKey);
    } catch(ConversionException e) {
        LOG.error("Missing numeric floating point value for: " + confKey);
        return false;
    }
    if (f < 0.0f) {
        LOG.error("Must be positive or zero floating point number: " + confKey);
        return false;
    }
    return true;
}
 
Example #8
Source File: Configuration.java    From AisAbnormal with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static boolean isValidPositiveFloat(org.apache.commons.configuration.Configuration configuration, String confKey) {
    Float f;
    try {
        f = configuration.getFloat(confKey);
    } catch(ConversionException e) {
        LOG.error("Missing numeric floating point value for: " + confKey);
        return false;
    }
    if (f <= 0.0f) {
        LOG.error("Must be positive floating point number: " + confKey);
        return false;
    }
    return true;
}
 
Example #9
Source File: ImportProfile.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private Integer getPositiveInteger(String key) {
    Integer val = config.getInteger(key, null);
    if (val != null && val <= 0) {
        throw new ConversionException(key + " expects positive integer!");
    }
    return val;
}
 
Example #10
Source File: ImportProfile.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private ScalingMethod getJavaScaling(String key) {
    String val = config.getString(key);
    if (val == null || val.isEmpty()) {
        return ScalingMethod.BICUBIC_STEPPED;
    }
    try {
        ScalingMethod hint = ScalingMethod.valueOf(val);
        return hint;
    } catch (Exception e) {
        throw new ConversionException(key, e);
    }
}
 
Example #11
Source File: CejshConfig.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
public static CejshConfig from(Configuration conf) {
        CejshConfig cc = new CejshConfig();
        cc.setCejshXslUrl(conf.getString(PROP_MODS_XSL_URL, null));
//        cc.setJournalUrl(conf.getString(PROP_JOURNALS_URL, null));
        try {
            boolean debug = conf.getBoolean(PROP_DEBUG, Boolean.FALSE);
            cc.setLogLevel(debug ? Level.INFO : Level.FINE);
        } catch (ConversionException ex) {
            LOG.log(Level.SEVERE, PROP_DEBUG, ex);
        }
        return cc;
    }
 
Example #12
Source File: ExternalProcess.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
long getTimeout() {
    try {
        long timeout = conf.getLong(PROP_TIMEOUT, DEFAULT_TIMEOUT);
        timeout = Math.max(0, timeout);
        return timeout;
    } catch (ConversionException ex) {
        LOG.log(Level.WARNING, null, ex);
        return DEFAULT_TIMEOUT;
    }
}
 
Example #13
Source File: ExternalProcess.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
int getRetryCount() {
    try {
        int retry = conf.getInt("retry", DEFAULT_RETRY_ATTEMPTS);
        retry = Math.max(0, retry);
        retry = Math.min(100, retry);
        return retry;
    } catch (ConversionException ex) {
        LOG.log(Level.WARNING, null, ex);
        return DEFAULT_RETRY_ATTEMPTS;
    }
}
 
Example #14
Source File: ShellShockScanner.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void init() {
    // Read the sleep value from the configs
    try {
        this.sleep = this.getConfig().getInt(RuleConfigParam.RULE_COMMON_SLEEP_TIME, 5);
    } catch (ConversionException e) {
        log.debug(
                "Invalid value for 'rules.common.sleep': "
                        + this.getConfig().getString(RuleConfigParam.RULE_COMMON_SLEEP_TIME));
    }
    if (log.isDebugEnabled()) {
        log.debug("Sleep set to " + sleep + " seconds");
    }
}
 
Example #15
Source File: SQLInjectionMySQL.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void init() {
    if (this.debugEnabled) log.debug("Initialising");

    // set up what we are allowed to do, depending on the attack strength that was set.
    if (this.getAttackStrength() == AttackStrength.LOW) {
        doTimeBased = true;
        doTimeMaxRequests = 3;
    } else if (this.getAttackStrength() == AttackStrength.MEDIUM) {
        doTimeBased = true;
        doTimeMaxRequests = 6;
    } else if (this.getAttackStrength() == AttackStrength.HIGH) {
        doTimeBased = true;
        doTimeMaxRequests = 12;
    } else if (this.getAttackStrength() == AttackStrength.INSANE) {
        doTimeBased = true;
        doTimeMaxRequests = 100;
    }

    // Read the sleep value from the configs
    try {
        this.sleep = this.getConfig().getInt(RuleConfigParam.RULE_COMMON_SLEEP_TIME, 5);
    } catch (ConversionException e) {
        log.debug(
                "Invalid value for 'rules.common.sleep': "
                        + this.getConfig().getString(RuleConfigParam.RULE_COMMON_SLEEP_TIME));
    }
    if (this.debugEnabled) {
        log.debug("Sleep set to " + sleep + " seconds");
    }
}
 
Example #16
Source File: SQLInjectionPostgresql.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void init() {
    // DEBUG: turn on for debugging
    // TODO: turn this off
    // log.setLevel(org.apache.log4j.Level.DEBUG);
    // this.debugEnabled = true;

    if (this.debugEnabled) log.debug("Initialising");

    // TODO: debug only
    // this.setAttackStrength(AttackStrength.LOW);

    // set up what we are allowed to do, depending on the attack strength that was set.
    if (this.getAttackStrength() == AttackStrength.LOW) {
        doTimeBased = true;
        doTimeMaxRequests = 3;
    } else if (this.getAttackStrength() == AttackStrength.MEDIUM) {
        doTimeBased = true;
        doTimeMaxRequests = 5;
    } else if (this.getAttackStrength() == AttackStrength.HIGH) {
        doTimeBased = true;
        doTimeMaxRequests = 10;
    } else if (this.getAttackStrength() == AttackStrength.INSANE) {
        doTimeBased = true;
        doTimeMaxRequests = 100;
    }
    // Read the sleep value from the configs
    try {
        this.sleep = this.getConfig().getInt(RuleConfigParam.RULE_COMMON_SLEEP_TIME, 5);
    } catch (ConversionException e) {
        log.debug(
                "Invalid value for 'rules.common.sleep': "
                        + this.getConfig().getString(RuleConfigParam.RULE_COMMON_SLEEP_TIME));
    }
    if (this.debugEnabled) {
        log.debug("Sleep set to " + sleep + " seconds");
    }
}
 
Example #17
Source File: JythonOptionsParam.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@Override
protected void parseImpl() {
    try {
        this.modulePath = super.getConfig().getString(MODULE_PATH_PROPERTY, "");
    } catch (ConversionException e) {
        logger.error("Error while loading '" + MODULE_PATH_PROPERTY + "':", e);
    }
}
 
Example #18
Source File: TestDomXSS.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void init() {
    getProxy();

    try {
        String browserId = this.getConfig().getString(RULE_BROWSER_ID, DEFAULT_BROWSER.getId());
        if (browserId != null && !browserId.isEmpty()) {
            browser = Browser.getBrowserWithIdNoFailSafe(browserId);
        }
    } catch (ConversionException e) {
        log.debug(
                "Invalid value for '"
                        + RULE_BROWSER_ID
                        + "': "
                        + this.getConfig().getString(RULE_BROWSER_ID));
    }

    if (browser == null) {
        browser = DEFAULT_BROWSER;
    } else if (!isSupportedBrowser(browser)) {
        log.warn(
                "Specified browser "
                        + browser
                        + " is not supported, defaulting to: "
                        + DEFAULT_BROWSER);
        browser = DEFAULT_BROWSER;
    }

    if (log.isDebugEnabled()) {
        log.debug("Using browser: " + browser);
    }
}
 
Example #19
Source File: RevealParam.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@Override
protected void parseImpl() {
    try {
        reveal = getConfig().getBoolean(PARAM_REVEAL_STATE, PARAM_REVEAL_STATE_DEFAULT_VALUE);
    } catch (ConversionException e) {
        logger.error("Error while loading the reveal state: " + e.getMessage(), e);
    }
}
 
Example #20
Source File: AjaxSpiderParam.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"fallthrough"})
@Override
protected void updateConfigsImpl(int fileVersion) {
    switch (fileVersion) {
        case NO_CONFIG_VERSION:
            // No updates/changes needed, the configurations were not previously persisted
            // and the current version is already written after this method.
            break;
        case 1:
            String crawlInDepthKey = AJAX_SPIDER_BASE_KEY + ".crawlInDepth";
            try {
                boolean crawlInDepth = getConfig().getBoolean(crawlInDepthKey, false);
                getConfig()
                        .setProperty(CLICK_DEFAULT_ELEMS_KEY, Boolean.valueOf(!crawlInDepth));
            } catch (ConversionException e) {
                logger.warn(
                        "Failed to read (old) configuration '"
                                + crawlInDepthKey
                                + "', no update will be made.");
            }
            getConfig().clearProperty(crawlInDepthKey);
            // $FALL-THROUGH$
        case 2:
            // Remove old version element, from now on the version is saved as an attribute of
            // root element
            getConfig().clearProperty(OLD_CONFIG_VERSION_KEY);
    }
}
 
Example #21
Source File: GlobalAlertFilterParam.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@Override
protected void parseImpl() {
    try {
        List<HierarchicalConfiguration> fields =
                ((HierarchicalConfiguration) getConfig())
                        .configurationsAt(ALL_ALERT_FILTERS_KEY);
        this.alertFilters = new HashSet<>();
        for (HierarchicalConfiguration sub : fields) {
            alertFilters.add(
                    new AlertFilter(
                            -1,
                            sub.getInt(FILTER_RULE_ID_KEY),
                            sub.getInt(FILTER_NEW_RISK_KEY),
                            sub.getString(FILTER_URL_KEY, null),
                            sub.getBoolean(FILTER_URL_IS_REGEX_KEY, false),
                            sub.getString(FILTER_PARAMETER_KEY, null),
                            sub.getBoolean(FILTER_PARAMETER_IS_REGEX_KEY, false),
                            sub.getString(FILTER_ATTACK_KEY, null),
                            sub.getBoolean(FILTER_ATTACK_IS_REGEX_KEY, false),
                            sub.getString(FILTER_EVIDENCE_KEY, null),
                            sub.getBoolean(FILTER_EVIDENCE_IS_REGEX_KEY, false),
                            sub.getBoolean(FILTER_ENABLED_KEY, false)));
        }
    } catch (ConversionException e) {
        logger.error("Error while loading global alert filters: " + e.getMessage(), e);
    }

    this.confirmRemoveFilter = getBoolean(CONFIRM_REMOVE_FILTER_KEY, true);
}
 
Example #22
Source File: SQLInjectionHypersonic.java    From zap-extensions with Apache License 2.0 4 votes vote down vote up
@Override
public void init() {
    // DEBUG: turn on for debugging
    // TODO: turn this off
    // log.setLevel(org.apache.log4j.Level.DEBUG);
    // this.debugEnabled = true;

    if (this.debugEnabled) log.debug("Initialising");

    // TODO: debug only
    // this.setAttackStrength(AttackStrength.INSANE);

    // set up what we are allowed to do, depending on the attack strength that was set.
    if (this.getAttackStrength() == AttackStrength.LOW) {
        doTimeBased = true;
        doTimeMaxRequests = 3;
        doUnionBased = true;
        doUnionMaxRequests = 3;
    } else if (this.getAttackStrength() == AttackStrength.MEDIUM) {
        doTimeBased = true;
        doTimeMaxRequests = 5;
        doUnionBased = true;
        doUnionMaxRequests = 5;
    } else if (this.getAttackStrength() == AttackStrength.HIGH) {
        doTimeBased = true;
        doTimeMaxRequests = 10;
        doUnionBased = true;
        doUnionMaxRequests = 10;
    } else if (this.getAttackStrength() == AttackStrength.INSANE) {
        doTimeBased = true;
        doTimeMaxRequests = 100;
        doUnionBased = true;
        doUnionMaxRequests = 100;
    }
    // Read the sleep value from the configs - note this is in milliseconds
    try {
        this.sleep = this.getConfig().getInt(RuleConfigParam.RULE_COMMON_SLEEP_TIME, 5) * 1000;
    } catch (ConversionException e) {
        log.debug(
                "Invalid value for 'rules.common.sleep': "
                        + this.getConfig().getString(RuleConfigParam.RULE_COMMON_SLEEP_TIME));
    }
    if (this.debugEnabled) {
        log.debug("Sleep set to " + sleep + " milliseconds");
    }
}
 
Example #23
Source File: JobHistoryFileParserHadoop2.java    From hraven with Apache License 2.0 4 votes vote down vote up
/**
 * calculate mega byte millis puts as:
 * if not uberized:
 *        map slot millis * mapreduce.map.memory.mb
 *        + reduce slot millis * mapreduce.reduce.memory.mb
 *        + yarn.app.mapreduce.am.resource.mb * job runtime
 * if uberized:
 *        yarn.app.mapreduce.am.resource.mb * job run time
 */
@Override
public Long getMegaByteMillis() {

  long endTime = this.jobDetails.getFinishTime();
  long startTime = this.jobDetails.getSubmitTime();
  if (endTime == Constants.NOTFOUND_VALUE || startTime == Constants.NOTFOUND_VALUE)
  {
    throw new ProcessingException("Cannot calculate megabytemillis for " + jobKey
        + " since one or more of endTime " + endTime + " startTime " + startTime
        + " not found!");
  }

  long jobRunTime = 0L;
  long amMb = 0L;
  long mapMb = 0L;
  long reduceMb = 0L;

  jobRunTime = endTime - startTime;

  if (jobConf == null) {
    LOG.error("job conf is null? for job key: " + jobKey.toString());
    return null;
  }

  // get am memory mb, map memory mb, reducer memory mb from job conf
  try {
    amMb = jobConf.getLong(Constants.AM_MEMORY_MB_CONF_KEY, Constants.NOTFOUND_VALUE);
    mapMb = jobConf.getLong(Constants.MAP_MEMORY_MB_CONF_KEY,  Constants.NOTFOUND_VALUE);
    reduceMb = jobConf.getLong(Constants.REDUCE_MEMORY_MB_CONF_KEY,  Constants.NOTFOUND_VALUE);
  } catch (ConversionException ce) {
    LOG.error(" Could not convert to long ", ce);
    throw new ProcessingException(
        " Can't calculate megabytemillis since conversion to long failed", ce);
  }
  if (amMb == Constants.NOTFOUND_VALUE ) {
    throw new ProcessingException("Cannot calculate megabytemillis for " + jobKey
        + " since " + Constants.AM_MEMORY_MB_CONF_KEY + " not found!");
  }

  long mapSlotMillis = this.jobDetails.getMapSlotMillis();
  long reduceSlotMillis = this.jobDetails.getReduceSlotMillis();

  /* in case of older versions of hadoop2
   *  the counter of mb millis is not available
   * then use slot millis counter value
   */
  if (this.mapMbMillis == Constants.NOTFOUND_VALUE) {
    this.mapMbMillis = (mapMb * mapSlotMillis);
  }
  if (this.reduceMbMillis == Constants.NOTFOUND_VALUE) {
     this.reduceMbMillis = (reduceMb * reduceSlotMillis);
  }

  long mbMillis = 0L;
  if (uberized) {
    mbMillis = amMb * jobRunTime;
  } else {
    mbMillis = this.mapMbMillis + this.reduceMbMillis + (amMb * jobRunTime);
  }

  LOG.debug("For " + jobKey.toString() + "\n" + Constants.MEGABYTEMILLIS + " is " + mbMillis
      + " since \n uberized: " + uberized + " \n " + "mapMbMillis: " + mapMbMillis
      + " reduceMbMillis:" + reduceMbMillis + "mapMb: " + mapMb + " mapSlotMillis: "
      + mapSlotMillis + " \n " + " reduceMb: " + reduceMb + " reduceSlotMillis: "
      + reduceSlotMillis + " \n " + " amMb: " + amMb + " jobRunTime: " + jobRunTime
      + " start time: " + startTime + " endtime " + endTime);

  this.jobDetails.setMegabyteMillis(mbMillis);
  return mbMillis;
}
 
Example #24
Source File: BrowserViewParam.java    From zap-extensions with Apache License 2.0 3 votes vote down vote up
/**
 * Updates the configurations in the file, if needed.
 *
 * <p>The following steps are made:
 *
 * <ol>
 *   <li>Read the version of the configurations that are in the file;
 *   <li>Check if the version read is the latest version;
 *   <li>If it's not at the latest version, update the configurations.
 * </ol>
 *
 * @see #CURRENT_CONFIG_VERSION
 * @see #isLatestConfigVersion(int)
 * @see #updateConfigsFromVersion(int)
 */
private void updateConfigFile() {
    int configVersion;
    try {
        configVersion = getConfig().getInt(CONFIG_VERSION_KEY, NO_CONFIG_VERSION);
    } catch (ConversionException e) {
        LOGGER.error(
                "Error while getting the version of the configurations: " + e.getMessage(), e);
        configVersion = ERROR_READING_CONFIG_VERSION;
    }

    if (!isLatestConfigVersion(configVersion)) {
        updateConfigsFromVersion(configVersion);
    }
}