Class Request

java.lang.Object
org.scribe.model.Request
Direct Known Subclasses:
OAuthRequest

public class Request extends Object
Represents an HTTP Request object
  • Field Details

  • Constructor Details

    • Request

      public Request(Verb verb, String url)
      Creates a new Http Request
      Parameters:
      verb - Http Verb (GET, POST, etc)
      url - url with optional querystring parameters.
  • Method Details

    • send

      public Response send(RequestTuner tuner)
      Execute the request and return a Response
      Returns:
      Http Response
      Throws:
      RuntimeException - if the connection cannot be created.
    • send

      public Response send()
    • getCompleteUrl

      public String getCompleteUrl()
      Returns the complete url (host + resource + encoded querystring parameters).
      Returns:
      the complete url.
    • addHeader

      public void addHeader(String key, String value)
      Add an HTTP Header to the Request
      Parameters:
      key - the header name
      value - the header value
    • addBodyParameter

      public void addBodyParameter(String key, String value)
      Add a body Parameter (for POST/ PUT Requests)
      Parameters:
      key - the parameter name
      value - the parameter value
    • addQuerystringParameter

      public void addQuerystringParameter(String key, String value)
      Add a QueryString parameter
      Parameters:
      key - the parameter name
      value - the parameter value
    • addPayload

      public void addPayload(String payload)
      Add body payload. This method is used when the HTTP body is not a form-url-encoded string, but another thing. Like for example XML. Note: The contents are not part of the OAuth signature
      Parameters:
      payload - the body of the request
    • addPayload

      public void addPayload(byte[] payload)
      Overloaded version for byte arrays
      Parameters:
      payload -
    • getQueryStringParams

      public ParameterList getQueryStringParams()
      Get a ParameterList with the query string parameters.
      Returns:
      a ParameterList containing the query string parameters.
      Throws:
      OAuthException - if the request URL is not valid.
    • getBodyParams

      public ParameterList getBodyParams()
      Obtains a ParameterList of the body parameters.
      Returns:
      a ParameterListcontaining the body parameters.
    • getUrl

      public String getUrl()
      Obtains the URL of the HTTP Request.
      Returns:
      the original URL of the HTTP Request
    • getSanitizedUrl

      public String getSanitizedUrl()
      Returns the URL without the port and the query string part.
      Returns:
      the OAuth-sanitized URL
    • getBodyContents

      public String getBodyContents()
      Returns the body of the request
      Returns:
      form encoded string
      Throws:
      OAuthException - if the charset chosen is not supported
    • getVerb

      public Verb getVerb()
      Returns the HTTP Verb
      Returns:
      the verb
    • getHeaders

      public Map<String,String> getHeaders()
      Returns the connection headers as a Map
      Returns:
      map of headers
    • getCharset

      public String getCharset()
      Returns the connection charset. Defaults to Charset defaultCharset if not set
      Returns:
      charset
    • setConnectTimeout

      public void setConnectTimeout(int duration, TimeUnit unit)
      Sets the connect timeout for the underlying HttpURLConnection
      Parameters:
      duration - duration of the timeout
      unit - unit of time (milliseconds, seconds, etc)
    • setReadTimeout

      public void setReadTimeout(int duration, TimeUnit unit)
      Sets the read timeout for the underlying HttpURLConnection
      Parameters:
      duration - duration of the timeout
      unit - unit of time (milliseconds, seconds, etc)
    • setCharset

      public void setCharset(String charsetName)
      Set the charset of the body of the request
      Parameters:
      charsetName - name of the charset of the request
    • setConnectionKeepAlive

      public void setConnectionKeepAlive(boolean connectionKeepAlive)
      Sets whether the underlying Http Connection is persistent or not.
      Parameters:
      connectionKeepAlive -
    • setFollowRedirects

      public void setFollowRedirects(boolean followRedirects)
      Sets whether the underlying Http Connection follows redirects or not. Defaults to true (follow redirects)
      Parameters:
      followRedirects -
    • toString

      public String toString()
      Overrides:
      toString in class Object