下面列出了java.net.URI#getRawQuery ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public KeycloakUriBuilder schemeSpecificPart(String ssp) throws IllegalArgumentException {
if (ssp == null) throw new IllegalArgumentException("schemeSpecificPart was null");
StringBuilder sb = new StringBuilder();
if (scheme != null) sb.append(scheme).append(':');
if (ssp != null)
sb.append(ssp);
if (fragment != null && fragment.length() > 0) sb.append('#').append(fragment);
URI uri = URI.create(sb.toString());
if (uri.getRawSchemeSpecificPart() != null && uri.getRawPath() == null) {
this.ssp = uri.getRawSchemeSpecificPart();
} else {
this.ssp = null;
userInfo = uri.getRawUserInfo();
host = uri.getHost();
port = uri.getPort();
path = uri.getRawPath();
query = uri.getRawQuery();
}
return this;
}
/**
* Creates a new instance.
*/
DefaultClientBuilderParams(URI uri, Class<?> type, ClientOptions options) {
final ClientFactory factory = requireNonNull(options, "options").factory();
this.uri = factory.validateUri(uri);
this.type = requireNonNull(type, "type");
this.options = options;
scheme = factory.validateScheme(Scheme.parse(uri.getScheme()));
endpointGroup = Endpoint.parse(uri.getRawAuthority());
final StringBuilder buf = TemporaryThreadLocals.get().stringBuilder();
buf.append(nullOrEmptyToSlash(uri.getRawPath()));
if (uri.getRawQuery() != null) {
buf.append('?').append(uri.getRawQuery());
}
if (uri.getRawFragment() != null) {
buf.append('#').append(uri.getRawFragment());
}
absolutePathRef = buf.toString();
}
/**
* This parses out all of the parameters in the query string for both
* http: and geo: URIs. This will only work on URIs with valid syntax, so
* it will not work on URIs that do odd things like have a query string in
* the fragment, like this one:
* http://www.amap.com/#!poi!!q=38.174596,114.995033|2|%E5%AE%BE%E9%A6%86&radius=1000
*
* @param uri
* @return {@link Map<String, String>} a Map of the query parameters
*/
private static Map<String, String> getQueryParameters(URI uri) {
String query = null;
if (uri.isOpaque()) {
String schemeSpecificPart = uri.getSchemeSpecificPart();
int pos = schemeSpecificPart.indexOf("?");
if (pos == schemeSpecificPart.length()) {
query = "";
} else if (pos > -1) {
query = schemeSpecificPart.substring(pos + 1);
}
} else {
query = uri.getRawQuery();
}
return getQueryParameters(query);
}
public static boolean containsEncodedParts(URI uri) {
boolean encoded = (uri.getRawQuery() != null && uri.getRawQuery().contains("%"))
|| (uri.getRawPath() != null && uri.getRawPath().contains("%"));
// Verify if it is really fully encoded. Treat partial encoded as unencoded.
if (encoded) {
try {
UriComponentsBuilder.fromUri(uri).build(true);
return true;
}
catch (IllegalArgumentException ignore) {
if (log.isTraceEnabled()) {
log.trace("Error in containsEncodedParts", ignore);
}
}
return false;
}
return encoded;
}
private ArmeriaClientHttpRequest createRequest(HttpMethod method, URI uri) {
final String scheme = uri.getScheme();
final String authority = uri.getRawAuthority();
final String path = uri.getRawPath();
final String query = uri.getRawQuery();
checkArgument(!Strings.isNullOrEmpty(authority), "URI is not absolute: %s", uri);
checkArgument(!Strings.isNullOrEmpty(path), "path is undefined: %s", uri);
final URI baseUri = URI.create(Strings.isNullOrEmpty(scheme) ? authority : scheme + "://" + authority);
final WebClientBuilder builder = WebClient.builder(baseUri);
configurators.forEach(c -> c.configure(builder));
final String pathAndQuery = Strings.isNullOrEmpty(query) ? path : path + '?' + query;
return new ArmeriaClientHttpRequest(builder.build(), method, pathAndQuery, uri, factoryWrapper);
}
protected final String buildMessage(String nonce, long timestamp, HttpRequestWrapper request)
throws IOException {
URI uri = request.getURI();
String canonicalUrl = uri.getRawPath();
if (uri.getQuery() != null) {
canonicalUrl += "?" + uri.getRawQuery();
}
String body = "";
// PATCH,POST,PUT
if (request.getOriginal() instanceof WechatPayUploadHttpPost) {
body = ((WechatPayUploadHttpPost) request.getOriginal()).getMeta();
} else if (request instanceof HttpEntityEnclosingRequest) {
body = EntityUtils.toString(((HttpEntityEnclosingRequest) request).getEntity());
}
return request.getRequestLine().getMethod() + "\n"
+ canonicalUrl + "\n"
+ timestamp + "\n"
+ nonce + "\n"
+ body + "\n";
}
private URI getPath(URI uri) {
// Cloudera 3u4 does not deal with "." and ".." in paths => normalize()
StringBuilder sb = new StringBuilder();
String path = uri.getRawPath();
if (path != null) {
sb.append(path);
}
String query = uri.getRawQuery();
if (query != null) {
sb.append('?').append(query);
}
String result = sb.toString();
if (result.isEmpty()) {
result = URIUtils.PATH_SEPARATOR;
}
return URI.create(result).normalize();
}
private static boolean containsEncodedParts(URI uri) {
boolean encoded = (uri.getRawQuery() != null
&& uri.getRawQuery().contains(PERCENTAGE_SIGN))
|| (uri.getRawPath() != null
&& uri.getRawPath().contains(PERCENTAGE_SIGN))
|| (uri.getRawFragment() != null
&& uri.getRawFragment().contains(PERCENTAGE_SIGN));
// Verify if it is really fully encoded. Treat partial encoded as unencoded.
if (encoded) {
try {
UriComponentsBuilder.fromUri(uri).build(true);
return true;
}
catch (IllegalArgumentException ignore) {
}
return false;
}
return false;
}
@Nonnull
public static Properties extractQueryPropertiesFromURI(@Nonnull final URI uri) {
final Properties result = new Properties();
final String rawQuery = uri.getRawQuery();
if (rawQuery != null) {
final Matcher matcher = URI_QUERY_PARAMETERS.matcher(rawQuery);
try {
while (matcher.find()) {
final String key = URLDecoder.decode(matcher.group(1), "UTF-8"); //NOI18N
final String value = URLDecoder.decode(matcher.group(2), "UTF-8"); //NOI18N
result.put(key, value);
}
} catch (UnsupportedEncodingException ex) {
LOGGER.error("Can't decode URI query", ex); //NOI18N
throw new Error("Unexpected exception, can't find UTF-8 charset!"); //NOI18N
}
}
return result;
}
/**
* 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.");
}
}
/**
* Get parameter value with name
*
* @param uri
* @param name
* @return value or null if not found in URI query
*/
public static String getParam(final URI uri, final String name) {
final String query = uri.getRawQuery();
if (query == null || query.length() == 0)
return null;
final String[] params = query.split("&"); //$NON-NLS-1$
for (String param : params) {
final String[] parts = param.split("="); //$NON-NLS-1$
if (parts.length != 2)
continue;
if (!name.equals(parts[0]))
continue;
return decode(parts[1]);
}
return null;
}
/**
* 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
*/
public static List<NameValuePair> parse(final URI uri) {
final String query = uri.getRawQuery();
if (!TextUtils.isEmpty(query)) {
List<NameValuePair> result = new ArrayList<NameValuePair>();
Scanner scanner = new Scanner(query);
parse(result, scanner);
return result;
} else {
return Collections.emptyList();
}
}
private void checkUri(URI uri) {
if (!uri.getScheme().equalsIgnoreCase(getScheme()))
throw new IllegalArgumentException("URI does not match this provider");
if (uri.getRawAuthority() != null)
throw new IllegalArgumentException("Authority component present");
String path = uri.getPath();
if (path == null)
throw new IllegalArgumentException("Path component is undefined");
if (!path.equals("/"))
throw new IllegalArgumentException("Path component should be '/'");
if (uri.getRawQuery() != null)
throw new IllegalArgumentException("Query component present");
if (uri.getRawFragment() != null)
throw new IllegalArgumentException("Fragment component present");
}
/**
* Return the constructed raw path for the give {@link URI}.
*/
static String rawPath(URI wsURL) {
String path = wsURL.getRawPath();
String query = wsURL.getRawQuery();
if (query != null && !query.isEmpty()) {
path = path + '?' + query;
}
return path == null || path.isEmpty() ? "/" : path;
}
/**
* Retrieves the raw (unescaped) path and query parameters from the URI, stripping out the scheme, host, and port.
* The path will begin with a leading '/'. For example, 'http://example.com/some/resource?param%20name=param%20value'
* would return '/some/resource?param%20name=param%20value'.
*
* @param uriString the URI to parse, containing a scheme, host, port, path, and query parameters
* @return the unescaped path and query parameters from the URI
* @throws URISyntaxException if the specified URI is invalid or cannot be parsed
*/
public static String getRawPathAndParamsFromUri(String uriString) throws URISyntaxException {
URI uri = new URI(uriString);
String path = uri.getRawPath();
String query = uri.getRawQuery();
if (query != null) {
return path + '?' + query;
} else {
return path;
}
}
public HttpRequestProperties(URI uri, String httpMethod) {
this(uri.getHost(), getPortFromURI(uri), httpMethod,
uri.getRawPath(), uri.getRawQuery());
}
/**
*
* @param urlString
* @param username
* @param password value is cloned, if you want to null the field, call {@link #clearPassword()}
* @throws URISyntaxException
*/
public HgURL(String urlString, String username, char[] password) throws URISyntaxException {
URI originalUri;
if (urlString == null) {
throw new IllegalArgumentException("<null> URL string"); //NOI18N
}
if (urlString.length() == 0) {
throw new IllegalArgumentException("empty URL string"); //NOI18N
}
if (looksLikePlainFilePath(urlString)) {
originalUri = new File(urlString).toURI();
scheme = Scheme.FILE;
} else {
originalUri = new URI(urlString).parseServerAuthority();
String originalScheme = originalUri.getScheme();
scheme = (originalScheme != null) ? determineScheme(originalScheme)
: null;
}
if (scheme == null) {
throw new URISyntaxException(
urlString,
NbBundle.getMessage(HgURL.class,
"MSG_UNSUPPORTED_PROTOCOL", //NOI18N
originalUri.getScheme()));
}
verifyUserInfoData(scheme, username, password);
if (username != null) {
this.username = username;
this.password = password == null ? null : (char[])password.clone();
} else {
String rawUserInfo = originalUri.getRawUserInfo();
if (rawUserInfo == null) {
this.username = null;
this.password = null;
} else {
int colonIndex = rawUserInfo.indexOf(':');
if (colonIndex == -1) {
this.username = rawUserInfo;
this.password = null;
} else {
this.username = rawUserInfo.substring(0, colonIndex);
this.password = rawUserInfo.substring(colonIndex + 1).toCharArray();
}
}
}
host = originalUri.getHost();
port = originalUri.getPort();
rawPath = originalUri.getRawPath();
rawQuery = originalUri.getRawQuery();
rawFragment = originalUri.getRawFragment();
path = originalUri.getPath();
}
/**
* 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);
}
private int checkUrl() {
int type = 0;
String id = null;
chineseRule = 1;
chineseFlag = false;
String url = txtUrl.getText().trim();
Pattern up =
Pattern.compile(
"https*://(?s).*?([^\\./]+\\.[^\\./]+)/(?s).*?(live/[a-zA-Z]+/)([^/]+)/[0-9]+/([^/]+)[^\\n]*");
Matcher um = up.matcher(url);
if (um.matches() && um.groupCount() >= 4) {
id = um.group(3);
roomId = Long.parseLong(um.group(4));
if (!Utils.isBlank(id) && roomId > 0) {
ajaxUrl = "https://api." + um.group(1) + "/golive/dtl?id=" + id;
return 1;
}
}
up = Pattern.compile("https*://(?s).*?([^\\./]+\\.[^\\./]+)/(?s).*?(live/[a-zA-Z]+/)([^/]+)");
um = up.matcher(url);
if (um.matches() && um.groupCount() >= 3) {
id = um.group(3);
if (!Utils.isBlank(id)) {
ajaxUrl = "https://api." + um.group(1) + "/golive/dtl?id=" + id;
return 2;
}
}
up =
Pattern.compile(
"https*://(?s).*?([^\\./]+\\.[^\\./]+)/(?s).*?(game/[a-zA-Z]+/)[0-9]+/([^/]+)");
um = up.matcher(url);
if (um.matches() && um.groupCount() >= 3) {
roomId = Long.parseLong(um.group(3));
if (roomId > 0) { // !Utils.isBlank(id)) {
ajaxUrl = "https://api." + um.group(1) + "/golive/dtl?id=" + roomId;
return 5;
}
}
up =
Pattern.compile(
"https*://(?s).*?([^\\./]+\\.[^\\./]+)/(?s).*?(room=)([0-9]+)(&hall)(?s).*?");
um = up.matcher(url);
if (um.matches() && um.groupCount() >= 3) {
roomId = Long.parseLong(um.group(3));
if (roomId > 0) { // !Utils.isBlank(id)) {
ajaxUrl = "https://api." + um.group(1) + "/golive/dtl?id=" + roomId;
return 5;
}
}
try {
URI uri = new URI(url);
queryMap = splitQuery(uri);
if (queryMap != null) {
if (queryMap.get("gameid") != null && queryMap.get("createtime") != null) {
return 3;
} else if (queryMap.get("gametag") != null && queryMap.get("uin") != null) {
query = uri.getRawQuery();
ajaxUrl =
"http://wshall."
+ uri.getHost()
+ "/wxnseed/Broadcast/RequestBroadcast?callback=jQuery1&"
+ query;
return 4;
}
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
// Try
ajaxUrl = url;
return 99;
}
public static Map<String, String> parseParamters(final URI uri) throws URISyntaxException {
return uri.getRawQuery() == null ? new HashMap<String, String>(0) : parseQuery(stripPrefix(uri.getRawQuery(), "?"));
}