oauthP5.oauth
Class OAuthRequest

java.lang.Object
  extended by oauthP5.oauth.OAuthRequest

public class OAuthRequest
extends Object

The representation of an OAuth HttpRequest. Adds OAuth-related functionality to the Request

Author:
Pablo Fernandez

Field Summary
static String DEFAULT_CONTENT_TYPE
           
 
Constructor Summary
OAuthRequest(Verb verb, String url)
          Default constructor.
 
Method Summary
 void addBodyParameter(String key, String value)
          Add a body Parameter (for POST/ PUT Requests)
 void addHeader(String key, String value)
          Add an HTTP Header to the Request
 void addOAuthParameter(String key, String value)
          Adds an OAuth parameter.
 void addPayload(byte[] payload)
          Overloaded version for byte arrays
 void addPayload(String payload)
          Add body payload.
 void addQuerystringParameter(String key, String value)
          Add a QueryString parameter
 String getBodyContents()
          Returns the body of the request
 ParameterList getBodyParams()
          Obtains a ParameterList of the body parameters.
 String getCharset()
          Returns the connection charset.
 String getCompleteUrl()
          Returns the complete url (host + resource + encoded querystring parameters).
 Map<String,String> getHeaders()
          Returns the connection headers as a Map
 Map<String,String> getOauthParameters()
          Returns the Map containing the key-value pair of parameters.
 ParameterList getQueryStringParams()
          Get a ParameterList with the query string parameters.
 String getSanitizedUrl()
          Returns the URL without the port and the query string part.
 String getUrl()
          Obtains the URL of the HTTP Request.
 Verb getVerb()
          Returns the HTTP Verb
 Response send()
          Execute the request and return a Response
 void setCharset(String charsetName)
          Set the charset of the body of the request
 void setConnectionKeepAlive(boolean connectionKeepAlive)
          Sets whether the underlying Http Connection is persistent or not.
 void setConnectTimeout(int duration, TimeUnit unit)
          Sets the connect timeout for the underlying HttpURLConnection
 void setReadTimeout(int duration, TimeUnit unit)
          Sets the read timeout for the underlying HttpURLConnection
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CONTENT_TYPE

public static final String DEFAULT_CONTENT_TYPE
See Also:
Constant Field Values
Constructor Detail

OAuthRequest

public OAuthRequest(Verb verb,
                    String url)
Default constructor.

Parameters:
verb - Http verb/method
url - resource URL
Method Detail

addOAuthParameter

public void addOAuthParameter(String key,
                              String value)
Adds an OAuth parameter.

Parameters:
key - name of the parameter
value - value of the parameter
Throws:
IllegalArgumentException - if the parameter is not an OAuth parameter

getOauthParameters

public Map<String,String> getOauthParameters()
Returns the Map containing the key-value pair of parameters.

Returns:
parameters as map

toString

public String toString()

send

public Response send()
Execute the request and return a Response

Returns:
Http Response
Throws:
RuntimeException - if the connection cannot be created.

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 -
See Also:
http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html


Processing library oauthP5 by New York Times R&D Lab. (c) 2012