Package org.wiremock.url
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 ClassesModifier and TypeInterfaceDescriptionstatic interfacestatic interfaceUri.Transformer<SELF extends Uri.Transformer<SELF>> -
Method Summary
Modifier and TypeMethodDescriptionstatic Uri.Builderbuilder()Creates a new builder for constructing URI references.static Uri.BuilderCreates a new builder initialized with the values from the given URI reference.@Nullable AuthorityReturns the authority component of this URI reference, ornullif there is no authority.@Nullable FragmentReturns the fragment component of this URI reference, ornullif there is no fragment.default @Nullable HostgetHost()Returns the host component from the authority, ornullif there is no authority.getPath()Returns the path component of this URI reference.default @Nullable PortgetPort()Returns the port component from the authority, ornullif there is no authority or no port.@Nullable QuerygetQuery()Returns the query component of this URI reference, ornullif there is no query.default Querydefault @Nullable PortReturns the resolved port, which is either the explicitly defined port or the default port for the scheme.@Nullable SchemeReturns the scheme component of this URI, ornullif it is a URI Reference and so there is no scheme.default @Nullable UserInfoReturns the user info component from the authority, ornullif there is no authority or no user info.booleanReturnstrueif this is an absolute URI (either an absolute URL or an Opaque URI).booleanReturnstrueif this is an absolute URL (has a scheme and authority).booleanReturnstrueif this is an Opaque URI (has a scheme but no authority).booleanReturnstrueif this is a relative reference (has no scheme).static UriConverts ajava.net.URIto aUri.static UriParses a string into a URI reference.default URIConverts aUrito ajava.net.URIMethods inherited from interface org.wiremock.stringparser.ParsedString
toString
-
Method Details
-
getScheme
@Nullable Scheme getScheme()Returns the scheme component of this URI, ornullif it is a URI Reference and so there is no scheme.- Returns:
- the scheme component, or
nullif absent
-
getAuthority
@Nullable Authority getAuthority()Returns the authority component of this URI reference, ornullif there is no authority.- Returns:
- the authority component, or
nullif 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, ornullif there is no query.- Returns:
- the query component, or
nullif absent
-
getQueryOrEmpty
-
getFragment
@Nullable Fragment getFragment()Returns the fragment component of this URI reference, ornullif there is no fragment.- Returns:
- the fragment component, or
nullif absent
-
isRelative
boolean isRelative()Returnstrueif this is a relative reference (has no scheme).- Returns:
trueif this is a relative reference
-
isAbsolute
boolean isAbsolute()Returnstrueif this is an absolute URI (either an absolute URL or an Opaque URI).- Returns:
trueif this is an absolute URI
-
isAbsoluteUrl
boolean isAbsoluteUrl()Returnstrueif this is an absolute URL (has a scheme and authority).- Returns:
trueif this is an absolute URL
-
isOpaqueUri
boolean isOpaqueUri()Returnstrueif this is an Opaque URI (has a scheme but no authority).- Returns:
trueif this is an Opaque URI
-
getUserInfo
Returns the user info component from the authority, ornullif there is no authority or no user info.- Returns:
- the user info component, or
nullif absent
-
getHost
Returns the host component from the authority, ornullif there is no authority.- Returns:
- the host component, or
nullif absent
-
getPort
Returns the port component from the authority, ornullif there is no authority or no port.- Returns:
- the port component, or
nullif absent
-
getResolvedPort
Returns the resolved port, which is either the explicitly defined port or the default port for the scheme.- Returns:
- the resolved port, or
nullif no port is defined and no default exists for the scheme
-
toJavaUri
Converts aUrito ajava.net.URIThis may fail with an
IllegalArgumentExceptionbecauseUriis more lenient thanjava.net.URI. CallingUri.normalise().toUri()should nearly always work; the only cases where it will not are:scheme:- no authority, no path, no query, no fragmentscheme:#fragment- no authority, no path, no queryscheme://- empty authority, no path, no query, no fragment
- Returns:
- this as a
java.net.URI - Throws:
IllegalArgumentException- if this is not a validjava.net.URI
-
parse
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
Converts ajava.net.URIto aUri.This is guaranteed to succeed - if it throws an exception it is a bug.
- Parameters:
uri- the value as ajava.net.URI- Returns:
- the value as a
Uri
-
builder
Creates a new builder for constructing URI references.- Returns:
- a new builder
-
builder
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
-