List of usage examples for java.net URI getQuery
public String getQuery()
From source file:org.apache.hadoop.fs.HarFileSystem.java
/** * decode the raw URI to get the underlying URI * @param rawURI raw Har URI//from w w w . j a v a 2 s . c o m * @return filtered URI of the underlying fileSystem */ private URI decodeHarURI(URI rawURI, Configuration conf) throws IOException { String tmpAuth = rawURI.getAuthority(); //we are using the default file //system in the config //so create a underlying uri and //return it if (tmpAuth == null) { //create a path return FileSystem.getDefaultUri(conf); } String authority = rawURI.getAuthority(); int i = authority.indexOf('-'); if (i < 0) { throw new IOException("URI: " + rawURI + " is an invalid Har URI since '-' not found." + " Expecting har://<scheme>-<host>/<path>."); } if (rawURI.getQuery() != null) { // query component not allowed throw new IOException("query component in Path not supported " + rawURI); } URI tmp; try { // convert <scheme>-<host> to <scheme>://<host> URI baseUri = new URI(authority.replaceFirst("-", "://")); tmp = new URI(baseUri.getScheme(), baseUri.getAuthority(), rawURI.getPath(), rawURI.getQuery(), rawURI.getFragment()); } catch (URISyntaxException e) { throw new IOException( "URI: " + rawURI + " is an invalid Har URI. Expecting har://<scheme>-<host>/<path>."); } return tmp; }
From source file:org.jclouds.rest.internal.RestAnnotationProcessorTest.java
public void testUnEncodeQuery() { URI expects = URI.create( "http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriancole-blobstore.testObjectOperations&metadata=chef:sushi&metadata=foo:bar&sessionToken=775ef26e-0740-4707-ad92-afe9814bc436"); URI start = URI.create( "http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriancole-blobstore.testObjectOperations&metadata=chef%3Asushi&metadata=foo%3Abar&sessionToken=775ef26e-0740-4707-ad92-afe9814bc436"); URI value = RestAnnotationProcessor.replaceQuery(start, start.getQuery(), null, '/', ':'); assertEquals(value, expects);// w ww. j a v a2 s .c o m }
From source file:org.uberfire.java.nio.fs.jgit.JGitFileSystemProvider.java
private boolean hasForceFlag(URI uri) { checkNotNull("uri", uri); return uri.getQuery() != null && uri.getQuery().contains("force"); }
From source file:org.uberfire.java.nio.fs.jgit.JGitFileSystemProvider.java
private boolean hasSyncFlag(final URI uri) { checkNotNull("uri", uri); return uri.getQuery() != null && uri.getQuery().contains("sync"); }
From source file:org.uberfire.java.nio.fs.jgit.JGitFileSystemProvider.java
private boolean hasPushFlag(final URI uri) { checkNotNull("uri", uri); return uri.getQuery() != null && uri.getQuery().contains("push"); }
From source file:org.soyatec.windowsazure.internal.util.HttpUtilities.java
/** * Create a request URI./*from w w w . j ava 2s .c o m*/ * * @param baseUri * @param usePathStyleUris * @param accountName * @param containerName * @param blobName * @param timeout * @param queryParameters * @param uriComponents * @param appendQuery * @return URI */ public static URI createRequestUri(URI baseUri, boolean usePathStyleUris, String accountName, String containerName, String blobName, TimeSpan timeout, NameValueCollection queryParameters, ResourceUriComponents uriComponents, String appendQuery) { URI uri = HttpRequestAccessor.constructResourceUri(baseUri, uriComponents, usePathStyleUris); if (queryParameters != null) { if (queryParameters.get(QueryParams.QueryParamTimeout) == null && timeout != null) { queryParameters.put(QueryParams.QueryParamTimeout, timeout.toSeconds()); } StringBuilder sb = new StringBuilder(); boolean firstParam = true; boolean appendBlockAtTail = false; for (Object key : queryParameters.keySet()) { String queryKey = (String) key; if (queryKey.equalsIgnoreCase(QueryParams.QueryParamBlockId)) { appendBlockAtTail = true; continue; } if (!firstParam) { sb.append("&"); } sb.append(Utilities.encode(queryKey)); sb.append('='); sb.append(Utilities.encode(queryParameters.getSingleValue(queryKey))); firstParam = false; } /* * You shuold add blockid as the last query parameters for put block * request, or an exception you will get. */ if (appendBlockAtTail) { String queryKey = QueryParams.QueryParamBlockId; sb.append("&"); sb.append(Utilities.encode(queryKey)); sb.append('='); sb.append(Utilities.encode(queryParameters.getSingleValue(queryKey))); } if (!Utilities.isNullOrEmpty(appendQuery)) { if (sb.length() > 0) { sb.append("&"); } // @NOTE: escape char sb.append(appendQuery.replaceAll(" ", "%20")); } if (sb.length() > 0) { try { String p = getNormalizePath(uri).replaceAll(" ", "%20"); return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), p, (uri.getQuery() == null ? Utilities.emptyString() : uri.getQuery()) + sb.toString(), uri.getFragment()); } catch (URISyntaxException e) { Logger.error("", e); } } return uri; } else { return uri; } }
From source file:org.apache.nifi.registry.web.api.ApplicationResource.java
protected URI getBaseUri() { final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder(); URI uri = uriBuilder.build(); try {//from www . j ava 2s. c o m // check for proxy settings final String scheme = getFirstHeaderValue(PROXY_SCHEME_HTTP_HEADER, FORWARDED_PROTO_HTTP_HEADER); final String host = getFirstHeaderValue(PROXY_HOST_HTTP_HEADER, FORWARDED_HOST_HTTP_HEADER); final String port = getFirstHeaderValue(PROXY_PORT_HTTP_HEADER, FORWARDED_PORT_HTTP_HEADER); String baseContextPath = getFirstHeaderValue(PROXY_CONTEXT_PATH_HTTP_HEADER, FORWARDED_CONTEXT_HTTP_HEADER); // if necessary, prepend the context path String resourcePath = uri.getPath(); if (baseContextPath != null) { // normalize context path if (!baseContextPath.startsWith("/")) { baseContextPath = "/" + baseContextPath; } if (baseContextPath.endsWith("/")) { baseContextPath = StringUtils.substringBeforeLast(baseContextPath, "/"); } // determine the complete resource path resourcePath = baseContextPath + resourcePath; } // determine the port uri int uriPort = uri.getPort(); if (port != null) { if (StringUtils.isWhitespace(port)) { uriPort = -1; } else { try { uriPort = Integer.parseInt(port); } catch (final NumberFormatException nfe) { logger.warn(String.format( "Unable to parse proxy port HTTP header '%s'. Using port from request URI '%s'.", port, uriPort)); } } } // construct the URI uri = new URI((StringUtils.isBlank(scheme)) ? uri.getScheme() : scheme, uri.getUserInfo(), (StringUtils.isBlank(host)) ? uri.getHost() : host, uriPort, resourcePath, uri.getQuery(), uri.getFragment()); } catch (final URISyntaxException use) { throw new UriBuilderException(use); } return uri; }
From source file:com.microsoft.azure.storage.core.Utility.java
/** * Determines the relative difference between the two specified URIs. * /*ww w . j a v a 2 s . c o m*/ * @param baseURI * A <code>java.net.URI</code> object that represents the base URI for which <code>toUri</code> will be * made relative. * @param toUri * A <code>java.net.URI</code> object that represents the URI to make relative to <code>baseURI</code>. * * @return A <code>String</code> that either represents the relative URI of <code>toUri</code> to * <code>baseURI</code>, or the URI of <code>toUri</code> itself, depending on whether the hostname and * scheme are identical for <code>toUri</code> and <code>baseURI</code>. If the hostname and scheme of * <code>baseURI</code> and <code>toUri</code> are identical, this method returns an unencoded relative URI * such that if appended to <code>baseURI</code>, it will yield <code>toUri</code>. If the hostname or * scheme of <code>baseURI</code> and <code>toUri</code> are not identical, this method returns an unencoded * full URI specified by <code>toUri</code>. * * @throws URISyntaxException * If <code>baseURI</code> or <code>toUri</code> is invalid. */ public static String safeRelativize(final URI baseURI, final URI toUri) throws URISyntaxException { // For compatibility followed // http://msdn.microsoft.com/en-us/library/system.uri.makerelativeuri.aspx // if host and scheme are not identical return from uri if (!baseURI.getHost().equals(toUri.getHost()) || !baseURI.getScheme().equals(toUri.getScheme())) { return toUri.toString(); } final String basePath = baseURI.getPath(); String toPath = toUri.getPath(); int truncatePtr = 1; // Seek to first Difference // int maxLength = Math.min(basePath.length(), toPath.length()); int m = 0; int ellipsesCount = 0; for (; m < basePath.length(); m++) { if (m >= toPath.length()) { if (basePath.charAt(m) == '/') { ellipsesCount++; } } else { if (basePath.charAt(m) != toPath.charAt(m)) { break; } else if (basePath.charAt(m) == '/') { truncatePtr = m + 1; } } } // ../containername and ../containername/{path} should increment the truncatePtr // otherwise toPath will incorrectly begin with /containername if (m < toPath.length() && toPath.charAt(m) == '/') { // this is to handle the empty directory case with the '/' delimiter // for example, ../containername/ and ../containername// should not increment the truncatePtr if (!(toPath.charAt(m - 1) == '/' && basePath.charAt(m - 1) == '/')) { truncatePtr = m + 1; } } if (m == toPath.length()) { // No path difference, return query + fragment return new URI(null, null, null, toUri.getQuery(), toUri.getFragment()).toString(); } else { toPath = toPath.substring(truncatePtr); final StringBuilder sb = new StringBuilder(); while (ellipsesCount > 0) { sb.append("../"); ellipsesCount--; } if (!Utility.isNullOrEmpty(toPath)) { sb.append(toPath); } if (!Utility.isNullOrEmpty(toUri.getQuery())) { sb.append("?"); sb.append(toUri.getQuery()); } if (!Utility.isNullOrEmpty(toUri.getFragment())) { sb.append("#"); sb.append(toUri.getRawFragment()); } return sb.toString(); } }
From source file:com.android.exchange.EasSyncService.java
@Override public void reset() { synchronized (getSynchronizer()) { if (mPendingPost != null) { URI uri = mPendingPost.getURI(); if (uri != null) { String query = uri.getQuery(); if (query.startsWith("Cmd=Ping")) { userLog("Reset, aborting Ping"); mPostReset = true;//from www.j ava 2 s .c om mPendingPost.abort(); } } } } }