Class RestDataSource

    • Constructor Detail

      • RestDataSource

        public RestDataSource()
    • Method Detail

      • getInputStream

        public InputStream getInputStream()
                                   throws IOException
        Returns an InputStream that is able to read data from an HTTP URL that will be constructed with the settings defined on this data source.
        Specified by:
        getInputStream in interface InputDataSource
        Returns:
        an InputStream that is able to read from an HTTP URL
        Throws:
        IOException - when the HTTP connection could not be established or the InputStream could not be created
      • getOutputStream

        public OutputStream getOutputStream()
                                     throws IOException
        Returns an OutputStream that is able to write data to an HTTP URL that will be constructed with the settings defined on this data source.
        Specified by:
        getOutputStream in interface OutputDataSource
        Returns:
        an OutputStream that is able to write data to an HTTP URL
        Throws:
        IOException - when the HTTP connection could not be established or the OutputStream could not be created
      • getHost

        public String getHost()
        Returns the complete host address of the URL to use for the HTTP connection. The host consists of the scheme, the remote host name and the port. If no port is specified, the default scheme port will be used.
        Returns:
        the complete host address of the URL
      • setHost

        public void setHost​(String host)
        Sets the complete host address of the URL to use for the HTTP connection. The host consists of the scheme, the remote host name and the port. If no port is specified, the default scheme port will be used.
        Parameters:
        host - the complete host address of the URL
      • getPath

        public String getPath()
        Returns the entire path of the URL to use for the HTTP connection.
        Returns:
        the entire path of the URL
      • setPath

        public void setPath​(String path)
        Sets the entire path of the URL to use for the HTTP connection. A forward slash will automatically be added in front of the provided path if it is missing.
        Parameters:
        path - the entire path of the URL
      • setMethod

        public void setMethod​(String method)
        Sets the request method to use for the HTTP connection. When the request method is not specified, POST will be used if any form parameters or a data string is set. Otherwise, the GET method will be used.
        Parameters:
        method - the request method for the HTTP connection
        See Also:
        HttpURLConnection.setRequestMethod(String)
      • getReadTimeout

        public int getReadTimeout()
        Gets the read timeout for the HTTP connection, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
        Returns:
        an int that indicates the read timeout value in milliseconds
        See Also:
        URLConnection.getReadTimeout()
      • setReadTimeout

        public void setReadTimeout​(int readTimeout)
        Sets the read timeout for the HTTP connection, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
        Parameters:
        readTimeout - an int that specifies the timeout value to be used in milliseconds
        See Also:
        URLConnection.setReadTimeout(int)
      • getConnectTimeout

        public int getConnectTimeout()
        Gets the connect timeout for the HTTP connection, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
        Returns:
        an int that indicates the connect timeout value in milliseconds
        See Also:
        URLConnection.getConnectTimeout()
      • setConnectTimeout

        public void setConnectTimeout​(int connectTimeout)
        Sets the connect timeout for the HTTP connection, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
        Parameters:
        connectTimeout - an int that specifies the timeout value to be used in milliseconds
        See Also:
        URLConnection.setConnectTimeout(int)
      • getDataString

        public String getDataString()
        Gets the entity to use for the HTTP connection.
        Returns:
        the entity of the HTTP connection
      • setDataString

        public void setDataString​(String dataString)
        Sets the entity to use for the HTTP connection. The dataString will be written to the OutputStream of the HTTP connection. Please note, when specifying both a data string and form parameters, the data string will be appended with an ampersand, followed by the encoded list of form parameters.
        Parameters:
        dataString - the entity for the HTTP connection
      • getConsumerKey

        public String getConsumerKey()
        Gets the consumer key to use for creating the OAuth 1.0 signature that is sent along with the request, by setting the Authorization request header.
        Returns:
        the consumer key used for calculating the OAuth 1.0 signature
      • setConsumerKey

        public void setConsumerKey​(String consumerKey)
        Sets the consumer key to use for creating the OAuth 1.0 signature that is sent along with the request, by setting the Authorization request header. Setting the consumer secret is mandatory when setting the consumer key.
        Parameters:
        consumerKey - the consumer key used for calculating the OAuth 1.0 signature
      • getConsumerSecret

        public String getConsumerSecret()
        Gets the consumer secret to use for creating the OAuth 1.0 signature that is sent along with the request, by setting the Authorization request header.
        Returns:
        the consumer secret used for calculating the OAuth 1.0 signature
      • setConsumerSecret

        public void setConsumerSecret​(String consumerSecret)
        Sets the consumer secret to use for creating the OAuth 1.0 signature that is sent along with the request, by setting the Authorization request header. Setting the consumer secret has no effect when the consumer key is not set.
        Parameters:
        consumerSecret - the consumer secret used for calculating the OAuth 1.0 signature
      • addQueryParam

        public void addQueryParam​(String key,
                                  String value)
        Add a single query parameter to the request.
        Parameters:
        key - the key of the query parameter
        value - the value of the query parameter
      • getQueryParams

        public MultiValuedMap<String,​String> getQueryParams()
        Returns a list of query parameters that will be sent along with the request.
        Returns:
        the list of query parameters for the request
      • setQueryParams

        public void setQueryParams​(MultiValuedMap<String,​String> queryParams)
        Sets the list of query parameters to be sent along with the request. The list is a multi valued map, hence there can be more than one value assigned to the same query parameter key.
        Parameters:
        queryParams - the list of query parameters to be sent with the request
      • addFormParam

        public void addFormParam​(String key,
                                 String value)
        Add a single form parameter to the request.
        Parameters:
        key - the key of the form parameter
        value - the value of the form parameter
      • getFormParams

        public MultiValuedMap<String,​String> getFormParams()
        Returns a list of form parameters that will be sent along with the request.
        Returns:
        the list of form parameters for the request
      • setFormParams

        public void setFormParams​(MultiValuedMap<String,​String> formParams)
        Sets the list of form parameters to be sent along with the request. The list is a multi valued map, hence there can be more than one value assigned to the same form parameter key.
        Parameters:
        formParams - the list of form parameters to be sent with the request
      • getContentType

        public String getContentType()
        Gets the Content-Type request header that will be set on the HTTP connection.
        Returns:
        the Content-Type request header for the HTTP connection
      • setContentType

        public void setContentType​(String contentType)
        Sets the Content-Type request header for the HTTP connection. The request header will only be set when either a data string or form parameters were set. In case the content type header was not set, it will by default be set to application/x-www-form-urlencoded.
        Parameters:
        contentType - the Content-Type request header for the HTTP connection
      • addHeader

        public void addHeader​(String field,
                              String value)
        Adds a single HTTP header to the request. NOTE: Headers set using this method will be included in addition to those set via other methods (e.g. by setContentType(String)), so to avoid complications you should only set headers here if you haven't set them via any other methods
        Parameters:
        field - The name of the HTTP header field (e.g. "Accept")
        value - The header value to send with the request
      • setHeaders

        public void setHeaders​(MultiValuedMap<String,​String> headers)
        Sets the list of HTTP headers to be sent along with the request. The list is a multi valued map, hence there can be more than one header with the same field sent.
        Parameters:
        headers - the list of headers to be sent with the request
      • getMultipartStringFields

        public MultiValuedMap<String,​String> getMultipartStringFields()
        Returns a list of multipart form fields that will be sent along with the request as part of the multipart form data.
        Returns:
        the list of multipart form fields to be sent
      • setMultipartStringFields

        public void setMultipartStringFields​(MultiValuedMap<String,​String> multipartStringFields)
        Sets the list of multipart form fields that will be sent along with the request as part of the multipart form data.
        Parameters:
        multipartStringFields - the list of multipart form fields to be sent with the request
      • getMultipartByteFields

        public MultiValuedMap<String,​byte[]> getMultipartByteFields()
        Returns a list of multipart binary fields that will be sent along with the request as part of the multipart form data.
        Returns:
        the list of multipart binary fields to be sent
      • setMultipartByteFields

        public void setMultipartByteFields​(MultiValuedMap<String,​byte[]> multipartByteFields)
        Sets the list of multipart binary fields that will be sent along with the request as part of the multipart form data.
        Parameters:
        multipartByteFields - the list of multipart binary fields to be sent with the request
      • getResponseCode

        public int getResponseCode()
        Gets the status code from an HTTP response message.
        Returns:
        the HTTP Status-Code, or -1
        See Also:
        HttpURLConnection.getResponseCode()
      • getResponseMessage

        public String getResponseMessage()
        Gets the HTTP response message, if any, returned along with the response code from a server.
        Returns:
        the HTTP response message, or null
        See Also:
        HttpURLConnection.getResponseMessage()