Class Url


public class Url extends CollectionElement
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 Details

  • Method Details

    • setRaw

      public void setRaw(String rawUrl) throws DuplicateVariableKeyException
      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 the key property
      value - Value for the value property
      description - Value for the description property
      Throws:
      DuplicateVariableKeyException
    • setPath

      public void setPath(String rawPath) throws DuplicateVariableKeyException
      Set the path element using a String. Elements of the path array are parsed out
      Parameters:
      rawPath - the raw path, e.g., /foo/:path1/bat
      Throws:
      DuplicateVariableKeyException
    • setQuery

      public void setQuery(String rawQuery)
      Set the elements of the query array with a string
      Parameters:
      rawQuery - String with the query component, e.g., "foo=bar&bat=big"
    • setHost

      public void setHost(String rawHost)
      Set the host component of the URL with a string. The elements of the host array are parsed out.
      Parameters:
      rawHost - The host as a string, e.g., foo.com
    • generateURL

      public String generateURL()
      Generate the raw URL from the component properties of this Url. If raw 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

      public void setProtocol(String rawProtocol)
      Set the value of the protocol 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

      public String getRaw()
      Returns the value of the raw 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 the raw property.
      Returns:
      String
    • getHosts

      public ArrayList<String> getHosts()
      Return the array of elements in the host array.
      Returns:
      ArrayList<String> Elements of the host property of this url.
    • getProtocol

      public String getProtocol()
      Returns:
      String
    • getUrl

      public String getUrl(boolean resolvePathVariables) throws VariableResolutionException
      Parameters:
      resolvePathVariables -
      Returns:
      String
      Throws:
      VariableResolutionException
    • setHosts

      public void setHosts(ArrayList<String> host)
      Set the value of the elements in the host array with a pre-populated ArrayList<String>
      Parameters:
      host - ArrayList<String> with host elements.
    • getPaths

      public ArrayList<String> getPaths()
      Returns the contents of the path element array
      Returns:
      ArrayList<String> containing the path elements
    • setPaths

      public void setPaths(ArrayList<String> path)
      Set the elements of the path element array
      Parameters:
      path - ArrayList<String> containing the path elements
    • getQueryElements

      public PropertyList<Property> getQueryElements()
      Return an ArrayList<Property> of key value pairs comprising the query array
      Returns:
      ArrayList<Property> containing the key value paris
    • getQueryElement

      public Property getQueryElement(String key)
      Parameters:
      key -
      Returns:
      Property
    • getQueryElement

      public Property getQueryElement(int index) throws IllegalPropertyAccessException
      Parameters:
      index -
      Returns:
      Property
      Throws:
      IllegalPropertyAccessException
    • setQueryELement

      public void setQueryELement(Property element, int index) throws IllegalPropertyAccessException
      Parameters:
      element -
      index -
      Throws:
      IllegalPropertyAccessException
    • getQueryString

      public String getQueryString()
      Get the raw query string for this URL.
      Returns:
    • removeQueryElement

      public void removeQueryElement(Property queryElement)
      Remove a query element key-value pair from the array of query elements, if it exists.
      Parameters:
      queryElement -
    • setQueries

      public void setQueries(PropertyList<Property> query)
      Set the contents of the query array with a pre-populated ArrayList<Property> containing the key value pairs
      Parameters:
      query -
    • getPathVariables

      public PropertyList<Property> getPathVariables()
      Get an ArrayList<Property> containing the key-value pairs comprising the variable array, or null if none exit.
      Returns:
      ArrayList<Property> The ArrayList containing the key-value pairs, or null if there are none.
    • getPathVariable

      public Property getPathVariable(String key)
      Parameters:
      key -
      Returns:
      Property
    • setPathVariables

      public void setPathVariables(PropertyList<Property> variable)
      Set the values of the variable array with a pre-populated ArrayList<Property> containing the key-value paris
      Parameters:
      variable - the ArrayList<Property> containing the key-value paris
    • setPathVariable

      public void setPathVariable(Property varPath)
      Parameters:
      varPath -
    • addPathVariable

      public void addPathVariable(Property varPath) throws DuplicateVariableKeyException
      Parameters:
      varPath -
      Throws:
      DuplicateVariableKeyException
    • removePathVariable

      public void removePathVariable(String key)
      Parameters:
      key -
    • getKey

      public String getKey()
      Currently unimplemented
      Specified by:
      getKey in class CollectionElement
      Returns:
      String
    • addQuery

      public void addQuery(String key, String value)
      Add an element to the query array using raw string values.
      Parameters:
      key - The key
      value - The value
    • addQuery

      public void addQuery(String key, String value, String description)
      Add an element to the query array using raw String values, with a description property
      Parameters:
      key - The key
      value - The value
      description - The description
    • addQuery

      public void addQuery(String queryString)
      Populate the elements of the query array with an http query string. Replaces any existing query string.
      Parameters:
      queryString - The query string, e.g., foo=bar&bat=bing
    • getPort

      public String getPort()
      Get the value of the port property
      Returns:
      String The port
    • setPort

      public void setPort(String port)
      Set the value of the port property
      Parameters:
      port - The port as a string.