Interface Uri

All Superinterfaces:
org.wiremock.stringparser.ParsedString
All Known Subinterfaces:
AbsoluteUri, AbsoluteUrl, BaseUrl, OpaqueUri, Origin, PathAndQuery, RelativeUrl, SchemeRelativeUrl, ServersideAbsoluteUrl, Url, UrlWithAuthority
All Known Implementing Classes:
BaseUrlValue

public sealed interface Uri extends org.wiremock.stringparser.ParsedString permits AbsoluteUri, Url (not exhaustive)
Represents a URI reference as defined in RFC 3986. The name Uri is used in preference to UriReference to maintain consistency with the names Url, AbsoluteUrl and RelativeUrl elsewhere in the hierarchy, which are chosen for familiarity to developers.

An Uri is either an AbsoluteUri or an Url. Uris are used to identify resources and can be resolved against an AbsoluteUri to produce an AbsoluteUri.

Implementations must be immutable and thread-safe.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
     
    static interface 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new builder for constructing URI references.
    builder(Uri uri)
    Creates a new builder initialized with the values from the given URI reference.
    @Nullable Authority
    Returns the authority component of this URI reference, or null if there is no authority.
    @Nullable Fragment
    Returns the fragment component of this URI reference, or null if there is no fragment.
    default @Nullable Host
    Returns the host component from the authority, or null if there is no authority.
    Returns the path component of this URI reference.
    default @Nullable Port
    Returns the port component from the authority, or null if there is no authority or no port.
    @Nullable Query
    Returns the query component of this URI reference, or null if there is no query.
    default Query
     
    default @Nullable Port
    Returns the resolved port, which is either the explicitly defined port or the default port for the scheme.
    @Nullable Scheme
    Returns the scheme component of this URI, or null if it is a URI Reference and so there is no scheme.
    default @Nullable UserInfo
    Returns the user info component from the authority, or null if there is no authority or no user info.
    boolean
    Returns true if this is an absolute URI (either an absolute URL or an Opaque URI).
    boolean
    Returns true if this is an absolute URL (has a scheme and authority).
    boolean
    Returns true if this is an Opaque URI (has a scheme but no authority).
    boolean
    Returns true if this is a relative reference (has no scheme).
    static Uri
    of(URI uri)
    Converts a java.net.URI to a Uri.
    static Uri
    Parses a string into a URI reference.
    default URI
    Converts a Uri to a java.net.URI

    Methods inherited from interface org.wiremock.stringparser.ParsedString

    toString
  • Method Details

    • getScheme

      @Nullable Scheme getScheme()
      Returns the scheme component of this URI, or null if it is a URI Reference and so there is no scheme.
      Returns:
      the scheme component, or null if absent
    • getAuthority

      @Nullable Authority getAuthority()
      Returns the authority component of this URI reference, or null if there is no authority.
      Returns:
      the authority component, or null if absent
    • getPath

      Path getPath()
      Returns the path component of this URI reference.
      Returns:
      the path component, never null
    • getQuery

      @Nullable Query getQuery()
      Returns the query component of this URI reference, or null if there is no query.
      Returns:
      the query component, or null if absent
    • getQueryOrEmpty

      default Query getQueryOrEmpty()
    • getFragment

      @Nullable Fragment getFragment()
      Returns the fragment component of this URI reference, or null if there is no fragment.
      Returns:
      the fragment component, or null if absent
    • isRelative

      boolean isRelative()
      Returns true if this is a relative reference (has no scheme).
      Returns:
      true if this is a relative reference
    • isAbsolute

      boolean isAbsolute()
      Returns true if this is an absolute URI (either an absolute URL or an Opaque URI).
      Returns:
      true if this is an absolute URI
    • isAbsoluteUrl

      boolean isAbsoluteUrl()
      Returns true if this is an absolute URL (has a scheme and authority).
      Returns:
      true if this is an absolute URL
    • isOpaqueUri

      boolean isOpaqueUri()
      Returns true if this is an Opaque URI (has a scheme but no authority).
      Returns:
      true if this is an Opaque URI
    • getUserInfo

      default @Nullable UserInfo getUserInfo()
      Returns the user info component from the authority, or null if there is no authority or no user info.
      Returns:
      the user info component, or null if absent
    • getHost

      default @Nullable Host getHost()
      Returns the host component from the authority, or null if there is no authority.
      Returns:
      the host component, or null if absent
    • getPort

      default @Nullable Port getPort()
      Returns the port component from the authority, or null if there is no authority or no port.
      Returns:
      the port component, or null if absent
    • getResolvedPort

      default @Nullable Port getResolvedPort()
      Returns the resolved port, which is either the explicitly defined port or the default port for the scheme.
      Returns:
      the resolved port, or null if no port is defined and no default exists for the scheme
    • toJavaUri

      default URI toJavaUri() throws IllegalArgumentException
      Converts a Uri to a java.net.URI

      This may fail with an IllegalArgumentException because Uri is more lenient than java.net.URI. Calling Uri.normalise().toUri() should nearly always work; the only cases where it will not are:

      1. scheme: - no authority, no path, no query, no fragment
      2. scheme:#fragment - no authority, no path, no query
      3. scheme:// - empty authority, no path, no query, no fragment
      Returns:
      this as a java.net.URI
      Throws:
      IllegalArgumentException - if this is not a valid java.net.URI
    • parse

      static Uri parse(String uri) throws IllegalUri
      Parses a string into a URI reference.
      Parameters:
      uri - the string to parse
      Returns:
      the parsed URI reference
      Throws:
      IllegalUri - if the string is not a valid URI reference
    • of

      static Uri of(URI uri)
      Converts a java.net.URI to a Uri.

      This is guaranteed to succeed - if it throws an exception it is a bug.

      Parameters:
      uri - the value as a java.net.URI
      Returns:
      the value as a Uri
    • builder

      static Uri.Builder builder()
      Creates a new builder for constructing URI references.
      Returns:
      a new builder
    • builder

      static Uri.Builder builder(Uri uri)
      Creates a new builder initialized with the values from the given URI reference.
      Parameters:
      uri - the URI reference to copy values from
      Returns:
      a new builder