Class URIUtils


  • public class URIUtils
    extends java.lang.Object
    A collection of utilities for URIs, to workaround bugs within the class or for ease-of-use features.
    Since:
    4.0
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private URIUtils()
      This class should not be instantiated.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static java.net.URI create​(java.lang.String scheme, org.apache.hc.core5.net.URIAuthority host, java.lang.String path)
      Deprecated.
      Use URIBuilder.
      static java.net.URI create​(org.apache.hc.core5.http.HttpHost host, java.lang.String path)
      Deprecated.
      Use URIBuilder.
      static org.apache.hc.core5.http.HttpHost extractHost​(java.net.URI uri)
      Extracts target host from the given URI.
      (package private) static java.net.URI normalizeSyntax​(java.net.URI uri)
      Removes dot segments and performs Syntax-Based Normalization.
      static java.net.URI resolve​(java.net.URI baseURI, java.lang.String reference)
      Resolves a URI reference against a base URI.
      static java.net.URI resolve​(java.net.URI baseURI, java.net.URI reference)
      Resolves a URI reference against a base URI.
      static java.net.URI resolve​(java.net.URI originalURI, org.apache.hc.core5.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.URI rewriteURI​(java.net.URI uri)
      Deprecated.
      Use URIBuilder.
      static java.net.URI rewriteURI​(java.net.URI uri, org.apache.hc.core5.http.HttpHost target)
      Deprecated.
      Use URIBuilder.
      static java.net.URI rewriteURI​(java.net.URI uri, org.apache.hc.core5.http.HttpHost target, boolean dropFragment)
      Deprecated.
      Use URIBuilder.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • URIUtils

        private URIUtils()
        This class should not be instantiated.
    • Method Detail

      • rewriteURI

        @Deprecated
        public static java.net.URI rewriteURI​(java.net.URI uri,
                                              org.apache.hc.core5.http.HttpHost target,
                                              boolean dropFragment)
                                       throws java.net.URISyntaxException
        Deprecated.
        Use URIBuilder.
        A convenience method for creating a new URI 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:
        java.net.URISyntaxException - If the resulting URI is invalid.
      • rewriteURI

        @Deprecated
        public static java.net.URI rewriteURI​(java.net.URI uri,
                                              org.apache.hc.core5.http.HttpHost target)
                                       throws java.net.URISyntaxException
        Deprecated.
        Use URIBuilder.
        A convenience method for rewriteURI(URI, HttpHost, boolean) that always keeps the fragment.
        Throws:
        java.net.URISyntaxException
      • rewriteURI

        @Deprecated
        public static java.net.URI rewriteURI​(java.net.URI uri)
                                       throws java.net.URISyntaxException
        Deprecated.
        Use URIBuilder.
        A convenience method that creates a new URI 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:
        java.net.URISyntaxException - If the resulting URI is invalid.
      • 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 URI
        reference - 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 URI
        reference - the URI reference
        Returns:
        the resulting URI
      • normalizeSyntax

        static java.net.URI normalizeSyntax​(java.net.URI uri)
                                     throws java.net.URISyntaxException
        Removes dot segments and performs Syntax-Based Normalization.
        Parameters:
        uri - the original URI
        Returns:
        the URI without dot segments
        Throws:
        java.net.URISyntaxException
      • extractHost

        public static org.apache.hc.core5.http.HttpHost extractHost​(java.net.URI uri)
        Extracts target host from the given URI.
        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 java.net.URI resolve​(java.net.URI originalURI,
                                           org.apache.hc.core5.http.HttpHost target,
                                           java.util.List<java.net.URI> redirects)
                                    throws java.net.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 a URI.
        Parameters:
        originalURI - original request before any redirects
        target - if the last URI is relative, it is resolved against this target, or null if not available.
        redirects - collection of redirect locations since the original request or null if not available.
        Returns:
        interpreted (absolute) URI
        Throws:
        java.net.URISyntaxException
      • create

        @Deprecated
        public static java.net.URI create​(org.apache.hc.core5.http.HttpHost host,
                                          java.lang.String path)
                                   throws java.net.URISyntaxException
        Deprecated.
        Use URIBuilder.
        Convenience factory method for URI instances.
        Throws:
        java.net.URISyntaxException
        Since:
        5.0
      • create

        @Deprecated
        public static java.net.URI create​(java.lang.String scheme,
                                          org.apache.hc.core5.net.URIAuthority host,
                                          java.lang.String path)
                                   throws java.net.URISyntaxException
        Deprecated.
        Use URIBuilder.
        Convenience factory method for URI instances.
        Throws:
        java.net.URISyntaxException
        Since:
        5.0