Package org.apache.http.client.utils
Class URIUtils
- java.lang.Object
-
- org.apache.http.client.utils.URIUtils
-
public class URIUtils extends java.lang.ObjectA collection of utilities forURIs, to workaround bugs within the class or for ease-of-use features.- Since:
- 4.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.net.URIcreateURI(java.lang.String scheme, java.lang.String host, int port, java.lang.String path, java.lang.String query, java.lang.String fragment)Deprecated.(4.2) useURIBuilder.static org.apache.http.HttpHostextractHost(java.net.URI uri)Extracts target host from the givenURI.static java.net.URIresolve(java.net.URI baseURI, java.lang.String reference)Resolves a URI reference against a base URI.static java.net.URIresolve(java.net.URI baseURI, java.net.URI reference)Resolves a URI reference against a base URI.static java.net.URIresolve(java.net.URI originalURI, org.apache.http.HttpHost target, java.util.List<java.net.URI> redirects)Derives the interpreted (absolute) URI that was used to generate the last request.static java.net.URIrewriteURI(java.net.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 java.net.URIrewriteURI(java.net.URI uri, org.apache.http.HttpHost target)A convenience method forrewriteURI(URI, HttpHost, boolean)that always keeps the fragment.static java.net.URIrewriteURI(java.net.URI uri, org.apache.http.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.static java.net.URIrewriteURIForRoute(java.net.URI uri, RouteInfo route)A convenience method that optionally converts the originalURIeither to a relative or an absolute form as required by the specified route.
-
-
-
Method Detail
-
createURI
@Deprecated public static java.net.URI createURI(java.lang.String scheme, java.lang.String host, int port, java.lang.String path, java.lang.String query, java.lang.String fragment) throws java.net.URISyntaxExceptionDeprecated.(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:
java.net.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 java.net.URI rewriteURI(java.net.URI uri, org.apache.http.HttpHost target, boolean dropFragment) throws java.net.URISyntaxExceptionA 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:
java.net.URISyntaxException- If the resulting URI is invalid.
-
rewriteURI
public static java.net.URI rewriteURI(java.net.URI uri, org.apache.http.HttpHost target) throws java.net.URISyntaxExceptionA convenience method forrewriteURI(URI, HttpHost, boolean)that always keeps the fragment.- Throws:
java.net.URISyntaxException
-
rewriteURI
public static java.net.URI rewriteURI(java.net.URI uri) throws java.net.URISyntaxExceptionA 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:
java.net.URISyntaxException- If the resulting URI is invalid.
-
rewriteURIForRoute
public static java.net.URI rewriteURIForRoute(java.net.URI uri, RouteInfo route) throws java.net.URISyntaxExceptionA convenience method that optionally converts the originalURIeither to a relative or an absolute form as required by the specified route.- Parameters:
uri- original URI.- Throws:
java.net.URISyntaxException- If the resulting URI is invalid.- Since:
- 4.4
-
resolve
public static java.net.URI resolve(java.net.URI baseURI, java.lang.String reference)Resolves a URI reference against a base URI. Work-around for bug in java.net.URI (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535)- Parameters:
baseURI- the base URIreference- the URI reference- Returns:
- the resulting URI
-
resolve
public static java.net.URI resolve(java.net.URI baseURI, java.net.URI reference)Resolves a URI reference against a base URI. Work-around for bugs in java.net.URI (e.g. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535)- Parameters:
baseURI- the base URIreference- the URI reference- Returns:
- the resulting URI
-
extractHost
public static org.apache.http.HttpHost extractHost(java.net.URI uri)
Extracts target host from the givenURI.- Parameters:
uri-- Returns:
- the target host if the URI is absolute or
nullif the URI is relative or does not contain a valid host name. - Since:
- 4.1
-
resolve
public static java.net.URI resolve(java.net.URI originalURI, org.apache.http.HttpHost target, java.util.List<java.net.URI> redirects) throws java.net.URISyntaxExceptionDerives 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:
java.net.URISyntaxException
-
-