Package org.scribe.model
Class Request
java.lang.Object
org.scribe.model.Request
- Direct Known Subclasses:
OAuthRequest
Represents an HTTP Request object
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBodyParameter(String key, String value) Add a body Parameter (for POST/ PUT Requests)voidAdd an HTTP Header to the RequestvoidaddPayload(byte[] payload) Overloaded version for byte arraysvoidaddPayload(String payload) Add body payload.voidaddQuerystringParameter(String key, String value) Add a QueryString parameterReturns the body of the requestObtains aParameterListof the body parameters.Returns the connection charset.Returns the complete url (host + resource + encoded querystring parameters).Returns the connection headers as aMapGet aParameterListwith the query string parameters.Returns the URL without the port and the query string part.getUrl()Obtains the URL of the HTTP Request.getVerb()Returns the HTTP Verbsend()send(RequestTuner tuner) Execute the request and return aResponsevoidsetCharset(String charsetName) Set the charset of the body of the requestvoidsetConnectionKeepAlive(boolean connectionKeepAlive) Sets whether the underlying Http Connection is persistent or not.voidsetConnectTimeout(int duration, TimeUnit unit) Sets the connect timeout for the underlyingHttpURLConnectionvoidsetFollowRedirects(boolean followRedirects) Sets whether the underlying Http Connection follows redirects or not.voidsetReadTimeout(int duration, TimeUnit unit) Sets the read timeout for the underlyingHttpURLConnectiontoString()
-
Field Details
-
DEFAULT_CONTENT_TYPE
- See Also:
-
-
Constructor Details
-
Request
Creates a new Http Request- Parameters:
verb- Http Verb (GET, POST, etc)url- url with optional querystring parameters.
-
-
Method Details
-
send
Execute the request and return aResponse- Returns:
- Http Response
- Throws:
RuntimeException- if the connection cannot be created.
-
send
-
getCompleteUrl
Returns the complete url (host + resource + encoded querystring parameters).- Returns:
- the complete url.
-
addHeader
Add an HTTP Header to the Request- Parameters:
key- the header namevalue- the header value
-
addBodyParameter
Add a body Parameter (for POST/ PUT Requests)- Parameters:
key- the parameter namevalue- the parameter value
-
addQuerystringParameter
Add a QueryString parameter- Parameters:
key- the parameter namevalue- the parameter value
-
addPayload
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
Get aParameterListwith the query string parameters.- Returns:
- a
ParameterListcontaining the query string parameters. - Throws:
OAuthException- if the request URL is not valid.
-
getBodyParams
Obtains aParameterListof the body parameters.- Returns:
- a
ParameterListcontaining the body parameters.
-
getUrl
Obtains the URL of the HTTP Request.- Returns:
- the original URL of the HTTP Request
-
getSanitizedUrl
Returns the URL without the port and the query string part.- Returns:
- the OAuth-sanitized URL
-
getBodyContents
Returns the body of the request- Returns:
- form encoded string
- Throws:
OAuthException- if the charset chosen is not supported
-
getVerb
Returns the HTTP Verb- Returns:
- the verb
-
getHeaders
Returns the connection headers as aMap- Returns:
- map of headers
-
getCharset
Returns the connection charset. Defaults toCharsetdefaultCharset if not set- Returns:
- charset
-
setConnectTimeout
Sets the connect timeout for the underlyingHttpURLConnection- Parameters:
duration- duration of the timeoutunit- unit of time (milliseconds, seconds, etc)
-
setReadTimeout
Sets the read timeout for the underlyingHttpURLConnection- Parameters:
duration- duration of the timeoutunit- unit of time (milliseconds, seconds, etc)
-
setCharset
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
-