Package com.postman.collection
Class Url
java.lang.Object
com.postman.collection.CollectionElement
com.postman.collection.Url
Class to encapsulate the properties in the
url object of a RequestBody object.
Postman SDK Analog: Url.
The URL object properties contain the raw URL itself, the protocol, the port an array of strings for the individual host and path elements, arrays of key/value pairs for query parameters, as well as path variables.
"url": {
"raw": "https://foo.com:8080/bar/:path1/bat.json?foo=1&bar=2",
"host": [
"foo",
"com"
],
"path": [
"bar",
":path1",
"bat.json"
],
"query": [
{
"key": "foo",
"value": "1"
},
{
"key": "bar",
"value": "2"
}
],
"variable": [
{
"key": "path1"
}
],
"protocol": "https",
"port": "8080"
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPathVariable(Property varPath) voidaddPathVariable(String key, String value, String description) Add a variable to the array of query elementsvoidPopulate the elements of thequeryarray with an http query string.voidAdd an element to thequeryarray using raw string values.voidAdd an element to thequeryarray using raw String values, with a description propertyGenerate the raw URL from the component properties of this Url.getHosts()Return the array of elements in thehostarray.getKey()Currently unimplementedgetPaths()Returns the contents of thepathelement arraygetPathVariable(String key) Get an ArrayList<Property> containing the key-value pairs comprising thevariablearray, or null if none exit.getPort()Get the value of theportpropertygetQueryElement(int index) getQueryElement(String key) Return an ArrayList<Property> of key value pairs comprising thequeryarrayGet the raw query string for this URL.getRaw()Returns the value of therawproperty, or null if it has not been set.getUrl(boolean resolvePathVariables) voidremovePathVariable(String key) voidremoveQueryElement(Property queryElement) Remove a query element key-value pair from the array of query elements, if it exists.voidSet the host component of the URL with a string.voidSet the value of the elements in thehostarray with a pre-populated ArrayList<String>voidSet the path element using a String.voidSet the elements of thepathelement arrayvoidsetPathVariable(Property varPath) voidsetPathVariables(PropertyList<Property> variable) Set the values of thevariablearray with a pre-populated ArrayList<Property> containing the key-value parisvoidSet the value of theportpropertyvoidsetProtocol(String rawProtocol) Set the value of theprotocolproperty with a string.voidsetQueries(PropertyList<Property> query) Set the contents of thequeryarray with a pre-populated ArrayList<Property> containing the key value pairsvoidSet the elements of thequeryarray with a stringvoidsetQueryELement(Property element, int index) voidSets the raw URL.Methods inherited from class com.postman.collection.CollectionElement
getCollection, getDefaultCollectionSchema, getDefaultValidationSchema, getParent, getUUID, getValidationMessages, isEquivalentTo, setParent, setUUID, toJson, toJson, validate, validate
-
Constructor Details
-
Url
Create a Url with the specified URL- Parameters:
rawURL- The raw URL- Throws:
DuplicateVariableKeyException
-
Url
Create a Url with the specified host and path.- Parameters:
host- The host, e.g., "foo.com"path- The path, e.g., "/bar/bat"- Throws:
DuplicateVariableKeyException
-
-
Method Details
-
setRaw
Sets the raw URL. The host, path, query,protocl, query and port properties are parsed from the raw url. Parsing does not always result in these properties being filled, as collection URLs are not always valid URLs in the java sense. For example, URLs containing variables may not produce discrete values, eg.{{baseUrl}}/{{theHost}}/foo/{{filename}}- Parameters:
rawUrl- The raw URL as a String. The URL is not validated- Throws:
DuplicateVariableKeyException
-
addPathVariable
public void addPathVariable(String key, String value, String description) throws DuplicateVariableKeyException Add a variable to the array of query elements- Parameters:
key- Value for thekeypropertyvalue- Value for thevaluepropertydescription- Value for thedescriptionproperty- Throws:
DuplicateVariableKeyException
-
setPath
Set the path element using a String. Elements of thepatharray are parsed out- Parameters:
rawPath- the raw path, e.g., /foo/:path1/bat- Throws:
DuplicateVariableKeyException
-
setQuery
Set the elements of thequeryarray with a string- Parameters:
rawQuery- String with the query component, e.g., "foo=bar&bat=big"
-
setHost
Set the host component of the URL with a string. The elements of thehostarray are parsed out.- Parameters:
rawHost- The host as a string, e.g., foo.com
-
generateURL
Generate the raw URL from the component properties of this Url. Ifrawhas been set, the output of this method should equal the raw URL provided.- Returns:
- The generated URL. Note that this may not be a valid URL
-
setProtocol
Set the value of theprotocolproperty with a string. This method will attempt to resolve the provided value to either 'http' or 'https', or null if a reasonable guess results in anything else.- Parameters:
rawProtocol- The protocol, eg http
-
getRaw
Returns the value of therawproperty, or null if it has not been set. Note that the Postman application doesn't seem to mind ingesting URLs with no value in therawproperty.- Returns:
- String
-
getHosts
Return the array of elements in thehostarray.- Returns:
- ArrayList<String> Elements of the
hostproperty of this url.
-
getProtocol
- Returns:
- String
-
getUrl
- Parameters:
resolvePathVariables-- Returns:
- String
- Throws:
VariableResolutionException
-
setHosts
Set the value of the elements in thehostarray with a pre-populated ArrayList<String>- Parameters:
host- ArrayList<String> with host elements.
-
getPaths
Returns the contents of thepathelement array- Returns:
- ArrayList<String> containing the path elements
-
setPaths
Set the elements of thepathelement array- Parameters:
path- ArrayList<String> containing the path elements
-
getQueryElements
Return an ArrayList<Property> of key value pairs comprising thequeryarray- Returns:
- ArrayList<
Property> containing the key value paris
-
getQueryElement
- Parameters:
key-- Returns:
- Property
-
getQueryElement
- Parameters:
index-- Returns:
- Property
- Throws:
IllegalPropertyAccessException
-
setQueryELement
- Parameters:
element-index-- Throws:
IllegalPropertyAccessException
-
getQueryString
Get the raw query string for this URL.- Returns:
-
removeQueryElement
Remove a query element key-value pair from the array of query elements, if it exists.- Parameters:
queryElement-
-
setQueries
Set the contents of thequeryarray with a pre-populated ArrayList<Property> containing the key value pairs- Parameters:
query-
-
getPathVariables
Get an ArrayList<Property> containing the key-value pairs comprising thevariablearray, or null if none exit.- Returns:
- ArrayList<
Property> The ArrayList containing the key-value pairs, or null if there are none.
-
getPathVariable
- Parameters:
key-- Returns:
- Property
-
setPathVariables
Set the values of thevariablearray with a pre-populated ArrayList<Property> containing the key-value paris- Parameters:
variable- the ArrayList<Property> containing the key-value paris
-
setPathVariable
- Parameters:
varPath-
-
addPathVariable
- Parameters:
varPath-- Throws:
DuplicateVariableKeyException
-
removePathVariable
- Parameters:
key-
-
getKey
Currently unimplemented- Specified by:
getKeyin classCollectionElement- Returns:
- String
-
addQuery
Add an element to thequeryarray using raw string values.- Parameters:
key- The keyvalue- The value
-
addQuery
Add an element to thequeryarray using raw String values, with a description property- Parameters:
key- The keyvalue- The valuedescription- The description
-
addQuery
Populate the elements of thequeryarray with an http query string. Replaces any existing query string.- Parameters:
queryString- The query string, e.g., foo=bar&bat=bing
-
getPort
Get the value of theportproperty- Returns:
- String The port
-
setPort
Set the value of theportproperty- Parameters:
port- The port as a string.
-