Example usage for java.net URI getQuery

List of usage examples for java.net URI getQuery

Introduction

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

Prototype

public String getQuery() 

Source Link

Document

Returns the decoded query component of this URI.

Usage

From source file:com.vmware.photon.controller.common.auth.AuthClientHandler.java

/**
 * Replace the id_token part in logout URL with placeholder.
 *
 * @param logoutUri//  w w  w .  ja v  a  2  s. co  m
 * @throws AuthException
 */
public static URI replaceIdTokenWithPlaceholder(URI logoutUri)
        throws IllegalArgumentException, URISyntaxException, UnsupportedEncodingException {
    String placeholderValue = "";
    String keyToMatch = URLDecoder.decode(LOGOUT_URL_ID_TOKEN_START, "UTF-8");
    final String urlQuery = logoutUri.getQuery();

    if (urlQuery == null) {
        throw new IllegalArgumentException(
                String.format("Logout URL %s has invalid format", logoutUri.toString()));
    }

    final String[] queryParams = urlQuery.split("&");

    for (String param : queryParams) {
        final String[] pairs = param.split("=");
        if (pairs[0].equals(keyToMatch)) {
            placeholderValue = pairs[1];
            break;
        }
    }

    if (placeholderValue == "") {
        throw new IllegalArgumentException(
                String.format("Logout URL %s has invalid format", logoutUri.toString()));
    }

    String logoutStr = logoutUri.toString();
    return new URI(logoutStr.replace(placeholderValue, LOGOUT_URL_ID_TOKEN_PLACEHOLDER));
}

From source file:URISupport.java

public static URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException {
    return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(),
            bindAddr.getQuery(), bindAddr.getFragment());
}

From source file:com.google.caja.precajole.StaticPrecajoleMap.java

public static String normalizeUri(String uri) {
    try {//from  w ww.  ja v a 2  s . c  o  m
        URI u = new URI(uri).normalize();
        if (u.getHost() != null) {
            u = new URI(lowercase(u.getScheme()), u.getUserInfo(), lowercase(u.getHost()), u.getPort(),
                    u.getPath(), u.getQuery(), u.getFragment());
        } else if (u.getScheme() != null) {
            u = new URI(lowercase(u.getScheme()), u.getSchemeSpecificPart(), u.getFragment());
        }
        return u.toString();
    } catch (URISyntaxException e) {
        return uri;
    }
}

From source file:org.hl7.fhir.client.ResourceAddress.java

public static URI appendHttpParameters(URI basePath, Map<String, String> parameters) {
    try {/*from w  w w  .j  a  v a2s. c  o m*/
        Set<String> httpParameterNames = parameters.keySet();
        String query = basePath.getQuery();

        for (String httpParameterName : httpParameterNames) {
            if (query != null) {
                query += "&";
            } else {
                query = "";
            }
            query += httpParameterName + "=" + parameters.get(httpParameterName);
        }

        return new URI(basePath.getScheme(), basePath.getUserInfo(), basePath.getHost(), basePath.getPort(),
                basePath.getPath(), query, basePath.getFragment());
    } catch (Exception e) {
        throw new EFhirClientException("Error appending http parameter", e);
    }
}

From source file:org.apache.hadoop.fs.s3native.S3xLoginHelper.java

/**
 * Canonicalize the given URI.//w  w  w .j av  a  2  s.c o  m
 *
 * This strips out login information.
 *
 * @return a new, canonicalized URI.
 */
public static URI canonicalizeUri(URI uri, int defaultPort) {
    if (uri.getPort() == -1 && defaultPort > 0) {
        // reconstruct the uri with the default port set
        try {
            uri = new URI(uri.getScheme(), null, uri.getHost(), defaultPort, uri.getPath(), uri.getQuery(),
                    uri.getFragment());
        } catch (URISyntaxException e) {
            // Should never happen!
            throw new AssertionError("Valid URI became unparseable: " + uri);
        }
    }

    return uri;
}

From source file:org.apache.hadoop.hive.ql.exec.ArchiveUtils.java

/**
 * Makes sure, that URI points to directory by adding slash to it.
 * Useful in relativizing URIs.//from  w w w .jav a2  s .  c  o  m
 */
public static URI addSlash(URI u) throws HiveException {
    if (u.getPath().endsWith("/")) {
        return u;
    } else {
        try {
            return new URI(u.getScheme(), u.getAuthority(), u.getPath() + "/", u.getQuery(), u.getFragment());
        } catch (URISyntaxException e) {
            throw new HiveException("Couldn't append slash to a URI", e);
        }
    }
}

From source file:com.bazaarvoice.seo.sdk.util.BVUtility.java

public static String removeBVParameters(String url) {
    String newUrl = url;//w  ww .  j av  a2s.  co m
    if (newUrl.contains("bvstate=")) {
        // Handle usecase with more parameters after bvstate
        newUrl = newUrl.replaceAll(BVConstant.BVSTATE_REGEX_WITH_TRAILING_SEPARATOR, "");

        // Handle usecase where bvstate is the last parameter
        if (newUrl.endsWith("?") | newUrl.endsWith("&")) {
            newUrl = newUrl.substring(0, newUrl.length() - 1);
        }
        if (newUrl.endsWith(BVConstant.ESCAPED_FRAGMENT_MULTIVALUE_SEPARATOR)) {
            newUrl = newUrl.substring(0, newUrl.length() - 3);
        }
    }

    if (hasBVQueryParameters(newUrl)) {
        final URI uri;
        try {
            uri = new URI(newUrl);
        } catch (URISyntaxException e) {
            return newUrl;
        }

        try {
            String newQuery = null;
            if (uri.getQuery() != null && uri.getQuery().length() > 0) {
                List<NameValuePair> newParameters = new ArrayList<NameValuePair>();
                List<NameValuePair> parameters = URLEncodedUtils.parse(uri.getQuery(),
                        Charset.forName("UTF-8"));
                for (NameValuePair parameter : parameters) {
                    if (!bvQueryParameters.contains(parameter.getName())) {
                        newParameters.add(parameter);
                    }
                }
                newQuery = newParameters.size() > 0
                        ? URLEncodedUtils.format(newParameters, Charset.forName("UTF-8"))
                        : null;
            }

            return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), newQuery, null).toString();
        } catch (URISyntaxException e) {
            return newUrl;
        }
    }
    return newUrl;
}

From source file:mitm.common.util.URIUtils.java

/**
 * Checks whether the given identifier is a valid URI. If type is null, a FULL check will be done.
 * If identifier is null, false will be returned.
 *//*www  .j a va  2  s  .  co m*/
public static boolean isValidURI(String identifier, URIType type) {
    if (identifier == null) {
        return false;
    }

    if (type == null) {
        type = URIType.FULL;
    }

    boolean valid = false;

    try {
        URI uri = new URI(identifier);

        if (type == URIType.BASE) {
            /*
             * Only accepts URI of the form [scheme:][//authority][path]
             */
            if (StringUtils.isNotEmpty(uri.getScheme()) && StringUtils.isNotEmpty(uri.getHost())
                    && StringUtils.isEmpty(uri.getQuery()) && StringUtils.isEmpty(uri.getFragment())) {
                valid = true;
            }
        } else if (type == URIType.RELATIVE) {
            /*
             * Only accepts URI of the form [path][?query][#fragment] 
             */
            if (StringUtils.isEmpty(uri.getScheme()) && StringUtils.isEmpty(uri.getAuthority())
                    && StringUtils.isEmpty(uri.getHost())) {
                valid = true;
            }
        } else if (type == URIType.FULL) {
            /*
             * Only accepts URI of the form [scheme:][//authority][path][?query][#fragment] 
             */
            if (StringUtils.isNotEmpty(uri.getScheme()) && StringUtils.isNotEmpty(uri.getHost())) {
                valid = true;
            }
        } else {
            valid = true;
        }

    } catch (URISyntaxException e) {
        // ignore
    }

    return valid;
}

From source file:org.eclipse.orion.server.servlets.JsonURIUnqualificationStrategy.java

protected static URI unqualifyURI(URI uri, String scheme, String hostname, int port) {
    URI simpleURI = uri;/* ww w. j ava2  s. c om*/
    int uriPort = uri.getPort();
    if (uriPort == -1) {
        uriPort = getDefaultPort(uri.getScheme());
    }
    if (scheme.equals(uri.getScheme()) && hostname.equals(uri.getHost()) && port == uriPort) {
        try {
            simpleURI = new URI(null, null, null, -1, uri.getPath(), uri.getQuery(), uri.getFragment());
        } catch (URISyntaxException e) {
            simpleURI = uri;
        }
    }
    return simpleURI;
}

From source file:org.sakaiproject.mediasite.tool.MediasiteContentLaunch.java

public static URI getRootPath(URI baseUri) throws URISyntaxException {
    URI uri = new URI(baseUri.getScheme(), null, baseUri.getHost(), baseUri.getPort(),
            baseUri.getPath() + WebApiConstants.SONICFOUNDRY_WEB_API_PATH.value(), baseUri.getQuery(),
            baseUri.getFragment());/*from ww w.  j  a  v  a 2s.c  o  m*/
    return uri;
}