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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addPathVariable
(Property varPath) void
addPathVariable
(String key, String value, String description) Add a variable to the array of query elementsvoid
Populate the elements of thequery
array with an http query string.void
Add an element to thequery
array using raw string values.void
Add an element to thequery
array 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 thehost
array.getKey()
Currently unimplementedgetPaths()
Returns the contents of thepath
element arraygetPathVariable
(String key) Get an ArrayList<Property
> containing the key-value pairs comprising thevariable
array, or null if none exit.getPort()
Get the value of theport
propertygetQueryElement
(int index) getQueryElement
(String key) Return an ArrayList<Property
> of key value pairs comprising thequery
arrayGet the raw query string for this URL.getRaw()
Returns the value of theraw
property, or null if it has not been set.getUrl
(boolean resolvePathVariables) void
removePathVariable
(String key) void
removeQueryElement
(Property queryElement) Remove a query element key-value pair from the array of query elements, if it exists.void
Set the host component of the URL with a string.void
Set the value of the elements in thehost
array with a pre-populated ArrayList<String>void
Set the path element using a String.void
Set the elements of thepath
element arrayvoid
setPathVariable
(Property varPath) void
setPathVariables
(PropertyList<Property> variable) Set the values of thevariable
array with a pre-populated ArrayList<Property
> containing the key-value parisvoid
Set the value of theport
propertyvoid
setProtocol
(String rawProtocol) Set the value of theprotocol
property with a string.void
setQueries
(PropertyList<Property> query) Set the contents of thequery
array with a pre-populated ArrayList<Property
> containing the key value pairsvoid
Set the elements of thequery
array with a stringvoid
setQueryELement
(Property element, int index) void
Sets 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 thekey
propertyvalue
- Value for thevalue
propertydescription
- Value for thedescription
property- Throws:
DuplicateVariableKeyException
-
setPath
Set the path element using a String. Elements of thepath
array are parsed out- Parameters:
rawPath
- the raw path, e.g., /foo/:path1/bat- Throws:
DuplicateVariableKeyException
-
setQuery
Set the elements of thequery
array 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 thehost
array 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. Ifraw
has 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 theprotocol
property 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 theraw
property, or null if it has not been set. Note that the Postman application doesn't seem to mind ingesting URLs with no value in theraw
property.- Returns:
- String
-
getHosts
Return the array of elements in thehost
array.- Returns:
- ArrayList<String> Elements of the
host
property of this url.
-
getProtocol
- Returns:
- String
-
getUrl
- Parameters:
resolvePathVariables
-- Returns:
- String
- Throws:
VariableResolutionException
-
setHosts
Set the value of the elements in thehost
array with a pre-populated ArrayList<String>- Parameters:
host
- ArrayList<String> with host elements.
-
getPaths
Returns the contents of thepath
element array- Returns:
- ArrayList<String> containing the path elements
-
setPaths
Set the elements of thepath
element array- Parameters:
path
- ArrayList<String> containing the path elements
-
getQueryElements
Return an ArrayList<Property
> of key value pairs comprising thequery
array- 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 thequery
array with a pre-populated ArrayList<Property
> containing the key value pairs- Parameters:
query
-
-
getPathVariables
Get an ArrayList<Property
> containing the key-value pairs comprising thevariable
array, 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 thevariable
array 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:
getKey
in classCollectionElement
- Returns:
- String
-
addQuery
Add an element to thequery
array using raw string values.- Parameters:
key
- The keyvalue
- The value
-
addQuery
Add an element to thequery
array using raw String values, with a description property- Parameters:
key
- The keyvalue
- The valuedescription
- The description
-
addQuery
Populate the elements of thequery
array 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 theport
property- Returns:
- String The port
-
setPort
Set the value of theport
property- Parameters:
port
- The port as a string.
-