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.microsoft.azuretools.adauth.ResponseUtils.java

public static AuthorizationResult parseAuthorizeResponse(String webAuthenticationResult, CallState callState)
        throws URISyntaxException, UnsupportedEncodingException {
    AuthorizationResult result = null;//from  ww w . j  ava  2s. c  o m

    URI resultUri = new URI(webAuthenticationResult);
    // NOTE: The Fragment property actually contains the leading '#' character and that must be dropped
    String resultData = resultUri.getQuery();
    if (resultData != null && !resultData.isEmpty()) {
        // Remove the leading '?' first
        Map<String, String> map = UriUtils.formQueryStirng(resultData);

        if (map.containsKey(OAuthHeader.CorrelationId)) {
            String correlationIdHeader = (map.get(OAuthHeader.CorrelationId)).trim();
            try {
                UUID correlationId = UUID.fromString(correlationIdHeader);
                if (!correlationId.equals(callState.correlationId)) {
                    log.log(Level.WARNING, "Returned correlation id '" + correlationId
                            + "' does not match the sent correlation id '" + callState.correlationId + "'");
                }
            } catch (IllegalArgumentException ex) {
                log.log(Level.WARNING,
                        "Returned correlation id '" + correlationIdHeader + "' is not in GUID format.");
            }
        }
        if (map.containsKey(OAuthReservedClaim.Code)) {
            result = new AuthorizationResult(map.get(OAuthReservedClaim.Code));
        } else if (map.containsKey(OAuthReservedClaim.Error)) {
            result = new AuthorizationResult(map.get(OAuthReservedClaim.Error),
                    map.get(OAuthReservedClaim.ErrorDescription), map.get(OAuthReservedClaim.ErrorSubcode));
        } else {
            result = new AuthorizationResult(AuthError.AuthenticationFailed,
                    AuthErrorMessage.AuthorizationServerInvalidResponse);
        }
    }
    return result;
}

From source file:com.meltmedia.cadmium.servlets.AbstractSecureRedirectStrategy.java

/**
 * Returns a new URI object, based on the specified URI template, with an updated port (scheme) and port.  If the port
 * number is -1, then the default port is used in the resulting URI. 
 * //from   ww  w .  java2 s  .c o m
 * @param protocol the new protocol (scheme) in the resulting URI.
 * @param port the new port in the resulting URI, or the default port if -1 is provided.
 * @param template the source of all other values for the new URI.
 * @return a new URI object with the updated protocol and port.
 * @throws URISyntaxException 
 */
public static URI changeProtocolAndPort(String protocol, int port, URI template) throws URISyntaxException {
    return new URI(protocol, template.getUserInfo(), template.getHost(), port, template.getPath(),
            template.getQuery(), null);
}

From source file:URIUtil.java

/**
 * Get the parent URI of the supplied URI
 * @param uri The input URI for which the parent URI is being requrested.
 * @return The parent URI.  Returns a URI instance equivalent to "../" if
 * the supplied URI path has no parent./*from   ww w  .  j  a v a2  s  .  co m*/
 * @throws URISyntaxException Failed to reconstruct the parent URI.
 */
public static URI getParent(URI uri) throws URISyntaxException {

    String parentPath = new File(uri.getPath()).getParent();

    if (parentPath == null) {
        return new URI("../");
    }

    return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(),
            parentPath.replace('\\', '/'), uri.getQuery(), uri.getFragment());
}

From source file:com.terremark.handlers.CloudApiAuthenticationHandler.java

/**
 * Builds a formatted string for the URI and the query string.
 *
 * @param request Client request./*from w  w  w .  ja v a 2  s. c o m*/
 * @return Formatted URI and query arguments.
 */
private static String getCanonicalizedResource(final ClientRequest request) {
    final Map<String, String> queryMap = new TreeMap<String, String>();
    final URI uri = request.getURI();
    final String query = uri.getQuery();

    if (query != null && query.length() > 0) {
        final String[] parts = query.split("&");

        for (final String part : parts) {
            final String[] nameValue = part.split("=");
            if (nameValue.length == 2) {
                queryMap.put(nameValue[0].toLowerCase(), nameValue[1]);
            }
        }
    }

    final StringBuilder builder = new StringBuilder();
    builder.append(uri.getPath().toLowerCase()).append('\n');

    for (final Map.Entry<String, String> entry : queryMap.entrySet()) {
        builder.append(entry.getKey()).append(':').append(entry.getValue()).append('\n');
    }

    return builder.toString();
}

From source file:URISupport.java

public static Map<String, String> parseParamters(URI uri) throws URISyntaxException {
    return uri.getQuery() == null ? emptyMap() : parseQuery(stripPrefix(uri.getQuery(), "?"));
}

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

public static String removeBVQuery(String queryUrl) {

    final URI uri;
    try {/*  w ww  . ja  v  a  2 s .c o  m*/
        uri = new URI(queryUrl);
    } catch (URISyntaxException e) {
        return queryUrl;
    }

    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"));
            List<String> bvParameters = Arrays.asList("bvrrp", "bvsyp", "bvqap", "bvpage");
            for (NameValuePair parameter : parameters) {
                if (!bvParameters.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 queryUrl;
    }
}

From source file:com.akamai.edgegrid.signer.EdgeGridV1Signer.java

private static String getRelativePathWithQuery(URI uri) {
    StringBuilder sb = new StringBuilder(uri.getPath());
    if (uri.getQuery() != null) {
        sb.append("?").append(uri.getQuery());
    }//www.  j  a v  a2s .c  o  m
    return sb.toString();
}

From source file:io.syndesis.rest.v1.handler.credential.CredentialHandler.java

static URI addFragmentTo(final URI uri, final CallbackStatus status) {
    try {// ww  w  . jav a 2s.c  om
        final String fragment = SERIALIZER.writeValueAsString(status);

        return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(),
                fragment);
    } catch (JsonProcessingException | URISyntaxException e) {
        throw new IllegalStateException("Unable to add fragment to URI: " + uri + ", for state: " + status, e);
    }
}

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

/**
 * Returns the role associated with a given Junction invitation.
 * @param uri/*w w  w.java 2s.  com*/
 * @return
 */
public static String getRoleFromInvitation(URI uri) {
    String query = uri.getQuery();
    if (query == null)
        return null;
    int pos = query.indexOf("role=");
    if (pos == -1) {
        return null;
    }

    query = query.substring(pos + 5);
    pos = query.indexOf('&');
    if (pos > -1) {
        query = query.substring(0, pos);
    }
    return query;
}

From source file:com.github.wolf480pl.mias4j.util.AbstractTransformingClassLoader.java

public static URL guessCodeSourceURL(String resourcePath, URL resourceURL) {
    // FIXME: Find a better way to do this
    @SuppressWarnings("restriction")
    String escaped = sun.net.www.ParseUtil.encodePath(resourcePath, false);
    String path = resourceURL.getPath();
    if (!path.endsWith(escaped)) {
        // Umm... whadda we do now? Maybe let's fallback to full resource URL.
        LOG.warn("Resource URL path \"" + path + "\" doesn't end with escaped resource path \"" + escaped
                + "\" for resource \"" + resourcePath + "\"");
        return resourceURL;
    }//  www  .jav  a2 s. c  o  m
    path = path.substring(0, path.length() - escaped.length());
    if (path.endsWith("!/")) { // JAR
        path = path.substring(0, path.length() - 2);
    }
    try {
        URI uri = resourceURL.toURI();
        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(),
                uri.getFragment()).toURL();
    } catch (MalformedURLException | URISyntaxException e) {
        // Umm... whadda we do now? Maybe let's fallback to full resource URL.
        LOG.warn("Couldn't assemble CodeSource URL with modified path", e);
        return resourceURL;
    }
}