Package org.apache.http.client.utils
Class URIUtils
- java.lang.Object
-
- org.apache.http.client.utils.URIUtils
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
URIUtils.UriFlag
Flags that control how URI is being rewritten.
-
Field Summary
Fields Modifier and Type Field Description static EnumSet<URIUtils.UriFlag>
DROP_FRAGMENT
Set of uri flags containingURIUtils.UriFlag.DROP_FRAGMENT
.static EnumSet<URIUtils.UriFlag>
DROP_FRAGMENT_AND_NORMALIZE
Set of uri flags containingURIUtils.UriFlag.DROP_FRAGMENT
andURIUtils.UriFlag.NORMALIZE
.static EnumSet<URIUtils.UriFlag>
NO_FLAGS
Empty set of uri flags.static EnumSet<URIUtils.UriFlag>
NORMALIZE
Set of uri flags containingURIUtils.UriFlag.NORMALIZE
.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static URI
createURI(String scheme, String host, int port, String path, String query, String fragment)
Deprecated.(4.2) useURIBuilder
.static HttpHost
extractHost(URI uri)
Extracts target host from the givenURI
.static URI
normalizeSyntax(URI uri)
Removes dot segments according to RFC 3986, section 5.2.4 and Syntax-Based Normalization according to RFC 3986, section 6.2.2.static URI
resolve(URI baseURI, String reference)
Resolves a URI reference against a base URI.static URI
resolve(URI baseURI, URI reference)
Resolves a URI reference against a base URI.static URI
resolve(URI originalURI, HttpHost target, List<URI> redirects)
Derives the interpreted (absolute) URI that was used to generate the last request.static URI
rewriteURI(URI uri)
A convenience method that creates a newURI
whose scheme, host, port, path, query are taken from the existing URI, dropping any fragment or user-information.static URI
rewriteURI(URI uri, HttpHost target)
A convenience method forrewriteURI(URI, HttpHost, EnumSet)
that always keeps the fragment.static URI
rewriteURI(URI uri, HttpHost target, boolean dropFragment)
Deprecated.(4.5.8) UserewriteURI(URI, HttpHost, EnumSet)
static URI
rewriteURI(URI uri, HttpHost target, EnumSet<URIUtils.UriFlag> flags)
A convenience method for creating a newURI
whose scheme, host and port are taken from the target host, but whose path, query and fragment are taken from the existing URI.static URI
rewriteURIForRoute(URI uri, RouteInfo route)
A convenience method that optionally converts the originalURI
either to a relative or an absolute form as required by the specified route.static URI
rewriteURIForRoute(URI uri, RouteInfo route, boolean normalizeUri)
A convenience method that optionally converts the originalURI
either to a relative or an absolute form as required by the specified route.
-
-
-
Field Detail
-
NO_FLAGS
public static final EnumSet<URIUtils.UriFlag> NO_FLAGS
Empty set of uri flags.- Since:
- 4.5.8
-
DROP_FRAGMENT
public static final EnumSet<URIUtils.UriFlag> DROP_FRAGMENT
Set of uri flags containingURIUtils.UriFlag.DROP_FRAGMENT
.- Since:
- 4.5.8
-
NORMALIZE
public static final EnumSet<URIUtils.UriFlag> NORMALIZE
Set of uri flags containingURIUtils.UriFlag.NORMALIZE
.- Since:
- 4.5.8
-
DROP_FRAGMENT_AND_NORMALIZE
public static final EnumSet<URIUtils.UriFlag> DROP_FRAGMENT_AND_NORMALIZE
Set of uri flags containingURIUtils.UriFlag.DROP_FRAGMENT
andURIUtils.UriFlag.NORMALIZE
.- Since:
- 4.5.8
-
-
Method Detail
-
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 aURI
using 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
@Deprecated public static URI rewriteURI(URI uri, HttpHost target, boolean dropFragment) throws URISyntaxException
Deprecated.(4.5.8) UserewriteURI(URI, HttpHost, EnumSet)
A convenience method for creating a newURI
whose 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
public static URI rewriteURI(URI uri, HttpHost target, EnumSet<URIUtils.UriFlag> flags) throws URISyntaxException
A convenience method for creating a newURI
whose scheme, host and port are taken from the target host, but whose path, query and fragment are taken from the existing URI. What exactly is used and how is driven by the passed in flags. 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.flags
- True if the fragment should not be copied.- Throws:
URISyntaxException
- If the resulting URI is invalid.- Since:
- 4.5.8
-
rewriteURI
public static URI rewriteURI(URI uri, HttpHost target) throws URISyntaxException
A convenience method forrewriteURI(URI, HttpHost, EnumSet)
that always keeps the fragment.- Throws:
URISyntaxException
-
rewriteURI
public static URI rewriteURI(URI uri) throws URISyntaxException
A convenience method that creates a newURI
whose 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.
-
rewriteURIForRoute
public static URI rewriteURIForRoute(URI uri, RouteInfo route) throws URISyntaxException
A convenience method that optionally converts the originalURI
either to a relative or an absolute form as required by the specified route.- Parameters:
uri
- original URI.- Throws:
URISyntaxException
- If the resulting URI is invalid.- Since:
- 4.4
-
rewriteURIForRoute
public static URI rewriteURIForRoute(URI uri, RouteInfo route, boolean normalizeUri) throws URISyntaxException
A convenience method that optionally converts the originalURI
either to a relative or an absolute form as required by the specified route.- Parameters:
uri
- original URI.- Throws:
URISyntaxException
- If the resulting URI is invalid.- Since:
- 4.5.8
-
resolve
public static URI resolve(URI baseURI, 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 URI resolve(URI baseURI, 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
-
normalizeSyntax
public static URI normalizeSyntax(URI uri) throws URISyntaxException
Removes dot segments according to RFC 3986, section 5.2.4 and Syntax-Based Normalization according to RFC 3986, section 6.2.2.- Parameters:
uri
- the original URI- Returns:
- the URI without dot segments
- Throws:
URISyntaxException
- Since:
- 4.5
-
extractHost
public static HttpHost extractHost(URI uri)
Extracts target host from the givenURI
.- Parameters:
uri
-- Returns:
- the target host if the URI is absolute or
null
if the URI is relative or does not contain a valid host name. - Since:
- 4.1
-
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, ornull
if not available.redirects
- collection of redirect locations since the original request ornull
if not available.- Returns:
- interpreted (absolute) URI
- Throws:
URISyntaxException
-
-