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:org.fao.geonet.utils.AbstractHttpRequest.java

protected String getSentData(HttpRequestBase httpMethod) {
    URI uri = httpMethod.getURI();
    StringBuilder sentData = new StringBuilder(httpMethod.getMethod()).append(" ").append(uri.getPath());

    if (uri.getQuery() != null) {
        sentData.append("?" + uri.getQuery());
    }//  w w  w.ja  v  a2  s.c  om

    sentData.append("\r\n");

    for (Header h : httpMethod.getAllHeaders()) {
        sentData.append(h);
    }

    sentData.append("\r\n");

    if (httpMethod instanceof HttpPost) {
        sentData.append(postData);
    }

    return sentData.toString();
}

From source file:io.jmnarloch.spring.cloud.discovery.DiscoveryClientPropertySource.java

/**
 * Expands the service URI./*  w ww.  j av a 2 s.co  m*/
 *
 * @param uri the input uri
 * @return the result uri
 */
private URI expandUri(String uri) {
    try {
        final URI inputUri = URI.create(uri);
        final ServiceInstance serviceInstance = findOneService(inputUri.getHost());
        if (serviceInstance == null) {
            return null;
        }
        return new URI((serviceInstance.isSecure() ? "https" : "http"), inputUri.getUserInfo(),
                serviceInstance.getHost(), serviceInstance.getPort(), inputUri.getPath(), inputUri.getQuery(),
                inputUri.getFragment());
    } catch (URISyntaxException e) {
        logger.error("Unexpected error occurred when expanding the property URI", e);
        throw new RuntimeException("Could not parse URI value: " + uri, e);
    }
}

From source file:leap.webunit.client.THttpRequestImpl.java

protected String buildRequestUrl() {
    String url = null;//from   w  w  w  .  j av a 2 s  .  com

    if (Strings.isEmpty(uri)) {
        url = tclient.getBaseUrl();
    } else if (uri.indexOf("://") > 0) {
        url = uri;
    } else if (Strings.startsWith(uri, "/")) {
        url = tclient.getBaseUrl() + uri;
    } else {
        url = tclient.getBaseUrl() + "/" + uri;
    }

    if (!queryString.isEmpty()) {
        url = Urls.appendQueryString(url, queryString.build());
    }

    URI uri = URI.create(url);
    String path = uri.getPath();
    if (!"".equals(path)) {
        for (String contextPath : tclient.getContextPaths()) {
            if (path.equals(contextPath)) {
                url = uri.getScheme() + ":" + uri.getSchemeSpecificPart() + "/";
                if (null != uri.getQuery()) {
                    url = url + "?" + uri.getRawQuery();
                }
                break;
            }
        }
    }

    return url;
}

From source file:org.soyatec.windowsazure.authenticate.SharedKeyCredentialsWrapper.java

/**
 * Replace the uri container name.//from  ww  w. ja v a  2s .c om
 * 
 * @param uri
 * @param containerName
 * @return The uri after be replaced the container name with the input
 *         containerName.
 */
private URI replaceContainerName(URI uri, String containerName) {
    if (containerName == null) {
        return uri;
    }
    try {
        String host = uri.getPath();
        String[] temp = host.split("/");
        temp[0] = containerName;
        return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), join("/", temp),
                (uri.getQuery() == null ? Utilities.emptyString() : uri.getQuery()), uri.getFragment());
    } catch (URISyntaxException e) {
        Logger.error("", e);
    }
    return uri;
}

From source file:org.eclipse.orion.server.git.objects.Status.java

private URI statusToIndexLocation(URI u) throws URISyntaxException {
    String uriPath = u.getPath();
    String prefix = uriPath.substring(0, uriPath.indexOf(GitServlet.GIT_URI));
    uriPath = uriPath.substring(prefix.length() + (GitServlet.GIT_URI + '/' + Status.RESOURCE).length());
    uriPath = prefix + GitServlet.GIT_URI + '/' + Index.RESOURCE + uriPath;
    return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), uriPath, u.getQuery(),
            u.getFragment());// ww w.j  a v a2  s.  c o m
}

From source file:com.vp9.plugin.WebSocket.java

/**
 * Create the uri./*from   w  w  w  . j  a v a 2  s.co  m*/
 * @param uriString
 * @return
 * @throws URISyntaxException
 */
private URI createURI(String uriString) throws URISyntaxException {
    URI uri = new URI(uriString);
    int port = uri.getPort();

    if (port == -1) {
        if ("ws".equals(uri.getScheme())) {
            port = 80;
        } else if ("wss".equals(uri.getScheme())) {
            port = 443;
        }
        uri = URIUtils.createURI(uri.getScheme(), uri.getHost(), port, uri.getPath(), uri.getQuery(),
                uri.getFragment());
    }
    return uri;
}

From source file:com.pemikir.youtubeplus.youtube.YoutubeExtractor.java

@Override
public String getVideoId(String videoUrl) {
    try {/*from   www  . j  a v a2 s .co m*/
        URI uri = new URI(videoUrl);
        if (uri.getHost().contains("youtube")) {
            String query = uri.getQuery();
            String queryElements[] = query.split("&");
            Map<String, String> queryArguments = new HashMap<>();
            for (String e : queryElements) {
                String[] s = e.split("=");
                queryArguments.put(s[0], s[1]);
            }
            return queryArguments.get("v");
        } else if (uri.getHost().contains("youtu.be")) {
            // uri.getRawPath() does somehow not return the last character.
            // so we do a workaround instead.
            //return uri.getRawPath();
            String url[] = videoUrl.split("/");
            return url[url.length - 1];
        } else {
            Log.e(TAG, "Error could not parse url: " + videoUrl);

        }
    } catch (Exception e) {
        Log.e(TAG, "Error could not parse url: " + videoUrl);
        e.printStackTrace();
        return "";
    }
    return null;
}

From source file:org.jvoicexml.interpreter.grammar.GrammarLoader.java

/**
 * Take the route of processing an external grammar.
 *
 * @param context//ww w.ja  v a 2  s  . c  o m
 *            The current context
 * @param attributes
 *            attributes governing the fetch.
 * @param grammar
 *            The grammar to be processed.
 *
 * @return Is just the string representation of the grammar as well as the
 *         type.
 *
 * @throws UnsupportedFormatError
 *             If an unsupported grammar has to be processed.
 * @throws BadFetchError
 *             If the document could not be fetched successfully.
 * @throws SemanticError
 *             if the srcexpr attribute could not be evaluated
 * @exception URISyntaxException
 *                if the URI of the external grammar could not be resolved
 */
private GrammarDocument loadExternalGrammar(final VoiceXmlInterpreterContext context,
        final FetchAttributes attributes, final Grammar grammar)
        throws BadFetchError, UnsupportedFormatError, SemanticError, URISyntaxException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("loading external grammar");
    }

    // First of all, we need to check, if user has provided any
    // grammar type.
    URI src = getExternalUriSrc(grammar, context);
    if (src.getFragment() != null) {
        // TODO add support for URI fragments
        LOGGER.warn("URI fragments are currently not supported: " + "ignoring fragment");
        src = new URI(src.getScheme(), src.getUserInfo(), src.getHost(), src.getPort(), src.getPath(),
                src.getQuery(), null);
    }

    // Now load the grammar
    LOGGER.info("loading grammar from source: '" + src + "'");
    final FetchAttributes adaptedAttributes = adaptFetchAttributes(attributes, grammar);
    final GrammarDocument document = context.acquireExternalGrammar(src, adaptedAttributes);
    if (document == null) {
        throw new BadFetchError("Unable to load grammar '" + src + "'!");
    }
    return document;
}

From source file:com.vmware.photon.controller.deployer.xenon.task.RegisterAuthClientTaskService.java

/**
 * This method modifies a URI by removing a set of query parameters from the URI and editing the scope parameter to
 * include ID_GROUPS. The parameters that are removed are session related and will be set by the UI as needed.
 *//*from   w w w. ja  v  a  2s. co m*/
private String parseURL(String url, String[] removeParams) throws URISyntaxException {
    if (StringUtils.isBlank(url)) {
        return url;
    }

    // Get the query parameters from the URL and return if empty
    URI uri = new URI(url);
    String urlQuery = uri.getQuery();
    if (StringUtils.isBlank(urlQuery)) {
        return url;
    }

    // Remove the query parameters specified in removeParams
    List<String> queryParams = Arrays.asList(urlQuery.split("&"));
    queryParams = queryParams.stream().filter(param -> {
        for (String removeParam : removeParams) {
            if (param.startsWith(removeParam + "=")) {
                return false;
            }
        }
        return true;
    }).collect(Collectors.toList());

    // Edit the scope query parameter to add id_groups to it. id_groups requests that the groups from the id token are
    // included.
    for (String parameter : queryParams) {
        if (parameter.startsWith(SCOPE + "=")) {
            queryParams.set(queryParams.indexOf(parameter), parameter + "+" + ID_GROUPS);
        }
    }

    // Append the modified query parameters to the base URL and return the new URL
    String baseUrl = url.split("\\?")[0];
    if (queryParams.size() > 0) {
        baseUrl = baseUrl + "?" + StringUtils.join(queryParams, "&");
    }
    return baseUrl;
}

From source file:org.eclipse.orion.server.git.objects.Status.java

private URI statusToCommitLocation(URI u, String ref) throws URISyntaxException {
    String uriPath = u.getPath();
    String prefix = uriPath.substring(0, uriPath.indexOf(GitServlet.GIT_URI));
    uriPath = uriPath.substring(prefix.length() + (GitServlet.GIT_URI + '/' + Status.RESOURCE).length());
    uriPath = prefix + GitServlet.GIT_URI + '/' + Commit.RESOURCE + '/' + ref + uriPath;
    return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), uriPath, u.getQuery(),
            u.getFragment());/*from ww  w  .  j  a va 2s  .c om*/
}