Java Code Examples for java.net.URI.getRawQuery()

The following are Jave code examples for showing how to use getRawQuery() of the java.net.URI class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: unity-obb-downloader   File: URIQueryDecoder.java   View Source Code Vote up 6 votes
/**
 * Decodes the query portion of the passed-in URI.
 *
 * @param encodedURI the URI containing the query to decode
 * @param results a map containing all query parameters. Query parameters that do not have a
 *            value will map to a null string
 */
static public void DecodeQuery(URI encodedURI, Map<String, String> results) {
    Scanner scanner = new Scanner(encodedURI.getRawQuery());
    scanner.useDelimiter("&");
    try {
        while (scanner.hasNext()) {
            String param = scanner.next();
            String[] valuePair = param.split("=");
            String name, value;
            if (valuePair.length == 1) {
                value = null;
            } else if (valuePair.length == 2) {
                value = URLDecoder.decode(valuePair[1], "UTF-8");
            } else {
                throw new IllegalArgumentException("query parameter invalid");
            }
            name = URLDecoder.decode(valuePair[0], "UTF-8");
            results.put(name, value);
        }
    } catch (UnsupportedEncodingException e) {
        // This should never happen.
        Log.e(TAG, "UTF-8 Not Recognized as a charset.  Device configuration Error.");
    }
}
 
Example 2
Project: Limitart   File: QueryStringDecoderV2.java   View Source Code Vote up 6 votes
public QueryStringDecoderV2(URI uri, Charset charset, int maxParams) {
	if (uri == null) {
		throw new NullPointerException("getUri");
	}
	if (charset == null) {
		throw new NullPointerException("charset");
	}
	if (maxParams <= 0) {
		throw new IllegalArgumentException("maxParams: " + maxParams + " (expected: a positive integer)");
	}

	String rawPath = uri.getRawPath();
	if (rawPath != null) {
		hasPath = true;
	} else {
		rawPath = "";
		hasPath = false;
	}
	// Also take care of cut of things like "http://localhost"
	this.uri = rawPath + (uri.getRawQuery() == null ? "" : '?' + uri.getRawQuery());

	this.charset = charset;
	this.maxParams = maxParams;
}
 
Example 3
Project: mxhsd   File: HttpFederationClient.java   View Source Code Vote up 6 votes
private String getAuthObj(String remoteDomain, String method, URI target, JsonObject content) {
    String uri = target.getRawPath();
    if (StringUtils.isNotBlank(target.getRawQuery())) {
        uri += "?" + target.getRawQuery();
    }

    JsonObject authObj = new JsonObject();
    authObj.addProperty("method", method);
    authObj.addProperty("uri", uri);
    authObj.addProperty("origin", global.getDomain());
    authObj.addProperty("destination", remoteDomain);
    Optional.ofNullable(content).ifPresent(c -> authObj.add("content", c));
    String data = MatrixJson.encodeCanonical(authObj);
    log.info("Auth object: {}", data);
    return data;
}
 
Example 4
Project: app-ms   File: Conversions.java   View Source Code Vote up 6 votes
/**
 * Builds the request options suitable for HttpClient from a URI and a relative
 * path.
 *
 * @param uri
 *            URI
 * @return request options
 */
public static RequestOptions toRequestOptions(final URI uri,
    final String relativeUri) {

    final RequestOptions options = new RequestOptions()
        .setSsl("https".equals(uri.getScheme()))
        .setHost(uri.getHost());
    if (uri.getPort() > 0) {
        options.setPort(uri.getPort());
    } else if (options.isSsl()) {
        options.setPort(443);
    } else {
        options.setPort(80);
    }
    final String rawPath = uri.getRawPath() + relativeUri;
    if (uri.getRawQuery() == null) {
        options.setURI(rawPath);
    } else {
        options.setURI(rawPath + "?" + uri.getRawQuery());
    }
    return options;
}
 
Example 5
Project: app-ms   File: Conversions.java   View Source Code Vote up 6 votes
public static RequestOptions toRequestOptions(final URI uri) {

        final RequestOptions options = new RequestOptions()
            .setSsl("https".equals(uri.getScheme()))
            .setHost(uri.getHost());
        if (uri.getPort() > 0) {
            options.setPort(uri.getPort());
        } else if (options.isSsl()) {
            options.setPort(443);
        } else {
            options.setPort(80);
        }
        if (uri.getRawQuery() == null) {
            options.setURI(uri.getRawPath());
        } else {
            options.setURI(uri.getRawPath() + "?" + uri.getRawQuery());
        }
        return options;
    }
 
Example 6
Project: Phoenix-for-VK   File: URLUtils.java   View Source Code Vote up 5 votes
public static List<NameValuePair> parse(final URI uri, final String encoding) {
    List<NameValuePair> result = Collections.emptyList();
    final String query = uri.getRawQuery();
    if (query != null && query.length() > 0) {
        result = new ArrayList<>();
        parse(result, new Scanner(query), encoding);
    }
    return result;
}
 
Example 7
Project: truevfs   File: FsNodeName.java   View Source Code Vote up 5 votes
/**
 * Returns {@code true} if and only if the path component of this file
 *         system node name is empty and no query component is defined.
 * 
 * @return {@code true} if and only if the path component of this file
 *         system node name is empty and no query component is defined.
 */
public boolean isRoot() {
    //return getUri().toString().isEmpty();
    final URI uri = getUri();
    final String path = uri.getRawPath();
    if (null != path && !path.isEmpty())
        return false;
    final String query = uri.getRawQuery();
    return null == query;
}
 
Example 8
Project: Hotspot-master-devp   File: URIBuilder.java   View Source Code Vote up 5 votes
private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), Charset.forName(HTTP.UTF_8));
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}
 
Example 9
Project: Hotspot-master-devp   File: URLEncodedUtils.java   View Source Code Vote up 5 votes
/**
 * Returns a list of {@link org.apache.http.NameValuePair NameValuePairs} as built from the
 * URI's query portion. For example, a URI of
 * http://example.org/path/to/file?a=1&b=2&c=3 would return a list of three
 * NameValuePairs, one for a=1, one for b=2, and one for c=3.
 * <p/>
 * This is typically useful while parsing an HTTP PUT.
 *
 * @param uri      uri to parse
 * @param encoding encoding to use while parsing the query
 */
public static List<NameValuePair> parse(final URI uri, final String encoding) {
    final String query = uri.getRawQuery();
    if (!TextUtils.isEmpty(query)) {
        List<NameValuePair> result = new ArrayList<NameValuePair>();
        Scanner scanner = new Scanner(query);
        parse(result, scanner, encoding);
        return result;
    } else {
        return Collections.emptyList();
    }
}
 
Example 10
Project: apache-tomcat-7.0.73-with-comment   File: WsWebSocketContainer.java   View Source Code Vote up 5 votes
private static ByteBuffer createRequest(URI uri, Map<String,List<String>> reqHeaders) {
    ByteBuffer result = ByteBuffer.allocate(4 * 1024);

    // Request line
    result.put(GET_BYTES);
    byte[] path = (null == uri.getPath() || "".equals(uri.getPath()))
            ? ROOT_URI_BYTES : uri.getRawPath().getBytes(StandardCharsets.ISO_8859_1);
    result.put(path);
    String query = uri.getRawQuery();
    if (query != null) {
        result.put((byte) '?');
        result.put(query.getBytes(StandardCharsets.ISO_8859_1));
    }
    result.put(HTTP_VERSION_BYTES);

    // Headers
    Iterator<Entry<String,List<String>>> iter =
            reqHeaders.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<String,List<String>> entry = iter.next();
        addHeader(result, entry.getKey(), entry.getValue());
    }

    // Terminating CRLF
    result.put(crlf);

    result.flip();

    return result;
}
 
Example 11
Project: JInsight   File: ApptuitPutClientTest.java   View Source Code Vote up 5 votes
private int getResponseType(HttpExchange exchange) {
  URI uri = exchange.getRequestURI();
  String rawQuery = uri.getRawQuery();
  if (rawQuery == null) {
    return HttpURLConnection.HTTP_OK;
  }
  if ("status=400".equals(rawQuery)) {
    return HttpURLConnection.HTTP_BAD_REQUEST;
  }
  return HttpURLConnection.HTTP_OK;
}
 
Example 12
Project: JInsight   File: RequestExecutorBasedClientInstrumentationTest.java   View Source Code Vote up 5 votes
public HttpResponse doGET(URI url) throws IOException, HttpException {
  String uri = url.getRawPath() + (url.getRawQuery() != null ? "?" + url.getRawQuery() : "");
  HttpRequest request = new BasicHttpRequest("GET", uri);
  String hostHeader = (url.getPort() == 0 || url.getPort() == 80)
      ? url.getHost() : (url.getHost() + ":" + url.getPort());
  request.addHeader("Host", hostHeader);
  return execute(request);
}
 
Example 13
Project: lams   File: URIBuilder.java   View Source Code Vote up 5 votes
private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8);
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}
 
Example 14
Project: lazycat   File: WsWebSocketContainer.java   View Source Code Vote up 5 votes
private static ByteBuffer createRequest(URI uri, Map<String, List<String>> reqHeaders) {
	ByteBuffer result = ByteBuffer.allocate(4 * 1024);

	// Request line
	result.put(GET_BYTES);
	byte[] path = (null == uri.getPath() || "".equals(uri.getPath())) ? ROOT_URI_BYTES
			: uri.getRawPath().getBytes(StandardCharsets.ISO_8859_1);
	result.put(path);
	String query = uri.getRawQuery();
	if (query != null) {
		result.put((byte) '?');
		result.put(query.getBytes(StandardCharsets.ISO_8859_1));
	}
	result.put(HTTP_VERSION_BYTES);

	// Headers
	Iterator<Entry<String, List<String>>> iter = reqHeaders.entrySet().iterator();
	while (iter.hasNext()) {
		Entry<String, List<String>> entry = iter.next();
		addHeader(result, entry.getKey(), entry.getValue());
	}

	// Terminating CRLF
	result.put(crlf);

	result.flip();

	return result;
}
 
Example 15
Project: FirefoxData-android   File: HMACAuthHeaderProvider.java   View Source Code Vote up 5 votes
/**
 * Generate an HMAC request string.
 * <p>
 * This method trusts its inputs to be valid as per the MAC Authentication spec.
 *
 * @param request HTTP request.
 * @param timestamp to use.
 * @param nonce to use.
 * @param extra to use.
 * @return request string.
 */
protected static String getRequestString(HttpUriRequest request, long timestamp, String nonce, String extra) {
  String method = request.getMethod().toUpperCase();

  URI uri = request.getURI();
  String host = uri.getHost();

  String path = uri.getRawPath();
  if (uri.getRawQuery() != null) {
    path += "?";
    path += uri.getRawQuery();
  }
  if (uri.getRawFragment() != null) {
    path += "#";
    path += uri.getRawFragment();
  }

  int port = uri.getPort();
  String scheme = uri.getScheme();
  if (port != -1) {
  } else if ("http".equalsIgnoreCase(scheme)) {
    port = 80;
  } else if ("https".equalsIgnoreCase(scheme)) {
    port = 443;
  } else {
    throw new IllegalArgumentException("Unsupported URI scheme: " + scheme + ".");
  }

  String requestString = timestamp + "\n" +
      nonce       + "\n" +
      method      + "\n" +
      path        + "\n" +
      host        + "\n" +
      port        + "\n" +
      extra       + "\n";

  return requestString;
}
 
Example 16
Project: RLibrary   File: WebSocketFactory.java   View Source Code Vote up 4 votes
/**
 * Create a WebSocket.
 *
 * <p>
 * A socket factory (= a {@link SocketFactory} instance) to create a raw
 * socket (= a {@link Socket} instance) is determined as described below.
 * </p>
 *
 * <ol>
 * <li>
 *   If the scheme of the URI is either {@code wss} or {@code https},
 *   <ol type="i">
 *     <li>
 *       If an {@link SSLContext} instance has been set by {@link
 *       #setSSLContext(SSLContext)}, the value returned from {@link
 *       SSLContext#getSocketFactory()} method of the instance is used.
 *     <li>
 *       Otherwise, if an {@link SSLSocketFactory} instance has been
 *       set by {@link #setSSLSocketFactory(SSLSocketFactory)}, the
 *       instance is used.
 *     <li>
 *       Otherwise, the value returned from {@link SSLSocketFactory#getDefault()}
 *       is used.
 *   </ol>
 * <li>
 *   Otherwise (= the scheme of the URI is either {@code ws} or {@code http}),
 *   <ol type="i">
 *     <li>
 *       If a {@link SocketFactory} instance has been set by {@link
 *       #setSocketFactory(SocketFactory)}, the instance is used.
 *     <li>
 *       Otherwise, the value returned from {@link SocketFactory#getDefault()}
 *       is used.
 *   </ol>
 * </ol>
 *
 * @param uri
 *         The URI of the WebSocket endpoint on the server side.
 *         The scheme part of the URI must be one of {@code ws},
 *         {@code wss}, {@code http} and {@code https}
 *         (case-insensitive).
 *
 * @param timeout
 *         The timeout value in milliseconds for socket connection.
 *
 * @return
 *         A WebSocket.
 *
 * @throws IllegalArgumentException
 *         The given URI is {@code null} or violates RFC 2396, or
 *         the given timeout value is negative.
 *
 * @throws IOException
 *         Failed to create a socket.
 *
 * @since 1.10
 */
public WebSocket createSocket(URI uri, int timeout) throws IOException
{
    if (uri == null)
    {
        throw new IllegalArgumentException("The given URI is null.");
    }

    if (timeout < 0)
    {
        throw new IllegalArgumentException("The given timeout value is negative.");
    }

    // Split the URI.
    String scheme   = uri.getScheme();
    String userInfo = uri.getUserInfo();
    String host     = Misc.extractHost(uri);
    int port        = uri.getPort();
    String path     = uri.getRawPath();
    String query    = uri.getRawQuery();

    return createSocket(scheme, userInfo, host, port, path, query, timeout);
}
 
Example 17
Project: Equella   File: SuperDuperFilter.java   View Source Code Vote up 4 votes
private Map<String, List<String>> parseGetParameters(HttpExchange exchange)
{
	URI requestedUri = exchange.getRequestURI();
	String query = requestedUri.getRawQuery();
	return parseQuery(query, new HashMap<String, List<String>>());
}
 
Example 18
Project: openjdk-jdk10   File: File.java   View Source Code Vote up 3 votes
/**
 * Creates a new {@code File} instance by converting the given
 * {@code file:} URI into an abstract pathname.
 *
 * <p> The exact form of a {@code file:} URI is system-dependent, hence
 * the transformation performed by this constructor is also
 * system-dependent.
 *
 * <p> For a given abstract pathname <i>f</i> it is guaranteed that
 *
 * <blockquote><code>
 * new File(</code><i>&nbsp;f</i><code>.{@link #toURI()
 * toURI}()).equals(</code><i>&nbsp;f</i><code>.{@link #getAbsoluteFile() getAbsoluteFile}())
 * </code></blockquote>
 *
 * so long as the original abstract pathname, the URI, and the new abstract
 * pathname are all created in (possibly different invocations of) the same
 * Java virtual machine.  This relationship typically does not hold,
 * however, when a {@code file:} URI that is created in a virtual machine
 * on one operating system is converted into an abstract pathname in a
 * virtual machine on a different operating system.
 *
 * @param  uri
 *         An absolute, hierarchical URI with a scheme equal to
 *         {@code "file"}, a non-empty path component, and undefined
 *         authority, query, and fragment components
 *
 * @throws  NullPointerException
 *          If {@code uri} is {@code null}
 *
 * @throws  IllegalArgumentException
 *          If the preconditions on the parameter do not hold
 *
 * @see #toURI()
 * @see java.net.URI
 * @since 1.4
 */
public File(URI uri) {

    // Check our many preconditions
    if (!uri.isAbsolute())
        throw new IllegalArgumentException("URI is not absolute");
    if (uri.isOpaque())
        throw new IllegalArgumentException("URI is not hierarchical");
    String scheme = uri.getScheme();
    if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
        throw new IllegalArgumentException("URI scheme is not \"file\"");
    if (uri.getRawAuthority() != null)
        throw new IllegalArgumentException("URI has an authority component");
    if (uri.getRawFragment() != null)
        throw new IllegalArgumentException("URI has a fragment component");
    if (uri.getRawQuery() != null)
        throw new IllegalArgumentException("URI has a query component");
    String p = uri.getPath();
    if (p.equals(""))
        throw new IllegalArgumentException("URI path component is empty");

    // Okay, now initialize
    p = fs.fromURIPath(p);
    if (File.separatorChar != '/')
        p = p.replace('/', File.separatorChar);
    this.path = fs.normalize(p);
    this.prefixLength = fs.prefixLength(this.path);
}
 
Example 19
Project: lams   File: URLEncodedUtils.java   View Source Code Vote up 3 votes
/**
 * Returns a list of {@link NameValuePair NameValuePairs} as built from the
 * URI's query portion. For example, a URI of
 * http://example.org/path/to/file?a=1&b=2&c=3 would return a list of three
 * NameValuePairs, one for a=1, one for b=2, and one for c=3.
 * <p>
 * This is typically useful while parsing an HTTP PUT.
 *
 * @param uri
 *            uri to parse
 * @param encoding
 *            encoding to use while parsing the query
 */
public static List <NameValuePair> parse (final URI uri, final String encoding) {
    final String query = uri.getRawQuery();
    if (query != null && query.length() > 0) {
        List<NameValuePair> result = new ArrayList<NameValuePair>();
        Scanner scanner = new Scanner(query);
        parse(result, scanner, encoding);
        return result;
    } else {
        return Collections.emptyList();
    }
}
 
Example 20
Project: FirefoxData-android   File: URLEncodedUtils.java   View Source Code Vote up 3 votes
/**
 * Returns a list of {@link NameValuePair NameValuePairs} as built from the URI's query portion. For example, a URI
 * of http://example.org/path/to/file?a=1&b=2&c=3 would return a list of three NameValuePairs, one for a=1, one for
 * b=2, and one for c=3. By convention, {@code '&'} and {@code ';'} are accepted as parameter separators.
 * <p>
 * This is typically useful while parsing an HTTP PUT.
 *
 * This API is currently only used for testing.
 *
 * @param uri
 *            URI to parse
 * @param charset
 *            Charset name to use while parsing the query
 * @return a list of {@link NameValuePair} as built from the URI's query portion.
 */
public static List <NameValuePair> parse(final URI uri, final String charset) {
    final String query = uri.getRawQuery();
    if (query != null && query.length() > 0) {
        final List<NameValuePair> result = new ArrayList<NameValuePair>();
        final Scanner scanner = new Scanner(query);
        parse(result, scanner, QP_SEP_PATTERN, charset);
        return result;
    }
    return Collections.emptyList();
}