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:Bean.ObjectStorageConnector.java

public void getConnection() {

    try {//www  . j ava  2 s  .  com
        String envApp = System.getenv("VCAP_APPLICATION");
        String envServices = System.getenv("VCAP_SERVICES");

        JSONParser parser = new JSONParser();
        Object obj = parser.parse(envServices);
        JSONObject jsonObject = (JSONObject) obj;
        JSONArray vcapArray = (JSONArray) jsonObject.get("Object-Storage");
        JSONObject vcap = (JSONObject) vcapArray.get(0);
        JSONObject credentials = (JSONObject) vcap.get("credentials");
        auth_url = credentials.get("auth_url").toString() + "/v3";
        project = credentials.get("project").toString();
        projectId = credentials.get("projectId").toString();
        region = credentials.get("region").toString();
        userId = credentials.get("userId").toString();
        username = credentials.get("username").toString();
        password = credentials.get("password").toString();
        domainId = credentials.get("domainId").toString();
        domainName = credentials.get("domainName").toString();

        Identifier domainIdent = Identifier.byName(domainName);
        Identifier projectIdent = Identifier.byName(project);

        os = OSFactory.builderV3().endpoint(auth_url).credentials(userId, password)
                .scopeToProject(projectIdent, domainIdent).authenticate();

        account = os.objectStorage().account().get();

    } catch (ParseException ex) {
    }
}

From source file:com.seyren.core.util.config.GraphiteConfig.java

private static String environmentOrDefault(String propertyName, String defaultValue) {
    String value = System.getProperty(propertyName);
    if (isNotEmpty(value)) {
        return value;
    }/*from   ww  w  .jav  a 2s.  com*/
    value = System.getenv(propertyName);
    if (isNotEmpty(value)) {
        return value;
    }
    return defaultValue;
}

From source file:com.cisco.oss.foundation.logging.converters.FoundationLoggingCompInstPathPatternConverter.java

private static String getComponentInstallPath() {
    String compInstPath = System.getenv("_INSTALL_DIR");

    if (StringUtils.isBlank(compInstPath)) {
        compInstPath = "UNKNOWN";
    }/*from ww  w .  ja v a 2s.c o  m*/

    return compInstPath;
}

From source file:com.gooddata.AbstractGoodDataAT.java

public static String getProperty(String name) {
    final String value = System.getenv(name);
    if (value != null) {
        return value;
    }//from w  w  w  . j a v  a  2 s.  c om
    throw new IllegalArgumentException(
            "Environment variable " + name + " not found! Available variables: " + System.getenv().keySet());
}

From source file:com.mohawk.webcrawler.lang.verb.GetPdf_Verb.java

@Override
public Object run(ScriptContext pageContext, Object... params) throws Exception {

    String dataDirectory = System.getenv("OPENSHIFT_DATA_DIR");
    String cacheDirectory = null;

    if (dataDirectory != null)
        cacheDirectory = dataDirectory + "webcrawler/cache";
    else/* w  w w  .  ja  v a 2s .  com*/
        cacheDirectory = "C:\\Users\\cnguyen\\Projects\\ProjectMohawk\\Scripts\\cache";

    Object param = LangCore.resolveParameter(pageContext, params[0]);

    Document doc = null;
    Config config = pageContext.getConfig();

    if (config.getCacheDirectory() != null) { // pull the HTML from cache

        String prefix = null; //config.getProviderId() + "_";
        Collection<File> files = FileUtils.listFiles(new File(cacheDirectory), null, false);

        for (File file : files) {
            String filename = file.getName();
            if (file.getName().startsWith(prefix) && filename.endsWith(".html")) {
                doc = (Document) Jsoup.parse(file, "UTF-8");
                break;
            }
        }

        if (doc == null)
            throw new Exception("Unable to find cached file for script>> " + config.getScriptFilename());
    } else {
        // get it from the web
        System.out.println("URL>> " + param);
    }

    // clear out any other contexts
    pageContext.setTableContext(null);
    pageContext.setDocument(doc);
    pageContext.setDocumentHtml(doc.html());
    pageContext.setCursorPosition(0);

    return null;
}

From source file:com.chinamobile.bcbsp.fault.storage.MonitorFaultLog.java

/**
 * get the faultlog storage path// w  ww.j av  a2s .  c om
 * @return faultlog storage path
 */
private static String getFaultStoragePath() {
    String BCBSP_HOME = System.getenv("BCBSP_HOME");
    String FaultStoragePath = BCBSP_HOME + "/logs/faultlog/";
    return FaultStoragePath;
}

From source file:com.opensymphony.xwork2.config.providers.EnvsValueSubstitutorTest.java

public void testEnvSimpleValue() {
    if (SystemUtils.IS_OS_WINDOWS) {
        assertThat(substitutor.substitute("${env.USERNAME}"), is(System.getenv("USERNAME")));
    } else {/*  w w w. j  a  va  2s .c  o m*/
        assertThat(substitutor.substitute("${env.USER}"), is(System.getenv("USER")));
    }
}

From source file:com.example.analytics.AnalyticsServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    String trackingId = System.getenv("GA_TRACKING_ID");
    HttpClient client = HttpClientBuilder.create().build();
    URIBuilder builder = new URIBuilder();
    builder.setScheme("http").setHost("www.google-analytics.com").setPath("/collect").addParameter("v", "1") // API Version.
            .addParameter("tid", trackingId) // Tracking ID / Property ID.
            // Anonymous Client Identifier. Ideally, this should be a UUID that
            // is associated with particular user, device, or browser instance.
            .addParameter("cid", "555").addParameter("t", "event") // Event hit type.
            .addParameter("ec", "example") // Event category.
            .addParameter("ea", "test action"); // Event action.
    URI uri = null;//  w w  w.j av a 2  s  . c  o m
    try {
        uri = builder.build();
    } catch (URISyntaxException e) {
        throw new ServletException("Problem building URI", e);
    }
    HttpPost request = new HttpPost(uri);
    client.execute(request);
    resp.getWriter().println("Event tracked.");
}

From source file:net.sf.jvifm.util.AutoCompleteUtil.java

public static void _initSysExeNameList() {
    sysExeNameList = new ArrayList<String>();

    String pathStr = System.getenv("PATH");
    String[] paths = pathStr.split(";");
    for (String path : paths) {
        File file = new File(path);
        if (!file.exists())
            continue;
        File[] subFiles = file.listFiles();
        if (subFiles == null)
            continue;
        for (File subFile : subFiles) {
            String ext = FilenameUtils.getExtension(subFile.getPath());
            if (isExecuteFile(ext)) {
                sysExeNameList.add(subFile.getAbsolutePath());
            }//from   w w  w  .  java2 s.  co m
        }
    }
}

From source file:com.bbc.remarc.servlet.ResourceServletContextListener.java

@Override
public void contextInitialized(ServletContextEvent event) {
    log.debug("contextInitialized");

    String resourcesPath = System.getenv(Configuration.ENV_DATA_DIR_OPENSHIFT);

    if (resourcesPath == null || "".equals(resourcesPath)) {
        log.info("Not running on OpenShift. Falling back to local resource path");

        resourcesPath = System.getenv(Configuration.ENV_DATA_DIR_LOCAL);
    }//from ww  w. ja va  2 s  .  c  o  m

    createResourceFolders(resourcesPath);

    event.getServletContext().setAttribute(Configuration.ATT_DATA_DIR, resourcesPath);
}