Ejemplo n.º 1
0
  /** @param args */
  public static void main(String[] args) {
    // TODO Auto-generated method stub

    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {
      config.addConfiguration(new PropertiesConfiguration("storage.properties"));
    } catch (ConfigurationException e) {
      // TODO Auto-generated catch block
      logger.error(e.getMessage());
    }

    String rootFolder = config.getString("bp.root.folder");

    String altpartyid = args[0];

    SqlSession sqlSession = RazorServer.openSession();
    try {
      if (StringUtils.isBlank(altpartyid)) {
        //				altpartyid = "231051"; //NextPax partner GA
        altpartyid = "179795";
      }

      Partner partner = sqlSession.getMapper(PartnerMapper.class).exists(altpartyid);
      if (partner == null) {
        throw new ServiceException(Error.party_id, altpartyid);
      }
      A_Handler handler = new A_Handler(partner);
      handler.downloadImages(rootFolder);
    } catch (Exception e) {
      logger.error(e.getMessage());
    }
  }
  private void _addIncludedPropertiesSources(
      Configuration newConfiguration, CompositeConfiguration loadedCompositeConfiguration) {

    CompositeConfiguration tempCompositeConfiguration = new CompositeConfiguration();

    tempCompositeConfiguration.addConfiguration(_prefixedSystemConfiguration);
    tempCompositeConfiguration.addConfiguration(newConfiguration);
    tempCompositeConfiguration.addConfiguration(_systemConfiguration);
    tempCompositeConfiguration.addProperty(Conventions.COMPANY_ID_PROPERTY, _companyId);
    tempCompositeConfiguration.addProperty(Conventions.COMPONENT_NAME_PROPERTY, _componentName);

    String[] fileNames = tempCompositeConfiguration.getStringArray(Conventions.INCLUDE_PROPERTY);

    for (String fileName : fileNames) {
      URL url = null;

      try {
        url = _classLoader.getResource(fileName);
      } catch (RuntimeException re) {
        if (fileName.startsWith("file:/")) {
          throw re;
        }

        fileName = "file:/".concat(fileName);

        url = _classLoader.getResource(fileName);
      }

      _addPropertiesSource(fileName, url, loadedCompositeConfiguration);
    }
  }
Ejemplo n.º 3
0
  public static Configuration instance() {
    if (config == null) {
      try {
        // Default values build into war file, this is last prio used if no of the other sources
        // override this
        boolean allowexternal =
            Boolean.getBoolean(
                new PropertiesConfiguration(
                        ExtraConfiguration.class.getResource("/" + PROPERTY_FILENAME))
                    .getString(CONFIGALLOWEXTERNAL, "false"));

        config = new CompositeConfiguration();

        PropertiesConfiguration pc;
        // Only add these config sources if we allow external configuration
        if (allowexternal) {
          // Override with system properties, this is prio 1 if it exists (java -Dscep.test=foo)
          config.addConfiguration(new SystemConfiguration());
          log.info("Added system properties to configuration source (java -Dfoo.prop=bar).");

          // Override with file in "application server home directory"/conf, this is prio 2
          File f1 = new File("conf/" + PROPERTY_FILENAME);
          pc = new PropertiesConfiguration(f1);
          pc.setReloadingStrategy(new FileChangedReloadingStrategy());
          config.addConfiguration(pc);
          log.info("Added file to configuration source: " + f1.getAbsolutePath());

          // Override with file in "/etc/ejbca/conf/extra, this is prio 3
          File f2 = new File("/etc/ejbca/conf/extra/" + PROPERTY_FILENAME);
          pc = new PropertiesConfiguration(f2);
          pc.setReloadingStrategy(new FileChangedReloadingStrategy());
          config.addConfiguration(pc);
          log.info("Added file to configuration source: " + f2.getAbsolutePath());
        }

        // Default values build into war file, this is last prio used if no of the other sources
        // override this
        URL url = ExtraConfiguration.class.getResource("/" + PROPERTY_FILENAME);
        pc = new PropertiesConfiguration(url);
        config.addConfiguration(pc);
        log.info("Added url to configuration source: " + url);

        log.info("Allow external re-configuration: " + allowexternal);
        // Test
        log.debug("Using keystore path (1): " + config.getString(SCEPKEYSTOREPATH + ".1"));
        // log.debug("Using keystore pwd (1): "+config.getString(SCEPKEYSTOREPWD+".1"));
        // log.debug("Using authPwd: "+config.getString(SCEPAUTHPWD));
        log.debug("Using certificate profile: " + config.getString(SCEPCERTPROFILEKEY));
        log.debug("Using entity profile: " + config.getString(SCEPENTITYPROFILEKEY));
        log.debug("Using default CA: " + config.getString(SCEPDEFAULTCA));
        log.debug("Create or edit user: "******"Mapping for CN=Scep CA,O=EJBCA Sample,C=SE: "
                + config.getString("CN=Scep CA,O=EJBCA Sample,C=SE"));
      } catch (ConfigurationException e) {
        log.error("Error intializing ExtRA Configuration: ", e);
      }
    }
    return config;
  }
Ejemplo n.º 4
0
 public static CompositeConfiguration load(File source) throws ConfigurationException {
   CompositeConfiguration config = new CompositeConfiguration();
   config.setListDelimiter(',');
   File customConfigFile = new File(source, LEGACY_CONFIG_FILE);
   if (customConfigFile.exists()) {
     if (!LEGACY_CONFIG_FILE_WARNING_SHOWN) {
       LOGGER.warn(
           String.format(
               "You have defined a part of your JBake configuration in %s located at: %s",
               LEGACY_CONFIG_FILE, customConfigFile.getParent()));
       LOGGER.warn(
           String.format(
               "Usage of this file is being deprecated, please rename this file to: %s to remove this warning",
               CONFIG_FILE));
       LEGACY_CONFIG_FILE_WARNING_SHOWN = true;
     }
     config.addConfiguration(new PropertiesConfiguration(customConfigFile));
   }
   customConfigFile = new File(source, CONFIG_FILE);
   if (customConfigFile.exists()) {
     config.addConfiguration(new PropertiesConfiguration(customConfigFile));
   }
   config.addConfiguration(new PropertiesConfiguration(DEFAULT_CONFIG_FILE));
   return config;
 }
Ejemplo n.º 5
0
 @Override
 public Config createConfig(String name) {
   try {
     final CompositeConfiguration config = new CompositeConfiguration();
     config.addConfiguration(new SystemConfiguration());
     config.addConfiguration(new PropertiesConfiguration("test.properties"));
     return new ApacheTestConfig(config);
   } catch (ConfigurationException e) {
     throw new RuntimeException(e);
   }
 }
Ejemplo n.º 6
0
 @Before
 public void setUp() throws Exception {
   CompositeConfiguration config = new CompositeConfiguration();
   config.addConfiguration(new PropertiesConfiguration("whirr-elasticsearch-test.properties"));
   if (System.getProperty("config") != null) {
     config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
   }
   clusterSpec = ClusterSpec.withTemporaryKeys(config);
   controller = new ClusterController();
   cluster = controller.launchCluster(clusterSpec);
 }
  /**
   * Remove all cached property information and reload system properties. User must reload any
   * required property data sources.
   */
  public void ResetProperties() {
    // clear out composite config and add a fresh system config into it
    config.clear();
    Configuration sysConfig = new SystemConfiguration();
    config.addConfiguration(sysConfig);

    // clear out the config map and put system into it
    configMap.clear();
    configMap.put("system", sysConfig);
  }
Ejemplo n.º 8
0
 static {
   sConfig.addConfiguration(new SystemConfiguration());
   /* on the file system, if user specified */
   String key = "sprockets.config.file";
   String config = System.getProperty(key);
   if (config != null) {
     File file = new File(config);
     if (file.isFile() && file.canRead()) {
       try {
         sConfig.addConfiguration(new XMLConfiguration(config));
       } catch (ConfigurationException e) {
         throw new RuntimeException("loading " + key + ": " + config, e);
       }
     } else {
       sLog.log(WARNING, "can''t read {0}: {1}", new String[] {key, config});
     }
   }
   /* in the class path; if not user specified then check for default */
   key = "sprockets.config.resource";
   config = System.getProperty(key);
   String defConfig = "sprockets.xml";
   URL url = Sprockets.class.getClassLoader().getResource(config != null ? config : defConfig);
   if (url != null) {
     try {
       sConfig.addConfiguration(new XMLConfiguration(url));
     } catch (ConfigurationException e) {
       throw new RuntimeException("loading " + key + ": " + url, e);
     }
   } else if (config != null) {
     sLog.log(WARNING, "can''t read {0}: {1}", new String[] {key, config});
   }
   /* in this package */
   url = Sprockets.class.getResource(defConfig);
   if (url != null) {
     try {
       sConfig.addConfiguration(new XMLConfiguration(url));
     } catch (ConfigurationException e) {
       throw new RuntimeException("loading sprockets default config: " + defConfig, e);
     }
   }
 }
Ejemplo n.º 9
0
 static {
   try {
     CompositeConfiguration settings = new CompositeConfiguration();
     settings.addConfiguration(new PropertiesConfiguration("system.properties"));
     Configuration serverConf = settings.subset("service");
     dbReadUrls = serverConf.getString("dbReadUrls");
     dbDriver = serverConf.getString("dbDriver");
     dbClient = new MoDBRW(dbReadUrls, dbDriver);
   } catch (Exception e) {
     logger.error("init database error", e);
   }
 }
  /** Build a configuration by adding the expected defaults */
  public static Configuration buildConfig(ClusterSpec spec, Cluster cluster) {
    CompositeConfiguration config = new CompositeConfiguration();

    config.addConfiguration(spec.getConfiguration());
    try {
      config.addConfiguration(
          new PropertiesConfiguration("whirr-elasticsearch-default.properties"));
    } catch (ConfigurationException e) {
      LOG.error("Configuration error", e); // this should never happen
    }

    if ("aws-ec2".equals(spec.getProvider()) || "ec2".equals(spec.getProvider())) {
      addDefaultsForEC2(spec, config);
    } else {
      addDefaultsForUnicast(cluster, config);
    }
    if (!config.containsKey("es.cluster.name")) {
      config.addProperty("es.cluster.name", spec.getClusterName());
    }

    return config;
  }
Ejemplo n.º 11
0
  /**
   * Constructor for JakartaPropertiesConfig objects. Creates a new composite configuration and adds
   * a system configuration to it.
   */
  public JakartaPropertiesConfig() {
    // create global composite to store all loaded property config data
    config = new CompositeConfiguration();

    // create a system properties configuration - grabs all system
    // properties.
    Configuration sysConfig = new SystemConfiguration();
    config.addConfiguration(sysConfig);

    // create map to store individual configs
    configMap = new HashMap<String, Configuration>();

    // put system properties in the map
    configMap.put("system", sysConfig);
  }
  private Configuration _addPropertiesSource(
      String sourceName, URL url, CompositeConfiguration loadedCompositeConfiguration) {

    try {
      Configuration newConfiguration = null;

      if (DatasourceURL.isDatasource(sourceName)) {
        newConfiguration = _addDatasourceProperties(sourceName);
      } else if (JndiURL.isJndi(sourceName)) {
        newConfiguration = _addJNDIProperties(sourceName);
      } else if (url != null) {
        newConfiguration = _addURLProperties(url, loadedCompositeConfiguration);
      } else {
        newConfiguration = _addFileProperties(sourceName, loadedCompositeConfiguration);
      }

      if (newConfiguration == null) {
        return newConfiguration;
      }

      loadedCompositeConfiguration.addConfiguration(newConfiguration);

      super.addConfiguration(newConfiguration);

      if (newConfiguration instanceof AbstractFileConfiguration) {
        AbstractFileConfiguration abstractFileConfiguration =
            (AbstractFileConfiguration) newConfiguration;

        URL abstractFileConfigurationURL = abstractFileConfiguration.getURL();

        _loadedSources.add(abstractFileConfigurationURL.toString());
      } else {
        _loadedSources.add(sourceName);
      }

      return newConfiguration;
    } catch (Exception e) {
      if (_log.isDebugEnabled()) {
        _log.debug("Configuration source " + sourceName + " ignored: " + e.getMessage());
      }

      return null;
    }
  }
Ejemplo n.º 13
0
 @Test
 public void testCompositeConfiguration() throws URISyntaxException {
   CompositeConfiguration configuration = new CompositeConfiguration();
   try {
     PropertiesConfiguration propertiesConfiguration =
         new PropertiesConfiguration("conf/pss-settings.properties");
     //
     //	propertiesConfiguration.setFileName("E:/study/jelyworkspace/jelypss/pss-core/target/test-classes/conf/pss-settings.properties");
     propertiesConfiguration.load(
         "E:/study/jelyworkspace/jelypss/pss-core/target/test-classes/conf/pss-settings.properties");
     configuration.addConfiguration(propertiesConfiguration);
     //			propertiesConfiguration.setProperty("haha", 1235);
     configuration.setProperty("asdf", "aaaaaaaaa");
     System.out.println(configuration.getInt("haha"));
     System.out.println(this.getClass().getClassLoader().getResource("").toURI().toString());
     System.out.println(this.getClass().getClassLoader().getResource("").toString());
     propertiesConfiguration.save();
   } catch (ConfigurationException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 14
0
  /**
   * Load in a single property data source, or a "config.xml" descriptor file (specifying multiple
   * data sources). Properties are added to the global composite property data set.
   *
   * <p>
   *
   * <p>N.B. Due to underlying Jakarta (commons configuration) implementation, any previously loaded
   * properties (with duplicate keys) will override subsequently loaded properties. ie clients
   * should load in override (eg user) data before loading default (eg core) data.
   *
   * <p>
   *
   * <p>N.B. Also system properties are currently loaded before any calls to loadPropertyData, so
   * they take precedence over everything.
   *
   * @param listName the path name of the property data source. If the name ends in "config.xml"
   *     then the file is treated as a Jakarta commons configuration descriptor file. If the file
   *     ends in ".xml" it is loaded as a Jakarta XML property configuration file. Otherwise it is
   *     loaded as a legacy flat-file key-value pair plain text property file. N.B. Although Jakarta
   *     supports other data sources, eg JDBC, these are not yet supported via this method.
   * @throws ConfigurationException
   * @see gda.configuration.properties.PropertiesConfig#loadPropertyData(java.lang.String)
   */
  @Override
  public void loadPropertyData(String listName) throws ConfigurationException {
    Configuration userConfig = null;

    if (listName.contains(".xml")) {
      if (listName.endsWith("config.xml")) {

        // *****
        // FIXME 'ConfigurationFactory' should be replaced with the new and improved
        // 'DefaultConfigurationBuilder'
        // *****

        // create a JCC configuration factory from a JCC config descriptor
        // file and make a JCC configuration interface/object from it
        ConfigurationFactory factory = new ConfigurationFactory();

        // README - fix to get relative paths in config.xml working.
        // See comment for this method for explanation.
        configFactoryBasePathBugWorkaround(factory, listName);

        // now try to load in config.xml - relative paths should now work
        factory.setConfigurationFileName(listName);
        userConfig = factory.getConfiguration();
      } else {
        // load a JCC XML-format property file
        userConfig = new XMLConfiguration(listName);
      }
    } else {
      if (listName.contains(".properties")) {
        // load a classic java properties flat-textfile,
        // containing just name-value pairs - with extended JCC syntax
        userConfig = new PropertiesConfiguration(listName);
      }
    }

    if (userConfig != null) {
      config.addConfiguration(userConfig);
      configMap.put(listName, userConfig);
    }
  }
Ejemplo n.º 15
0
  private ConfigManager() {
    try {
      String configPath = this.getClass().getResource(ConstDef.SYSTEM_CONFIG).getFile();
      // String configPath2 =
      // "/D:/Program%20Files/apache-tomcat-6.0.32/webapps/SkyFormOpt/WEB-INF/classes/config.properties";
      configPath = java.net.URLDecoder.decode(configPath, "utf-8");
      log.info("get sysconfig file : " + configPath);

      config = new CompositeConfiguration();
      FileConfiguration pconfig = new PropertiesConfiguration(configPath);
      config.addConfiguration(pconfig);
      // pconfig.setAutoSave(true);
      // reload strategy
      FileChangedReloadingStrategy reloadStrategy = new FileChangedReloadingStrategy();
      reloadStrategy.setRefreshDelay(3000);
      // for performance tunning , remove this line
      pconfig.setReloadingStrategy(reloadStrategy);

      log.info("initialize sysconfig config file OK");
    } catch (Exception e) {
      log.error("initialize sysconfig config file error...");
      e.printStackTrace();
    }
  }
Ejemplo n.º 16
0
 /**
  * You can load configurations in precedence order. The first one takes precedence over any loaded
  * later.
  *
  * @param confURL
  */
 public void loadConf(URL confURL) throws ConfigurationException {
   Configuration loadedConf = new PropertiesConfiguration(confURL);
   conf.addConfiguration(loadedConf);
 }