Interface Request<T extends Request<?,?>,RESP extends Response>

Type Parameters:
T - the type of request used for method chaining

public interface Request<T extends Request<?,?>,RESP extends Response>
Interface Request represents a request to retrieve data. To execute a request call execute(ResponseHandler).
Since:
2.0
  • Method Details

    • setConnectionTimeout

      T setConnectionTimeout(int connectionTimeout)
      Setting connection timeout in milliseconds.
      Parameters:
      connectionTimeout - The timeout in milliseconds
      Returns:
      a reference to this object.
    • setSoTimeout

      T setSoTimeout(int soTimeout)
      Setting socket timeout in milliseconds.
      Parameters:
      soTimeout - the timeout in milliseconds
      Returns:
      a reference to this object.
    • setUrl

      T setUrl(String url)
      Parameters:
      url - the url to request
      Returns:
      a reference to this object.
    • setRequestBody

      T setRequestBody(String requestBody)
      Sets the body of the request. In default implementation only requests of type Request.MethodType.POST and Request.MethodType.PUT can have a request body.
      Parameters:
      requestBody - the body of the request
      Returns:
      a reference to this object.
    • setRequestBody

      T setRequestBody(String requestBody, String contentType)
      Sets the body of the request. In default implementation only requests of type Request.MethodType.POST and Request.MethodType.PUT can have a request body.
      Parameters:
      requestBody - the body of the request
      contentType - the contentType of the request
      Returns:
      a reference to this object.
    • setFiles

      T setFiles(List<RequestFilePart> files)
      Sets file parts of the request. File parts can only be added if the request body is empty. Only requests of type Request.MethodType.POST and Request.MethodType.PUT can have file parts.
      Parameters:
      files - the file parts, cannot be null.
      Returns:
      a reference to this object.
      Throws:
      IllegalArgumentException - if the method of this request is not a POST or PUT or files is NULL.
      IllegalStateException - if the request body for this request has already been set.
      Since:
      2.6
    • setEntity

      T setEntity(Object entity)
      Set an entity as the request body
      Parameters:
      entity - the request entity to be marshalled, not null
      Returns:
      this Request object
    • addRequestParameters

      T addRequestParameters(String... params)
      Sets parameters of the request. In default implementation only requests of type Request.MethodType.POST can have parameters. For other requests include parameters in url. This method accepts an even number of arguments, in form of name, value, name, value, name, value, etc
      Parameters:
      params - parameters of the request in as name, value pairs
      Returns:
      a reference to this object.
    • addBasicAuthentication

      T addBasicAuthentication(String hostname, String username, String password)
      Adds basic authentication to the request.
      Parameters:
      username - The user name
      password - The password
      Returns:
      a reference to this object.
    • addHeader

      T addHeader(String headerName, String headerValue)
      Adds the specified header to the request, not overwriting any previous value. Support for this operation is optional.
      Parameters:
      headerName - the header's name
      headerValue - the header's value
      Returns:
      a reference to this object
      See Also:
    • setHeader

      T setHeader(String headerName, String headerValue)
      Sets the specified header to the request, overwriting any previous value. Support for this operation is optional.
      Parameters:
      headerName - the header's name
      headerValue - the header's value
      Returns:
      a reference to this object
      See Also:
    • setFollowRedirects

      T setFollowRedirects(boolean follow)
      Sets whether the request should transparently follow a redirect from the server. The default behavior is that when a response is received with a status code in the 300s, a new request is made using the location header of the response without notifying the client. Set this to false to turn this behavior off.
      Parameters:
      follow - set this to false to have the request not transparently follow redirects.
      Returns:
      a reference to this object.
    • getHeaders

      Map<String,List<String>> getHeaders()
      Returns:
      an immutable Map of headers added to the request so far
      Since:
      2.1
    • execute

      void execute(ResponseHandler<? super RESP> responseHandler) throws ResponseException
      Executes the request.
      Parameters:
      responseHandler - Callback handler of the response.
      Throws:
      ResponseProtocolException - If the server returned a malformed response
      ResponseTimeoutException - If a connection timeout or read timeout occurred
      ResponseTransportException - If an I/O error occurred in request transport
      ResponseException - For all errors not otherwise specified
    • execute

      String execute() throws ResponseException
      Executes a request and if response is successful, returns response as a string. @see Response.getResponseBodyAsString()
      Returns:
      response as String
      Throws:
      ResponseStatusException - If the server returned a response that contained an error code
      ResponseProtocolException - If the server returned a malformed response
      ResponseTimeoutException - If a connection timeout or read timeout occurred
      ResponseTransportException - If an I/O error occurred in request transport
      ResponseException - For all errors not otherwise specified
    • executeAndReturn

      <RET> RET executeAndReturn(ReturningResponseHandler<? super RESP,RET> responseHandler) throws ResponseException
      Executes the request and returns a result value.
      Parameters:
      responseHandler - Callback handler of the response.
      Throws:
      ResponseProtocolException - If the server returned a malformed response
      ResponseTimeoutException - If a connection timeout or read timeout occurred
      ResponseTransportException - If an I/O error occurred in request transport
      ResponseException - For all errors not otherwise specified
      Since:
      v2.2.0