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:de.ii.xtraplatform.ogc.api.WFS.java

public static String cleanUrl(String url) {
    try {/*from  w w  w.  j  av  a  2  s .c  om*/
        URI inUri = new URI(url.trim());
        URIBuilder outUri = new URIBuilder(inUri).removeQuery();

        if (inUri.getQuery() != null && !inUri.getQuery().isEmpty()) {
            for (String inParam : inUri.getQuery().split("&")) {
                String[] param = inParam.split("=");
                if (!WFS.hasKVPKey(param[0].toUpperCase())) {
                    if (param.length >= 2)
                        outUri.addParameter(param[0], param[1]);
                    else
                        System.out.println("SINGLE " + param[0]);
                }
            }
        }

        return outUri.toString();
    } catch (URISyntaxException ex) {
        return url;
    }
}

From source file:org.wrml.runtime.rest.RestUtils.java

public static final SortedSet<Parameter> extractUriQueryParameters(final URI uri) {

    if (uri == null) {
        return null;
    }//from w  w  w.j  a v a2 s .  c o  m

    final String queryPart = uri.getQuery();
    if (queryPart == null || queryPart.isEmpty()) {
        return null;
    }

    final List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(uri, DEFAULT_ENCODING);
    if (nameValuePairs == null) {
        return null;
    }

    final SortedSet<Parameter> queryParameters = new TreeSet<Parameter>();
    for (final NameValuePair nameValuePair : nameValuePairs) {
        final Parameter parameter = new Parameter(nameValuePair.getName(), nameValuePair.getValue());
        queryParameters.add(parameter);
    }

    return queryParameters;
}

From source file:org.esigate.util.UriUtils.java

/**
 * Removes the server information frome a {@link URI}.
 * /*  ww w .jav  a  2s . c  om*/
 * @param uri
 *            the {@link URI}
 * @return a new {@link URI} with no scheme, host and port
 */
public static URI removeServer(URI uri) {
    try {
        return new URI(null, null, null, -1, uri.getPath(), uri.getQuery(), uri.getFragment());
    } catch (URISyntaxException e) {
        throw new InvalidUriException(e);
    }

}

From source file:org.apache.hadoop.yarn.server.webproxy.ProxyUriUtils.java

/**
 * Get a proxied URI for the original URI.
 * @param originalUri the original URI to go through the proxy, or null if
 * a default path "/" can be used. /*w  ww  . j a  va  2s  . c o  m*/
 * @param proxyUri the URI of the proxy itself, scheme, host and port are used.
 * @param id the id of the application
 * @return the proxied URI
 */
public static URI getProxyUri(URI originalUri, URI proxyUri, ApplicationId id) {
    try {
        String path = getPath(id, originalUri == null ? "/" : originalUri.getPath());
        return new URI(proxyUri.getScheme(), proxyUri.getAuthority(), path,
                originalUri == null ? null : originalUri.getQuery(),
                originalUri == null ? null : originalUri.getFragment());
    } catch (URISyntaxException e) {
        throw new RuntimeException("Could not proxify " + originalUri, e);
    }
}

From source file:com.vmware.identity.openidconnect.protocol.URIUtils.java

public static boolean areEqual(URI lhs, URI rhs) {
    Validate.notNull(lhs, "lhs");
    Validate.notNull(rhs, "rhs");

    URI lhsCopy;//  w ww.  j a  va2 s .c  o  m
    URI rhsCopy;
    try {
        lhsCopy = new URI(lhs.getScheme(), lhs.getUserInfo(), lhs.getHost(), URIUtils.getPort(lhs),
                lhs.getPath(), lhs.getQuery(), lhs.getFragment());
        rhsCopy = new URI(rhs.getScheme(), rhs.getUserInfo(), rhs.getHost(), URIUtils.getPort(rhs),
                rhs.getPath(), rhs.getQuery(), rhs.getFragment());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("failed to transform uri for equality check", e);
    }

    return lhsCopy.equals(rhsCopy);
}

From source file:org.wso2.carbon.dataservices.core.description.config.GSpreadConfig.java

public static String extractKey(String documentURL) throws DataServiceFault {
    URI documentURI;
    try {//from  w  ww .  j a v a  2 s.  c om
        documentURI = new URI(documentURL);
    } catch (URISyntaxException e) {
        String message = "Document URL Syntax error:" + documentURL;
        log.warn(message, e);
        throw new DataServiceFault(e, message);
    }
    String extractedQuery = documentURI.getQuery();
    if (extractedQuery == null) {
        return getKeyForNewSpreadsheetURLFormat(documentURL);
    }
    int i1 = extractedQuery.lastIndexOf("key=");
    int i2 = extractedQuery.indexOf("&", i1);
    if (i1 == -1) {
        return getKeyForNewSpreadsheetURLFormat(documentURL);
    } else if (i2 < 0) {
        return extractedQuery.substring(i1 + 4);
    } else {
        return extractedQuery.substring(i1 + 4, i2);
    }
}

From source file:de.ii.xtraplatform.ogc.csw.client.CSWAdapter.java

public static URI parseAndCleanWfsUrl(String url) throws URISyntaxException {
    URI inUri = new URI(url.trim());
    URIBuilder outUri = new URIBuilder(inUri).removeQuery();

    if (inUri.getQuery() != null && !inUri.getQuery().isEmpty()) {
        for (String inParam : inUri.getQuery().split("&")) {
            String[] param = inParam.split("=");
            if (!CSW.hasKVPKey(param[0].toUpperCase())) {
                outUri.addParameter(param[0], param[1]);
            }// w w  w .j  a  v a2 s .co  m
        }
    }

    return outUri.build();
}

From source file:org.xenmaster.web.VNCHook.java

protected static String buildHttpConnect(URI uri) {
    StringBuilder sb = new StringBuilder();
    sb.append("CONNECT ");
    sb.append(uri.getPath()).append('?').append(uri.getQuery());
    sb.append(" HTTP/1.1").append("\r\n");
    sb.append("Cookie: session_id=").append(Controller.getSession().getReference());
    sb.append("\r\n\r\n");
    return sb.toString();
}

From source file:com.ibm.jaggr.core.util.PathUtil.java

public static URI stripJsExtension(URI value) throws URISyntaxException {
    if (value == null) {
        return null;
    }//from w ww  .  j  a  v a2s.c  om
    return value.getPath().endsWith(".js") ? //$NON-NLS-1$
            new URI(value.getScheme(), value.getAuthority(),
                    value.getPath().substring(0, value.getPath().length() - 3), value.getQuery(),
                    value.getFragment())
            : value;
}

From source file:com.knowledgecode.cordova.websocket.ConnectionTask.java

/**
 * Complement default port number./* w  w  w.j a v  a  2  s .  c  om*/
 *
 * @param url
 * @return URI
 * @throws URISyntaxException
 */
private static URI complementPort(String url) throws URISyntaxException {
    URI uri = new URI(url);
    int port = uri.getPort();

    if (port < 0) {
        if ("ws".equals(uri.getScheme())) {
            port = 80;
        } else if ("wss".equals(uri.getScheme())) {
            port = 443;
        }
        uri = new URI(uri.getScheme(), "", uri.getHost(), port, uri.getPath(), uri.getQuery(), "");
    }
    return uri;
}