public class UriSpec extends Object implements Iterable<UriSpec.Part>
An abstraction for specifying a URI for an instance allowing for variable substitutions.
A Uri spec is a string with optional replacement fields. A replacement field begins with
an open brace and ends with a close brace. The value between the braces is the name of the
field. e.g. "{scheme}://foo.com:{port}" has two replacement fields named "scheme" and "port".
Several pre-defined fields are listed as constants in this class (e.g. FIELD_SCHEME
).
Modifier and Type | Class and Description |
---|---|
static class |
UriSpec.Part
Represents one token in the Uri spec
|
Modifier and Type | Field and Description |
---|---|
static String |
FIELD_ADDRESS
If a
ServiceInstance is passed when building, the replacement is ServiceInstance.getAddress() |
static String |
FIELD_CLOSE_BRACE
Always replaced with '}' - i.e.
|
static String |
FIELD_ID
If a
ServiceInstance is passed when building, the replacement is ServiceInstance.getId() |
static String |
FIELD_NAME
If a
ServiceInstance is passed when building, the replacement is ServiceInstance.getName() |
static String |
FIELD_OPEN_BRACE
Always replaced with '{' - i.e.
|
static String |
FIELD_PORT
If a
ServiceInstance is passed when building, the replacement is ServiceInstance.getPort() |
static String |
FIELD_REGISTRATION_TIME_UTC
If a
ServiceInstance is passed when building, the replacement is ServiceInstance.getRegistrationTimeUTC() |
static String |
FIELD_SCHEME
This defaults to "http".
|
static String |
FIELD_SERVICE_TYPE
If a
ServiceInstance is passed when building, the replacement is ServiceInstance.getServiceType() |
static String |
FIELD_SSL_PORT
If a
ServiceInstance is passed when building, the replacement is ServiceInstance.getSslPort() |
Modifier and Type | Method and Description |
---|---|
void |
add(UriSpec.Part part)
Add a part to the end of the list
|
String |
build()
Build into a UriSpec string
|
String |
build(Map<String,Object> variables)
Build into a UriSpec string
|
String |
build(ServiceInstance<?> serviceInstance)
Build into a UriSpec string
|
String |
build(ServiceInstance<?> serviceInstance,
Map<String,Object> variables)
Build into a UriSpec string
|
boolean |
equals(Object o) |
List<UriSpec.Part> |
getParts() |
int |
hashCode() |
Iterator<UriSpec.Part> |
iterator() |
void |
remove(UriSpec.Part part)
Remove the given part
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public static final String FIELD_SCHEME
ServiceInstance
is passed when building and an sslPort
is specified in the instance, the replacement is "https".public static final String FIELD_NAME
ServiceInstance
is passed when building, the replacement is ServiceInstance.getName()
public static final String FIELD_ID
ServiceInstance
is passed when building, the replacement is ServiceInstance.getId()
public static final String FIELD_ADDRESS
ServiceInstance
is passed when building, the replacement is ServiceInstance.getAddress()
public static final String FIELD_PORT
ServiceInstance
is passed when building, the replacement is ServiceInstance.getPort()
public static final String FIELD_SSL_PORT
ServiceInstance
is passed when building, the replacement is ServiceInstance.getSslPort()
public static final String FIELD_REGISTRATION_TIME_UTC
ServiceInstance
is passed when building, the replacement is ServiceInstance.getRegistrationTimeUTC()
public static final String FIELD_SERVICE_TYPE
ServiceInstance
is passed when building, the replacement is ServiceInstance.getServiceType()
public static final String FIELD_OPEN_BRACE
public static final String FIELD_CLOSE_BRACE
public UriSpec()
public UriSpec(String rawSpec)
rawSpec
- the spec to parsepublic String build()
public String build(ServiceInstance<?> serviceInstance)
serviceInstance
- instance to use for pre-defined replacement fieldspublic String build(Map<String,Object> variables)
variables
- a mapping of field replacement names to values. Note: any fields listed
in this map override pre-defined fieldspublic String build(ServiceInstance<?> serviceInstance, Map<String,Object> variables)
serviceInstance
- instance to use for pre-defined replacement fieldsvariables
- a mapping of field replacement names to values. Note: any fields listed
in this map override pre-defined fieldspublic Iterator<UriSpec.Part> iterator()
iterator
in interface Iterable<UriSpec.Part>
public List<UriSpec.Part> getParts()
public void add(UriSpec.Part part)
part
- part to addpublic void remove(UriSpec.Part part)
part
- the partCopyright © 2011–2023 The Apache Software Foundation. All rights reserved.