Package org.scribe.model
Class Request
- java.lang.Object
-
- org.scribe.model.Request
-
- Direct Known Subclasses:
OAuthRequest
public class Request extends java.lang.ObjectRepresents an HTTP Request object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_CONTENT_TYPE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBodyParameter(java.lang.String key, java.lang.String value)Add a body Parameter (for POST/ PUT Requests)voidaddHeader(java.lang.String key, java.lang.String value)Add an HTTP Header to the RequestvoidaddPayload(byte[] payload)Overloaded version for byte arraysvoidaddPayload(java.lang.String payload)Add body payload.voidaddQuerystringParameter(java.lang.String key, java.lang.String value)Add a QueryString parameterjava.lang.StringgetBodyContents()Returns the body of the requestParameterListgetBodyParams()Obtains aParameterListof the body parameters.java.lang.StringgetCharset()Returns the connection charset.java.lang.StringgetCompleteUrl()Returns the complete url (host + resource + encoded querystring parameters).java.util.Map<java.lang.String,java.lang.String>getHeaders()Returns the connection headers as aMapParameterListgetQueryStringParams()Get aParameterListwith the query string parameters.java.lang.StringgetSanitizedUrl()Returns the URL without the port and the query string part.java.lang.StringgetUrl()Obtains the URL of the HTTP Request.VerbgetVerb()Returns the HTTP VerbResponsesend()Responsesend(RequestTuner tuner)Execute the request and return aResponsevoidsetCharset(java.lang.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, java.util.concurrent.TimeUnit unit)Sets the connect timeout for the underlyingHttpURLConnectionvoidsetFollowRedirects(boolean followRedirects)Sets whether the underlying Http Connection follows redirects or not.voidsetReadTimeout(int duration, java.util.concurrent.TimeUnit unit)Sets the read timeout for the underlyingHttpURLConnectionjava.lang.StringtoString()
-
-
-
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 aParameterListwith the query string parameters.- Returns:
- a
ParameterListcontaining the query string parameters. - Throws:
OAuthException- if the request URL is not valid.
-
getBodyParams
public ParameterList getBodyParams()
Obtains aParameterListof the body parameters.- Returns:
- a
ParameterListcontaining 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 toCharsetdefaultCharset 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:
toStringin classjava.lang.Object
-
-