Class URIUtils
java.lang.Object
org.apache.http.client.utils.URIUtils
A collection of utilities for
URIs, to workaround
bugs within the class or for ease-of-use features.- Since:
- 4.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic URIDeprecated.static HttpHostextractHost(URI uri) Extracts target host from the givenURI.static URIResolves a URI reference against a base URI.static URIResolves a URI reference against a base URI.static URIDerives the interpreted (absolute) URI that was used to generate the last request.static URIrewriteURI(URI uri) A convenience method that creates a newURIwhose scheme, host, port, path, query are taken from the existing URI, dropping any fragment or user-information.static URIrewriteURI(URI uri, HttpHost target) A convenience method forrewriteURI(URI, HttpHost, boolean)that always keeps the fragment.static URIrewriteURI(URI uri, HttpHost target, boolean dropFragment) A convenience method for creating a newURIwhose scheme, host and port are taken from the target host, but whose path, query and fragment are taken from the existing URI.
-
Method Details
-
createURI
@Deprecated public static URI createURI(String scheme, String host, int port, String path, String query, String fragment) throws URISyntaxException Deprecated.(4.2) useURIBuilder.Constructs aURIusing all the parameters. This should be used instead ofURI(String, String, String, int, String, String, String)or any of the other URI multi-argument URI constructors.- Parameters:
scheme- Scheme namehost- Host nameport- Port numberpath- Pathquery- Queryfragment- Fragment- Throws:
URISyntaxException- If both a scheme and a path are given but the path is relative, if the URI string constructed from the given components violates RFC 2396, or if the authority component of the string is present but cannot be parsed as a server-based authority
-
rewriteURI
public static URI rewriteURI(URI uri, HttpHost target, boolean dropFragment) throws URISyntaxException A convenience method for creating a newURIwhose scheme, host and port are taken from the target host, but whose path, query and fragment are taken from the existing URI. The fragment is only used if dropFragment is false. The path is set to "/" if not explicitly specified.- Parameters:
uri- Contains the path, query and fragment to use.target- Contains the scheme, host and port to use.dropFragment- True if the fragment should not be copied.- Throws:
URISyntaxException- If the resulting URI is invalid.
-
rewriteURI
A convenience method forrewriteURI(URI, HttpHost, boolean)that always keeps the fragment.- Throws:
URISyntaxException
-
rewriteURI
A convenience method that creates a newURIwhose scheme, host, port, path, query are taken from the existing URI, dropping any fragment or user-information. The path is set to "/" if not explicitly specified. The existing URI is returned unmodified if it has no fragment or user-information and has a path.- Parameters:
uri- original URI.- Throws:
URISyntaxException- If the resulting URI is invalid.
-
resolve
Resolves a URI reference against a base URI. Work-around for bug in java.net.URI (invalid input: '<'http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>)- Parameters:
baseURI- the base URIreference- the URI reference- Returns:
- the resulting URI
-
resolve
Resolves a URI reference against a base URI. Work-around for bugs in java.net.URI (e.g. invalid input: '<'http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>)- Parameters:
baseURI- the base URIreference- the URI reference- Returns:
- the resulting URI
-
extractHost
-
resolve
public static URI resolve(URI originalURI, HttpHost target, List<URI> redirects) throws URISyntaxException Derives the interpreted (absolute) URI that was used to generate the last request. This is done by extracting the request-uri and target origin for the last request and scanning all the redirect locations for the last fragment identifier, then combining the result into aURI.- Parameters:
originalURI- original request before any redirectstarget- if the last URI is relative, it is resolved against this target, ornullif not available.redirects- collection of redirect locations since the original request ornullif not available.- Returns:
- interpreted (absolute) URI
- Throws:
URISyntaxException
-
URIBuilder.