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:ru.bozaro.protobuf.client.ProtobufClient.java

@NotNull
public static URI prepareUrl(@NotNull URI url) {
    final String path = url.getPath();
    return path == null || path.endsWith("/") ? url : url.resolve(path + "/");
}

From source file:com.github.tomakehurst.wiremock.common.UniqueFilenameGenerator.java

private static String getRandomId(final String prefix, final String id, final URI uri) {
    Iterable<String> uriPathNodes = on("/").omitEmptyStrings().split(uri.getPath());
    int nodeCount = size(uriPathNodes);

    String pathPart = nodeCount > 0
            ? Joiner.on("-").join(from(uriPathNodes).skip(nodeCount - min(nodeCount, 2)))
            : "(root)";

    return new StringBuilder(prefix).append("-").append(pathPart).append("-").append(id).append(".json")
            .toString();/*from   w  w  w.java  2 s . com*/
}

From source file:com.github.tomakehurst.wiremock.common.SafeNames.java

public static String makeSafeFileName(StubMapping mapping, String extension) {
    String suffix = "-" + mapping.getId() + "." + extension;
    if (isNotEmpty(mapping.getName())) {
        return makeSafeName(mapping.getName()) + suffix;
    }/*ww  w  .j  a v a 2s .  c o m*/

    UrlPattern urlMatcher = mapping.getRequest().getUrlMatcher();

    if (urlMatcher.getPattern() instanceof AnythingPattern) {
        return suffix.substring(1);
    }

    String expectedUrl = urlMatcher.getExpected();
    URI uri = URI.create(sanitise(expectedUrl));
    return makeSafeNameFromUrl(uri.getPath()) + suffix;
}

From source file:io.syndesis.credential.BaseCredentialProvider.java

protected static String callbackUrlFor(final URI baseUrl,
        final MultiValueMap<String, String> additionalParams) {
    final String path = baseUrl.getPath();

    final String callbackPath = path + "credentials/callback";

    try {/*from   w  ww .j  a v a 2  s  .  com*/
        final URI base = new URI(baseUrl.getScheme(), null, baseUrl.getHost(), baseUrl.getPort(), callbackPath,
                null, null);

        return UriComponentsBuilder.fromUri(base).queryParams(additionalParams).build().toUriString();
    } catch (final URISyntaxException e) {
        throw new IllegalStateException("Unable to generate callback URI", e);
    }
}

From source file:com.google.mr4c.content.RelativeContentFactory.java

public static String toRelativeFilePath(File file, File ancestor) {
    checkRelated(file, ancestor);/*from w  ww.  ja  va2 s .  c  o  m*/
    URI fileUri = file.toURI();
    URI ancestorUri = ancestor.toURI();
    URI relativeUri = ancestorUri.relativize(fileUri);
    return relativeUri.getPath();
}

From source file:me.zhuoran.amoeba.netty.server.http.HttpRequestHandler.java

/**
 * sanitize url/*  ww  w  .j a  v  a 2 s .c om*/
 * @param uri
 * @return
 * @throws URISyntaxException
 */
public static String sanitizeUri(String uri) throws URISyntaxException {
    try {
        uri = URLDecoder.decode(uri, "UTF-8");
    } catch (UnsupportedEncodingException var4) {
        try {
            uri = URLDecoder.decode(uri, "ISO-8859-1");
        } catch (UnsupportedEncodingException var3) {
            throw new Error();
        }
    }

    if (!uri.startsWith("/")) {
        return null;
    } else {
        URI uriObject = new URI(uri);

        for (uri = uriObject.getPath(); uri != null && uri.startsWith("/"); uri = uri.substring(1)) {
        }

        return uri.toLowerCase();
    }
}

From source file:com.twitter.distributedlog.client.serverset.DLZkServerSet.java

public static DLZkServerSet of(URI uri, int zkSessionTimeoutMs) {
    // Create zookeeper and server set
    String zkPath = uri.getPath() + "/" + ZNODE_WRITE_PROXY;
    Iterable<InetSocketAddress> zkAddresses = getZkAddresses(uri);
    ZooKeeperClient zkClient = new ZooKeeperClient(Amount.of(zkSessionTimeoutMs, Time.MILLISECONDS),
            zkAddresses);/* w  w  w  . j  a v  a2s .  c o m*/
    ServerSet serverSet = ServerSets.create(zkClient, ZooDefs.Ids.OPEN_ACL_UNSAFE, zkPath);
    return new DLZkServerSet(zkClient, serverSet);
}

From source file:at.bitfire.davdroid.URIUtils.java

/**
 * Parse a received absolute/relative URL and generate a normalized URI that can be compared.
 * @param original       URI to be parsed, may be absolute or relative
  * @param mustBePath    true if it's known that original is a path (may contain ":") and not an URI, i.e. ":" is not the scheme separator
 * @return             normalized URI/*from  w ww  .  j  a v  a  2s.c  o m*/
 * @throws URISyntaxException
 */
public static URI parseURI(String original, boolean mustBePath) throws URISyntaxException {
    if (mustBePath) {
        // may contain ":"
        // case 1: "my:file"        won't be parsed by URI correctly because it would consider "my" as URI scheme
        // case 2: "path/my:file"   will be parsed by URI correctly
        // case 3: "my:path/file"   won't be parsed by URI correctly because it would consider "my" as URI scheme
        int idxSlash = original.indexOf('/'), idxColon = original.indexOf(':');
        if (idxColon != -1) {
            // colon present
            if ((idxSlash != -1) && idxSlash < idxColon) // There's a slash, and it's before the colon  everything OK
                ;
            else // No slash before the colon; we have to put it there
                original = "./" + original;
        }
    }

    // escape some common invalid characters  servers keep sending unescaped crap like "my calendar.ics" or "{guid}.vcf"
    // this is only a hack, because for instance, "[" may be valid in URLs (IPv6 literal in host name)
    String repaired = original.replaceAll(" ", "%20").replaceAll("\\{", "%7B").replaceAll("\\}", "%7D");
    if (!repaired.equals(original))
        Log.w(TAG, "Repaired invalid URL: " + original + " -> " + repaired);

    URI uri = new URI(repaired);
    URI normalized = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(),
            uri.getFragment());
    Log.v(TAG, "Normalized URL " + original + " -> " + normalized.toASCIIString());
    return normalized;
}

From source file:io.gravitee.gateway.standalone.DynamicRoutingGatewayTest.java

private static URI create(URI uri, int port) {
    try {//from  w  ww  .j a  v  a 2  s . co m
        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), port, uri.getPath(), uri.getQuery(),
                uri.getFragment());
    } catch (URISyntaxException e) {
        return uri;
    }
}

From source file:NioHttpClient.java

public static String uriForRequest(URI u) {
    if (null == u.getQuery()) {
        return u.getPath();
    } else {// ww w  .  j  a v a2 s .  c  om
        int n = u.getPath().length() + u.getQuery().length() + 1;
        StringBuilder b = new StringBuilder(n);
        b.append(u.getPath()).append('?').append(u.getQuery());
        return b.toString();
    }
}