Example usage for java.lang System getenv

List of usage examples for java.lang System getenv

Introduction

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

Prototype

public static String getenv(String name) 

Source Link

Document

Gets the value of the specified environment variable.

Usage

From source file:com.ibm.rpe.web.template.ui.utils.Utils.java

public static String getSystemProperty(String property, String defaultValue) {
    String value = null;/*from w w w. ja va 2 s.c o m*/

    if (CommonUtils.isNullOrEmpty(value)) {
        value = System.getenv(property);
    }

    return value != null ? value : defaultValue;
}

From source file:io.kahu.hawaii.service.io.LocationHelper.java

public String getHawaiiClientDocRoot() {
    if (hawaiiClientDocRoot == null) {
        hawaiiClientDocRoot = System.getenv("HAWAII_CLIENT_DOCROOT");
    }//  w w w.  j  a va  2s  .  c  o m

    return hawaiiClientDocRoot;
}

From source file:com.springsource.oauthservice.Bootstrap.java

public void go() throws Exception {
    String vcapServices = System.getenv("VCAP_SERVICES");
    LOG.debug("VCAP_SERVICES: " + vcapServices);
    // jdbc:postgresql://172.30.48.126:5432/d6f69ba9c3c6349ac830af2973e31b779

    // pull values out and construct JDBC URL
    Map credentials = getCredentialsMap(vcapServices);
    String dbName = (String) credentials.get("name");
    String host = (String) credentials.get("host");
    Integer port = (Integer) credentials.get("port");
    String username = (String) credentials.get("username");
    String password = (String) credentials.get("password");

    LOG.debug("    JDBC URL:  jdbc:postgresql://" + host + ":" + port + "/" + dbName);
    LOG.debug("    DB USERNAME: " + username);
    LOG.debug("    DB PASSWORD: " + password);
}

From source file:discord4j.core.ExampleBot.java

@BeforeClass
public static void initialize() {
    token = System.getenv("token");
    testRole = System.getenv("testRole");
}

From source file:com.twitter.heron.uploader.localfs.LocalFileSystemUploaderTest.java

@Before
public void before() throws Exception {

    // form the file system directory using bazel environ files
    fileSystemDirectory = Paths.get(System.getenv("JAVA_RUNFILES"), "topologies").toString();

    // form the test topology directory
    testTopologyDirectory = Paths
            .get(System.getenv("JAVA_RUNFILES"), LocalFileSystemConstantsTest.TEST_DATA_PATH).toString();

    // Create the minimum config for tests
    config = Config.newBuilder().put(Keys.cluster(), "cluster").put(Keys.role(), "role")
            .put(Keys.topologyName(), "topology").put(Keys.topologyPackageType(), "tar")
            .put(LocalFileSystemKeys.fileSystemDirectory(), fileSystemDirectory).build();
}

From source file:com.nebhale.demo.web.ConfigurationController.java

@RequestMapping(method = RequestMethod.GET, value = "/environment")
String environment() {
    return System.getenv("TEST_PROPERTY");
}

From source file:com.messagehub.samples.bluemix.BluemixEnvironment.java

/**
 * Parses VCAP_SERVICES to extract Message Hub connection configuration
 * @return an instance of MessageHubCredentials
 * @throws IOException on parsing error//from  w w  w.  j  av a  2  s.c  om
 * @throws IllegalStateException if there is no Message Hub service bound to the application
 */
public static MessageHubCredentials getMessageHubCredentials() throws IOException {
    // Arguments parsed via VCAP_SERVICES environment variable.
    String vcapServices = System.getenv("VCAP_SERVICES");
    ObjectMapper mapper = new ObjectMapper();

    try {
        // Parse VCAP_SERVICES into Jackson JsonNode, then map the 'messagehub' entry
        // to an instance of MessageHubEnvironment.
        JsonNode vcapServicesJson = mapper.readValue(vcapServices, JsonNode.class);
        ObjectMapper envMapper = new ObjectMapper();
        String vcapKey = null;
        Iterator<String> it = vcapServicesJson.fieldNames();

        // Find the Message Hub service bound to this application.
        while (it.hasNext() && vcapKey == null) {
            String potentialKey = it.next();

            if (potentialKey.startsWith("messagehub")) {
                logger.log(Level.INFO, "Using the '" + potentialKey + "' key from VCAP_SERVICES.");
                vcapKey = potentialKey;
            }
        }

        // Sanity assertion check
        if (vcapKey == null) {
            logger.log(Level.ERROR,
                    "Error while parsing VCAP_SERVICES: A Message Hub service instance is not bound to this application.");
            throw new IllegalStateException(
                    "Error while parsing VCAP_SERVICES: A Message Hub service instance is not bound to this application.");
        }

        MessageHubEnvironment messageHubEnvironment = envMapper
                .readValue(vcapServicesJson.get(vcapKey).get(0).toString(), MessageHubEnvironment.class);
        MessageHubCredentials credentials = messageHubEnvironment.getCredentials();
        return credentials;
    } catch (IOException e) {
        logger.log(Level.ERROR, "Failed parsing or processing VCAP_SERVICES", e);
        throw e;
    }
}

From source file:com.predic8.membrane.core.RouterCLI.java

private static String getRulesFile(MembraneCommandLine line) {
    if (line.hasConfiguration()) {
        return line.getConfiguration();
    } else {/*  w  w w  .  j av  a  2s .c  o m*/
        return System.getenv("MEMBRANE_HOME") + System.getProperty("file.separator") + "conf"
                + System.getProperty("file.separator") + "rules.xml";
    }
}

From source file:eu.optimis.ecoefficiencytool.core.tools.ConfigManager.java

public static String getConfigFilePath(String configFile) {
    String optimisHome = System.getenv("OPTIMIS_HOME");
    if (optimisHome == null) {
        optimisHome = "/opt/optimis";
        log.debug("ECO: OPTIMIS_HOME: " + optimisHome + " (DEFAULT)");
    } else {/*from w  w  w  . j  a  v a  2  s .co m*/
        log.debug("ECO: OPTIMIS_HOME: " + optimisHome);
    }

    File fileObject = new File(optimisHome.concat(configFile));
    if (!fileObject.exists()) {
        try {
            createDefaultConfigFile(fileObject);
        } catch (Exception ex) {
            log.error("ECO: Error reading " + optimisHome.concat(configFile) + " configuration file: "
                    + ex.getMessage());
            ex.printStackTrace();
        }
    }

    return optimisHome.concat(configFile);
}

From source file:com.qwazr.mavenplugin.QwazrStopMojo.java

static Integer getProperty(Integer currentValue, String env, Integer defaultValue) {
    if (currentValue != null)
        return currentValue;
    String value = env == null ? null : System.getenv(env);
    return value != null ? Integer.parseInt(value) : defaultValue;
}