Example usage for java.lang System setProperties

List of usage examples for java.lang System setProperties

Introduction

In this page you can find the example usage for java.lang System setProperties.

Prototype

public static void setProperties(Properties props) 

Source Link

Document

Sets the system properties to the Properties argument.

Usage

From source file:com.netspective.commons.config.SystemProperty.java

public void register() {
    if (file != null) {
        Properties properties = new Properties();
        try {//from   w  w w  .j a v  a 2  s . co m
            InputStream is = new FileInputStream(file);
            properties.load(is);
            is.close();
        } catch (IOException e) {
            throw new NestableRuntimeException(e);
        }
        System.setProperties(properties);
    } else if (resource != null) {
        Resource res = new Resource(resourceRelativeToClass, resource);
        Properties properties = new Properties();
        try {
            InputStream is = res.getResourceAsStream();
            properties.load(is);
            is.close();
        } catch (IOException e) {
            throw new NestableRuntimeException(e);
        }
        System.setProperties(properties);
    } else
        System.setProperty(property.getName(), property.getValue(null));
}

From source file:org.holistic.ws_proxy.WSProxyHelper.java

/**
 * // w  w w. ja va  2 s  . com
 * @param strHost Proxy Host
 * @param strPort Proxy Port
 */
public void set_proxy(String strHost, String strPort) {
    if (strHost != null && strPort != null) {
        java.util.Properties m_objProperties = System.getProperties();
        m_objProperties.put("proxySet", "true");
        m_objProperties.put("proxyHost", strHost);
        m_objProperties.put("proxyPort", strPort);
        System.setProperties(m_objProperties);
        log.debug("La comunicacion entre el WSProxyHelper y el endPoint(" + m_strEndPoint
                + ") se realiza a trav\351s del proxy " + strHost + ":" + strPort);
    }
}

From source file:com.foundationdb.http.HttpMonitorVerifySSLIT.java

@Override
protected Map<String, String> startupConfigProperties() {
    Map<String, String> properties = new HashMap<>();
    properties.put("fdbsql.http.login", "digest"); // "digest"
    properties.put("fdbsql.http.ssl", "true");
    properties.put("fdbsql.restrict_user_schema", "true");

    Properties p = new Properties(System.getProperties());
    p.put("javax.net.ssl.keyStore", "./keystore");
    p.put("javax.net.ssl.keyStorePassword", "password");
    System.setProperties(p);
    return properties;
}

From source file:org.commonjava.indy.core.conf.DefaultIndyConfigFactory.java

@Override
public synchronized void load(final String configPath) throws ConfigurationException {
    Properties props = getBaseSystemProperties();

    logger.info(//from   w w  w  .ja  v  a 2 s.  co  m
            "\n\n\n\n[CONFIG] Reading Indy configuration in: '{}'\n\nAdding configuration section listeners:",
            Thread.currentThread().getName());

    logger.info("Adding configuration sections...");
    if (configSections != null) {
        for (final IndyConfigInfo section : configSections) {
            String sectionName = ConfigUtils.getSectionName(section.getClass());
            logger.info("Adding configuration section: {}", sectionName);
            with(sectionName, section);
        }
    }

    final String config = configPath(configPath);

    logger.info("\n\n[CONFIG] Reading configuration in: '{}'\n\nfrom {}", Thread.currentThread().getName(),
            config);

    File configFile = new File(config);
    if (configFile.isDirectory()) {
        configFile = new File(configFile, "main.conf");
    }

    if (!configFile.exists()) {
        File dir = configFile;
        if (dir.getName().equals("main.conf")) {
            dir = dir.getParentFile();
        }

        logger.warn(
                "Cannot find configuration in: {}. Writing default configurations there for future modification.",
                dir);

        if (!dir.exists() && !dir.mkdirs()) {
            throw new ConfigurationException(
                    "Failed to create configuration directory: %s, in order to write defaults.", dir);
        }

        writeDefaultConfigs(dir);
    }

    List<ConfigurationListener> listeners = new ArrayList<>();
    listeners.add(this);

    if (configListeners != null) {
        configListeners.forEach((listener) -> listeners.add(listener));
    }

    InputStream stream = null;
    try {
        stream = ConfigFileUtils.readFileWithIncludes(config, props);

        new DotConfConfigurationReader(listeners).loadConfiguration(stream);

        Properties sysprops = System.getProperties();
        props.stringPropertyNames().forEach((name) -> sysprops.setProperty(name, props.getProperty(name)));

        configSections.forEach((section) -> {
            if (section instanceof SystemPropertyProvider) {
                Properties p = ((SystemPropertyProvider) section).getSystemProperties();
                p.stringPropertyNames().forEach((name) -> sysprops.setProperty(name, p.getProperty(name)));
            }
        });

        System.setProperties(sysprops);
    } catch (final IOException e) {
        throw new ConfigurationException("Cannot open configuration file: {}. Reason: {}", e, configPath,
                e.getMessage());
    } finally {
        closeQuietly(stream);
    }

    logger.info("[CONFIG] Indy configuration complete for: '{}'.\n\n\n\n", Thread.currentThread().getName());
}

From source file:com.github.jrh3k5.flume.mojo.plugin.AbstractFlumePluginMojoITest.java

/**
 * Restore the system properties to their original values.
 * //w w  w.  ja  v a 2s  .c  o  m
 * @throws Exception
 *             If any errors occur during the restoration.
 */
@After
public void restoreSystemProperties() throws Exception {
    System.setProperties(ORIGINAL_SYSTEM_PROPERTIES);
}

From source file:org.apache.avalon.framework.logger.test.CommonsLoggerTestCase.java

/**
 * Test creation of a child logger. Nees <tt>simplelog.properties</tt> as resource.
 *///from   w ww . j  a  va  2 s  .c  o  m
public void testChildLogger() {
    final Properties systemProperties = System.getProperties();
    final PrintStream err = System.err;
    try {
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        final PrintStream stream = new PrintStream(buffer, true);
        System.setProperty(Log.class.getName(), SimpleLog.class.getName());
        LogFactory.releaseAll();
        System.setErr(stream);
        final Logger logger = new CommonsLogger(LogFactory.getLog("JUnit"), "JUnit");
        final Logger child = logger.getChildLogger("test");
        child.fatalError("foo");
        assertEquals("[FATAL] JUnit.test - foo", buffer.toString().trim());
    } finally {
        System.setProperties(systemProperties);
        System.setErr(err);
    }

}

From source file:org.graphwalker.maven.plugin.TestMojo.java

protected Properties switchProperties(Properties properties) {
    Properties oldProperties = (Properties) System.getProperties().clone();
    System.setProperties(properties);
    return oldProperties;
}

From source file:com.thoughtworks.acceptance.EncodingTestSuite.java

private void addDriverTest(final HierarchicalStreamDriver driver) {
    final String testName = getShortName(driver);
    final String allEncodingTests = System.getProperty("xstream.test.encoding.all");
    if ("true".equals(allEncodingTests)) {
        // Native encoding normally fails on most systems!!
        addTest(new TestCase(testName + "Native") {
            @Override/*from   www  .  ja v  a  2s  .  co  m*/
            protected void runTest() throws Throwable {
                test(driver, null);
            }
        });
        // System encoding fails on US-ASCII systems, like Codehaus Bamboo
        final String systemEncoding = System.getProperty("file.encoding");
        addTest(new TestCase(testName + "With" + systemEncoding + "SystemEncoding") {
            @Override
            protected void runTest() throws Throwable {
                final Properties systemProperties = new Properties();
                systemProperties.putAll(System.getProperties());
                try {
                    // Use BEA reference implementation for StAX
                    // (Woodstox will fail on Windows because of unknown system encoding)
                    System.setProperty(XMLInputFactory.class.getName(), MXParserFactory.class.getName());
                    test(driver, systemEncoding);
                } finally {
                    System.setProperties(systemProperties);
                }
            }
        });
    }
    addTest(new TestCase(testName + "WithUTF_8Encoding") {
        @Override
        protected void runTest() throws Throwable {
            test(driver, "UTF-8");
        }
    });
    addTest(new TestCase(testName + "WithIS0_8859_1Encoding") {
        @Override
        protected void runTest() throws Throwable {
            test(driver, "ISO-8859-1");
        }
    });
}

From source file:gov.nih.nci.nbia.StandaloneDMDispatcher.java

public void loadManifestFile(String fileName) {
    FileInputStream propFile;/*from  w  w w.  j a  v a2s.c o m*/
    try {
        propFile = new FileInputStream(fileName);
        Properties p = new Properties(System.getProperties());
        p.load(propFile);
        // set the system properties
        System.setProperties(p);
        System.setProperty("jnlp.localSeriesDownloader.className",
                "gov.nih.nci.nbia.download.LocalSeriesDownloader");
        System.setProperty("jnlp.remoteSeriesDownloader.className",
                "gov.nih.nci.nbia.download.RemoteSeriesDownloader");
        propFile.close();
        this.serverUrl = System.getProperty("downloadServerUrl");
        manifestVersion = System.getProperty("manifestVersion");
        checkManifestVersion(manifestVersion);
        if (manifestVersion.startsWith("3.")) {
            seriesList = getSeriesList(fileName);
        }

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.pentaho.di.junit.rules.RestorePDIEnvironment.java

@Override
protected void after() {
    cleanUp();/*  ww  w .j av  a2  s .com*/

    System.setProperties(originalProperties);
    Locale.setDefault(originalLocale);
    Locale.setDefault(Locale.Category.FORMAT, originalFormatLocale);
    LanguageChoice.getInstance().setDefaultLocale(originalLocale);
    TimeZone.setDefault(originalTimezone);
    FileUtils.deleteQuietly(tmpKettleHome.toFile());
}