/** * Returns whether or not the given URI is valid as a base file system URI. It must not have a * path, query or fragment. */ private static boolean isValidFileSystemUri(URI uri) { // would like to just check null, but fragment appears to be the empty string when not present return isNullOrEmpty(uri.getPath()) && isNullOrEmpty(uri.getQuery()) && isNullOrEmpty(uri.getFragment()); }
/** * @param pathQuery The path and (optional) query URI parts of this resource. * @param model The model object. */ public Resource(URI pathQuery, M model) { try { this.pathQuery = new URI(null, null, pathQuery.getPath(), pathQuery.getQuery(), null); } catch (URISyntaxException ex) { throw new RuntimeException(ex); } this.model = model; if (model == null) { throw new IllegalArgumentException("Model instance must not be null"); } }
public static List<TransportConfiguration> getTransportConfigurations(URI uri, Map<String, String> query, Set<String> allowableProperties, String name, String factoryName) throws URISyntaxException { HashMap<String, Object> props = new HashMap<>(); Map<String, Object> extraProps = new HashMap<>(); BeanSupport.setData(uri, props, allowableProperties, query, extraProps); List<TransportConfiguration> transportConfigurations = new ArrayList<>(); TransportConfiguration config = new TransportConfiguration(factoryName, props, name, extraProps); transportConfigurations.add(config); String connectors = uri.getFragment(); if (connectors != null && !connectors.trim().isEmpty()) { String[] split = connectors.split(","); for (String s : split) { URI extraUri = new URI(s); HashMap<String, Object> newProps = new HashMap<>(); extraProps = new HashMap<>(); BeanSupport.setData(extraUri, newProps, allowableProperties, query, extraProps); BeanSupport.setData(extraUri, newProps, allowableProperties, parseQuery(extraUri.getQuery(), null), extraProps); transportConfigurations.add(new TransportConfiguration(factoryName, newProps, name + ":" + extraUri.toString(), extraProps)); } } return transportConfigurations; }
private boolean digestUriMatchesRequestUri(HttpServerRequest request, byte[] digestUri) { if (!validateUri) { return true; } java.net.URI requestURI = request.getRequestURI(); String digestUriStr = new String(digestUri, UTF_8); if (requestURI.toString().equals(digestUriStr)) { return true; } else { // digestUri is relative & request is absolute String relativeRequestUri; String query = requestURI.getQuery(); if (query == null || query.isEmpty()) { relativeRequestUri = requestURI.getPath(); } else { relativeRequestUri = requestURI.getPath() + "?" + requestURI.getQuery(); } return relativeRequestUri.equals(digestUriStr); } }
try { parentUri = new java.net.URI(getSchemeComponents(parent.getScheme()).getSecond(), null, parentPath, parent.getQuery(), null); childUri = new java.net.URI(getSchemeComponents(child.getScheme()).getSecond(), null, child.getPath(), child.getQuery(), null); } catch (URISyntaxException e) { return create(resolvedScheme, authority, resolved.getPath(), resolved.getQuery());
private static RedisURI buildRedisUriFromUri(URI uri) { LettuceAssert.notNull(uri.getScheme(), "URI scheme must not be null"); if (uri.getScheme().equals(URI_SCHEME_REDIS_SENTINEL)) { builder = configureSentinel(uri); } else { if (isNotEmpty(uri.getPath()) && builder.socket == null) { String pathSuffix = uri.getPath().substring(1); if (isNotEmpty(uri.getQuery())) { StringTokenizer st = new StringTokenizer(uri.getQuery(), "&;"); while (st.hasMoreTokens()) { String queryParam = st.nextToken(); if (uri.getScheme().equals(URI_SCHEME_REDIS_SENTINEL)) { LettuceAssert.notEmpty(builder.sentinelMasterId, "URI must contain the sentinelMasterId");
/** * Convert a nested URI to decode the underlying path. The translation takes * the authority and parses it into the underlying scheme and authority. * For example, "myscheme://hdfs@nn/my/path" is converted to * "hdfs://nn/my/path". * @param nestedUri the URI from the nested URI * @return the unnested path */ public static Path unnestUri(URI nestedUri) { StringBuilder result = new StringBuilder(); String authority = nestedUri.getAuthority(); if (authority != null) { String[] parts = nestedUri.getAuthority().split("@", 2); result.append(parts[0]); result.append("://"); if (parts.length == 2) { result.append(parts[1]); } } result.append(nestedUri.getPath()); if (nestedUri.getQuery() != null) { result.append("?"); result.append(nestedUri.getQuery()); } if (nestedUri.getFragment() != null) { result.append("#"); result.append(nestedUri.getFragment()); } return new Path(result.toString()); }
/** * Set the URI scheme, AKA the 'protocol.' e.g. * <code>setScheme('https')</code> * * @throws URISyntaxException if the given scheme contains illegal characters. */ public URIBuilder setScheme(String scheme) throws URISyntaxException { this.base = new URI(scheme, base.getUserInfo(), base.getHost(), base.getPort(), base.getPath(), base.getQuery(), base.getFragment()); return this; }
private static URI buildURI(NodeId nodeId, URI baseUri) throws URISyntaxException { final String queryParams = "anonid=" + nodeId.anonymize() + "&version=" + ServerVersion.VERSION.toString(); return new URI( baseUri.getScheme(), baseUri.getUserInfo(), baseUri.getHost(), baseUri.getPort(), baseUri.getPath(), isNullOrEmpty(baseUri.getQuery()) ? queryParams : baseUri.getQuery() + "&" + queryParams, baseUri.getFragment() ); }
/** * The document fragment, without a preceeding '#' * * @param fragment * @return this URIBuilder instance, for method chaining. * @throws URISyntaxException if the given value contains illegal characters. */ public URIBuilder setFragment(String fragment) throws URISyntaxException { this.base = new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), base.getPath(), base.getQuery(), fragment); return this; }
/** * Creates a new {@link URI} from the given URI by replacing the host value. * @param uri Original URI * @param newHostPrefix New host for the uri */ public static URI updateUriHost(URI uri, String newHostPrefix) { try { return new URI(uri.getScheme(), uri.getUserInfo(), newHostPrefix + uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { throw new RuntimeException(e); } } }
/** * Given a URI value create and return a new URI that matches the target one but with the scheme value * supplied to this method. * * @param bindAddr The URI whose scheme value should be altered. * @param scheme The new scheme value to use for the returned URI. * @return a new URI that is a copy of the original except that its scheme matches the supplied one. * @throws java.net.URISyntaxException */ public static URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException { return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(), bindAddr.getQuery(), bindAddr.getFragment()); }
/** * Appends the given path to the given base URI. * * @param base the base URI * @param path the path to append * @return the URI resulting from appending the base and the path * @throws URISyntaxException if URI syntax error is encountered */ public static URI appendPath(URI base, String path) throws URISyntaxException { return new URI(base.getScheme(), base.getAuthority(), PathUtils.concatPath(base.getPath(), path), base.getQuery(), base.getFragment()); }
@Nullable public static URI getUriWithDefaultPath(@Nullable final URI uri, final String path) { if (uri == null) { return null; } try { return new URI( uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), isNullOrEmpty(uri.getPath()) ? path : uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { throw new RuntimeException("Could not parse URI.", e); } }