Example usage for java.net URI getPath

List of usage examples for java.net URI getPath

Introduction

In this page you can find the example usage for java.net URI getPath.

Prototype

public String getPath() 

Source Link

Document

Returns the decoded path component of this URI.

Usage

From source file:com.eucalyptus.storage.BlockStorageChecker.java

public static void checkWalrusConnection() {
    HttpClient httpClient = new HttpClient();
    GetMethod getMethod = null;/*from  w w w. j a va  2s. com*/
    try {
        java.net.URI addrUri = new URL(StorageProperties.WALRUS_URL).toURI();
        String addrPath = addrUri.getPath();
        String addr = StorageProperties.WALRUS_URL.replaceAll(addrPath, "");
        getMethod = new GetMethod(addr);

        httpClient.executeMethod(getMethod);
        StorageProperties.enableSnapshots = true;
    } catch (Exception ex) {
        LOG.error("Could not connect to Walrus. Snapshot functionality disabled. Please check the Walrus url.");
        StorageProperties.enableSnapshots = false;
    } finally {
        if (getMethod != null)
            getMethod.releaseConnection();
    }
}

From source file:com.linkedin.cubert.ScriptExecutor.java

/**
 * Properties are collected in the following order--
 * <p/>//from ww  w.  ja  va 2 s  .  c o m
 * 1. Azkaban (or other) executor params
 * 2. properties passed through -f argument (for multiple order in CLI order)
 * 3. properties passed as -D arguments directly on CLI
 *
 * @param cmdLine
 * @param executorProps
 * @return
 * @throws URISyntaxException
 * @throws IOException
 */
private static Properties getProperties(CommandLine cmdLine, Properties executorProps)
        throws URISyntaxException, IOException {
    Properties props = new Properties();

    // 1. Substitute executor params
    if (executorProps != null) {
        props.putAll(extractCubertParams(executorProps));
    }

    // 2. -f properties
    String[] propFiles = cmdLine.getOptionValues("f");
    if (propFiles != null && propFiles.length > 0) {
        for (String propFile : propFiles) {
            URI uri = new URI(propFile);
            boolean isHDFS = (uri.getScheme() != null) && uri.getScheme().equalsIgnoreCase("hdfs");
            String path = uri.getPath();
            if (isHDFS) {
                props.load(new BufferedReader(
                        new InputStreamReader(FileSystem.get(new JobConf()).open(new Path(path)))));
            } else {
                props.load(new BufferedReader(new FileReader(path)));
            }
        }
    }

    // 3. -D properties
    if (cmdLine.getOptionProperties("D").size() > 0) {
        props.putAll(cmdLine.getOptionProperties("D"));
    }
    return props;
}

From source file:com.microsoft.azure.hdinsight.jobs.JobViewDummyHttpServer.java

@Nullable
private static RequestDetail getRequestDetail(@NotNull URI myUrl) {
    String[] queries = myUrl.getQuery() == null ? null : myUrl.getQuery().split("&");
    String path = myUrl.getPath();
    Matcher matcher = clusterPattern.matcher(path);
    if (matcher.find()) {
        requestDetail = new RequestDetail(matcher.group(1), matcher.group(2), queries);
        return requestDetail;
    }/*w w  w .  j a v a  2 s .com*/
    return null;
}

From source file:de.shadowhunt.subversion.internal.URIUtils.java

private static URI createURI0(final URI repository, final Resource... resources) throws URISyntaxException {
    final URIBuilder builder = new URIBuilder();
    builder.setScheme(repository.getScheme());
    builder.setHost(repository.getHost());
    builder.setPort(repository.getPort());
    final StringBuilder completePath = new StringBuilder(repository.getPath());
    for (final Resource resource : resources) {
        completePath.append(resource.getValue());
    }/*from   w ww . j ava2  s  .com*/
    builder.setPath(completePath.toString());
    return builder.build();
}

From source file:edu.stanford.junction.JunctionMaker.java

public static String getSessionIDFromURI(URI uri) {
    try {//from   w w  w.j  a  v a2s  .  com
        return uri.getPath().substring(1);
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static boolean isURI(String str) {

    if (str.indexOf(':') == -1)
        return false;
    str = str.toLowerCase(Locale.ENGLISH).trim();

    if (!str.startsWith("http://") && !str.startsWith("https://") && !str.startsWith("ftp://"))
        return false;

    try {/*from w w w .  ja  v  a 2 s. co  m*/

        URI uri = new URI(str);
        String proto = uri.getScheme();

        if (proto == null)
            return false;

        if (proto.equals("http") || proto.equals("https") || proto.equals("ftp")) {

            if (uri.getHost() == null)
                return false;

            String path = uri.getPath();
            if (path != null) {

                int len = path.length();
                for (int i = 0; i < len; i++) {

                    if ("?<>:*|\"".indexOf(path.charAt(i)) > -1)
                        return false;
                }
            }
        }

        return true;
    } catch (Exception ex) {

        return false;
    }
}

From source file:org.kurento.test.services.KurentoServicesTestHelper.java

public static KurentoControlServerManager startKurentoControlServer(String wsUriProp) {

    JsonRpcClient client = KurentoClientTestFactory.createJsonRpcClient("kcs");

    try {/* w  w w . ja  v a  2 s. c om*/

        URI wsUri = new URI(wsUriProp);
        int port = wsUri.getPort();
        String path = wsUri.getPath();
        kcs = new KurentoControlServerManager(client, port, path);

        return kcs;

    } catch (URISyntaxException e) {
        throw new KurentoException(KCS_WS_URI_PROP + " invalid format: " + wsUriProp);
    }
}

From source file:org.projecthdata.social.api.connect.HDataServiceProvider.java

private static StringBuilder getBaseUrl(String ehrUrl) {
    URI uri = URIBuilder.fromUri(ehrUrl).build();
    StringBuilder builder = new StringBuilder();
    builder.append(uri.getScheme()).append("://");
    builder.append(uri.getHost());/*from  w ww.  j a va  2s .c  o m*/
    if (uri.getPort() >= 0) {
        builder.append(":").append(uri.getPort());
    }
    if (uri.getPath() != null) {
        StringTokenizer tokenizer = new StringTokenizer(uri.getPath(), "/");
        // if there is more than one path element, then the first one should
        // be the webapp name
        if (tokenizer.countTokens() > 1) {
            builder.append("/").append(tokenizer.nextToken());
        }
    }
    return builder;
}

From source file:io.lavagna.config.DataSourceConfig.java

/**
 * for supporting heroku style url:/*from  www .  j av  a 2 s  . c  om*/
 *
 * <pre>
 * [database type]://[username]:[password]@[host]:[port]/[database name]
 * </pre>
 *
 * @param dataSource
 * @param env
 * @throws URISyntaxException
 */
private static void urlWithCredentials(HikariDataSource dataSource, Environment env) throws URISyntaxException {
    URI dbUri = new URI(env.getRequiredProperty("datasource.url"));
    dataSource.setUsername(dbUri.getUserInfo().split(":")[0]);
    dataSource.setPassword(dbUri.getUserInfo().split(":")[1]);
    dataSource.setJdbcUrl(
            String.format("%s://%s:%s%s", scheme(dbUri), dbUri.getHost(), dbUri.getPort(), dbUri.getPath()));
}

From source file:com.eucalyptus.blockstorage.BlockStorageChecker.java

public static void checkWalrusConnection() {
    HttpClient httpClient = new HttpClient();
    GetMethod getMethod = null;//from w ww .  j av  a2  s . c  o m
    try {
        java.net.URI addrUri = new URL(StorageProperties.WALRUS_URL).toURI();
        String addrPath = addrUri.getPath();
        String addr = StorageProperties.WALRUS_URL.replaceAll(addrPath, "");
        getMethod = new GetMethod(addr);

        httpClient.executeMethod(getMethod);
        StorageProperties.enableSnapshots = true;
    } catch (Exception ex) {
        LOG.error(
                "Could not connect to ObjectStorage. Snapshot functionality disabled. Please check the ObjectStorage url.");
        StorageProperties.enableSnapshots = false;
    } finally {
        if (getMethod != null)
            getMethod.releaseConnection();
    }
}