Package org.scribe.model
Class Request
- java.lang.Object
-
- org.scribe.model.Request
-
- Direct Known Subclasses:
OAuthRequest
public class Request extends java.lang.Object
Represents an HTTP Request object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_CONTENT_TYPE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBodyParameter(java.lang.String key, java.lang.String value)
Add a body Parameter (for POST/ PUT Requests)void
addHeader(java.lang.String key, java.lang.String value)
Add an HTTP Header to the Requestvoid
addPayload(byte[] payload)
Overloaded version for byte arraysvoid
addPayload(java.lang.String payload)
Add body payload.void
addQuerystringParameter(java.lang.String key, java.lang.String value)
Add a QueryString parameterjava.lang.String
getBodyContents()
Returns the body of the requestParameterList
getBodyParams()
Obtains aParameterList
of the body parameters.java.lang.String
getCharset()
Returns the connection charset.java.lang.String
getCompleteUrl()
Returns the complete url (host + resource + encoded querystring parameters).java.util.Map<java.lang.String,java.lang.String>
getHeaders()
Returns the connection headers as aMap
ParameterList
getQueryStringParams()
Get aParameterList
with the query string parameters.java.lang.String
getSanitizedUrl()
Returns the URL without the port and the query string part.java.lang.String
getUrl()
Obtains the URL of the HTTP Request.Verb
getVerb()
Returns the HTTP VerbResponse
send()
Response
send(RequestTuner tuner)
Execute the request and return aResponse
void
setCharset(java.lang.String charsetName)
Set the charset of the body of the requestvoid
setConnectionKeepAlive(boolean connectionKeepAlive)
Sets whether the underlying Http Connection is persistent or not.void
setConnectTimeout(int duration, java.util.concurrent.TimeUnit unit)
Sets the connect timeout for the underlyingHttpURLConnection
void
setFollowRedirects(boolean followRedirects)
Sets whether the underlying Http Connection follows redirects or not.void
setReadTimeout(int duration, java.util.concurrent.TimeUnit unit)
Sets the read timeout for the underlyingHttpURLConnection
java.lang.String
toString()
-
-
-
Field Detail
-
DEFAULT_CONTENT_TYPE
public static final java.lang.String DEFAULT_CONTENT_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Request
public Request(Verb verb, java.lang.String url)
Creates a new Http Request- Parameters:
verb
- Http Verb (GET, POST, etc)url
- url with optional querystring parameters.
-
-
Method Detail
-
send
public Response send(RequestTuner tuner)
Execute the request and return aResponse
- Returns:
- Http Response
- Throws:
java.lang.RuntimeException
- if the connection cannot be created.
-
send
public Response send()
-
getCompleteUrl
public java.lang.String getCompleteUrl()
Returns the complete url (host + resource + encoded querystring parameters).- Returns:
- the complete url.
-
addHeader
public void addHeader(java.lang.String key, java.lang.String value)
Add an HTTP Header to the Request- Parameters:
key
- the header namevalue
- the header value
-
addBodyParameter
public void addBodyParameter(java.lang.String key, java.lang.String value)
Add a body Parameter (for POST/ PUT Requests)- Parameters:
key
- the parameter namevalue
- the parameter value
-
addQuerystringParameter
public void addQuerystringParameter(java.lang.String key, java.lang.String value)
Add a QueryString parameter- Parameters:
key
- the parameter namevalue
- the parameter value
-
addPayload
public void addPayload(java.lang.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 aParameterList
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 aParameterList
of the body parameters.- Returns:
- a
ParameterList
containing the body parameters.
-
getUrl
public java.lang.String getUrl()
Obtains the URL of the HTTP Request.- Returns:
- the original URL of the HTTP Request
-
getSanitizedUrl
public java.lang.String getSanitizedUrl()
Returns the URL without the port and the query string part.- Returns:
- the OAuth-sanitized URL
-
getBodyContents
public java.lang.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 java.util.Map<java.lang.String,java.lang.String> getHeaders()
Returns the connection headers as aMap
- Returns:
- map of headers
-
getCharset
public java.lang.String getCharset()
Returns the connection charset. Defaults toCharset
defaultCharset if not set- Returns:
- charset
-
setConnectTimeout
public void setConnectTimeout(int duration, java.util.concurrent.TimeUnit unit)
Sets the connect timeout for the underlyingHttpURLConnection
- Parameters:
duration
- duration of the timeoutunit
- unit of time (milliseconds, seconds, etc)
-
setReadTimeout
public void setReadTimeout(int duration, java.util.concurrent.TimeUnit unit)
Sets the read timeout for the underlyingHttpURLConnection
- Parameters:
duration
- duration of the timeoutunit
- unit of time (milliseconds, seconds, etc)
-
setCharset
public void setCharset(java.lang.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 java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-