本文整理汇总了Java中java.net.URI.getRawQuery方法的典型用法代码示例。如果您正苦于以下问题:Java URI.getRawQuery方法的具体用法?Java URI.getRawQuery怎么用?Java URI.getRawQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URI
的用法示例。
在下文中一共展示了URI.getRawQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DecodeQuery
import java.net.URI; //导入方法依赖的package包/类
/**
* 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.");
}
}
示例2: QueryStringDecoderV2
import java.net.URI; //导入方法依赖的package包/类
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;
}
示例3: getAuthObj
import java.net.URI; //导入方法依赖的package包/类
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;
}
示例4: toRequestOptions
import java.net.URI; //导入方法依赖的package包/类
/**
* 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;
}
示例5: toRequestOptions
import java.net.URI; //导入方法依赖的package包/类
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;
}
示例6: parse
import java.net.URI; //导入方法依赖的package包/类
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;
}
示例7: isRoot
import java.net.URI; //导入方法依赖的package包/类
/**
* 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;
}
示例8: digestURI
import java.net.URI; //导入方法依赖的package包/类
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();
}
示例9: parse
import java.net.URI; //导入方法依赖的package包/类
/**
* 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();
}
}
示例10: createRequest
import java.net.URI; //导入方法依赖的package包/类
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;
}
示例11: getResponseType
import java.net.URI; //导入方法依赖的package包/类
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;
}
示例12: doGET
import java.net.URI; //导入方法依赖的package包/类
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);
}
示例13: digestURI
import java.net.URI; //导入方法依赖的package包/类
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();
}
示例14: createRequest
import java.net.URI; //导入方法依赖的package包/类
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;
}
示例15: getRequestString
import java.net.URI; //导入方法依赖的package包/类
/**
* 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;
}