|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.oauth.client.OAuthClient
public class OAuthClient
Methods for an OAuth consumer to request tokens from a service provider.
This class can also be used to request access to protected resources, in some cases. But not in all cases. For example, this class can't handle arbitrary HTTP headers.
Methods of this class return a response as an OAuthMessage, from which you can get a body or parameters but not both. Calling a getParameter method will read and close the body (like readBodyAsString), so you can't read it later. If you read or close the body first, then getParameter can't read it. The response headers should tell you whether the response contains encoded parameters, that is whether you should call getParameter or not.
Methods of this class don't follow redirects. When they receive a redirect response, they throw an OAuthProblemException, with properties HttpResponseMessage.STATUS_CODE = the redirect code HttpResponseMessage.LOCATION = the redirect URL. Such a redirect can't be handled at the HTTP level, if the second request must carry another OAuth signature (with different parameters). For example, Google's Service Provider routinely redirects requests for access to protected resources, and requires the redirected request to be signed.
Nested Class Summary | |
---|---|
static class |
OAuthClient.ParameterStyle
Deprecated. use net.oauth.ParameterStyle. |
Field Summary | |
---|---|
static java.lang.String |
ACCEPT_ENCODING
Deprecated. use OAuthConsumer.ACCEPT_ENCODING instead |
protected static java.lang.String |
CONTENT_LENGTH
|
protected static java.lang.String |
DELETE
|
protected java.util.Map<java.lang.String,java.lang.Object> |
httpParameters
|
static java.lang.String |
PARAMETER_STYLE
The name of the OAuthConsumer property whose value is the ParameterStyle to be used by invoke. |
protected static java.lang.String |
POST
|
protected static java.lang.String |
PUT
|
Constructor Summary | |
---|---|
OAuthClient(HttpClient http)
|
Method Summary | |
---|---|
OAuthResponseMessage |
access(OAuthMessage request,
OAuthClient.ParameterStyle style)
Deprecated. |
OAuthResponseMessage |
access(OAuthMessage request,
ParameterStyle style)
Send a request and return the response. |
OAuthMessage |
getAccessToken(OAuthAccessor accessor,
java.lang.String httpMethod,
java.util.Collection<? extends java.util.Map.Entry> parameters)
Get an access token from the service provider, in exchange for an authorized request token. |
HttpClient |
getHttpClient()
|
java.util.Map<java.lang.String,java.lang.Object> |
getHttpParameters()
HTTP client parameters, as a map from parameter name to value. |
void |
getRequestToken(OAuthAccessor accessor)
Get a fresh request token from the service provider. |
void |
getRequestToken(OAuthAccessor accessor,
java.lang.String httpMethod)
Get a fresh request token from the service provider. |
void |
getRequestToken(OAuthAccessor accessor,
java.lang.String httpMethod,
java.util.Collection<? extends java.util.Map.Entry> parameters)
Get a fresh request token from the service provider. |
OAuthMessage |
getRequestTokenResponse(OAuthAccessor accessor,
java.lang.String httpMethod,
java.util.Collection<? extends java.util.Map.Entry> parameters)
Get a fresh request token from the service provider. |
OAuthMessage |
invoke(OAuthAccessor accessor,
java.lang.String url,
java.util.Collection<? extends java.util.Map.Entry> parameters)
Construct a request message, send it to the service provider and get the response. |
OAuthMessage |
invoke(OAuthAccessor accessor,
java.lang.String httpMethod,
java.lang.String url,
java.util.Collection<? extends java.util.Map.Entry> parameters)
Construct a request message, send it to the service provider and get the response. |
OAuthMessage |
invoke(OAuthMessage request,
OAuthClient.ParameterStyle style)
Deprecated. |
OAuthMessage |
invoke(OAuthMessage request,
ParameterStyle style)
Send a request message to the service provider and get the response. |
void |
setHttpClient(HttpClient http)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final java.util.Map<java.lang.String,java.lang.Object> httpParameters
public static final java.lang.String PARAMETER_STYLE
@Deprecated public static final java.lang.String ACCEPT_ENCODING
OAuthConsumer.ACCEPT_ENCODING
instead
protected static final java.lang.String PUT
protected static final java.lang.String POST
protected static final java.lang.String DELETE
protected static final java.lang.String CONTENT_LENGTH
Constructor Detail |
---|
public OAuthClient(HttpClient http)
Method Detail |
---|
public void setHttpClient(HttpClient http)
public HttpClient getHttpClient()
public java.util.Map<java.lang.String,java.lang.Object> getHttpParameters()
for parameter names.
public void getRequestToken(OAuthAccessor accessor) throws java.io.IOException, OAuthException, java.net.URISyntaxException
accessor
- should contain a consumer that contains a non-null consumerKey
and consumerSecret. Also,
accessor.consumer.serviceProvider.requestTokenURL should be
the URL (determined by the service provider) for getting a
request token.
OAuthProblemException
- the HTTP response status code was not 200 (OK)
java.io.IOException
OAuthException
java.net.URISyntaxException
public void getRequestToken(OAuthAccessor accessor, java.lang.String httpMethod) throws java.io.IOException, OAuthException, java.net.URISyntaxException
accessor
- should contain a consumer that contains a non-null consumerKey
and consumerSecret. Also,
accessor.consumer.serviceProvider.requestTokenURL should be
the URL (determined by the service provider) for getting a
request token.httpMethod
- typically OAuthMessage.POST or OAuthMessage.GET, or null to
use the default method.
OAuthProblemException
- the HTTP response status code was not 200 (OK)
java.io.IOException
OAuthException
java.net.URISyntaxException
public void getRequestToken(OAuthAccessor accessor, java.lang.String httpMethod, java.util.Collection<? extends java.util.Map.Entry> parameters) throws java.io.IOException, OAuthException, java.net.URISyntaxException
accessor
- should contain a consumer that contains a non-null consumerKey
and consumerSecret. Also,
accessor.consumer.serviceProvider.requestTokenURL should be
the URL (determined by the service provider) for getting a
request token.httpMethod
- typically OAuthMessage.POST or OAuthMessage.GET, or null to
use the default method.parameters
- additional parameters for this request, or null to indicate
that there are no additional parameters.
OAuthProblemException
- the HTTP response status code was not 200 (OK)
java.io.IOException
OAuthException
java.net.URISyntaxException
public OAuthMessage getRequestTokenResponse(OAuthAccessor accessor, java.lang.String httpMethod, java.util.Collection<? extends java.util.Map.Entry> parameters) throws java.io.IOException, OAuthException, java.net.URISyntaxException
accessor
- should contain a consumer that contains a non-null consumerKey
and consumerSecret. Also,
accessor.consumer.serviceProvider.requestTokenURL should be
the URL (determined by the service provider) for getting a
request token.httpMethod
- typically OAuthMessage.POST or OAuthMessage.GET, or null to
use the default method.parameters
- additional parameters for this request, or null to indicate
that there are no additional parameters.
OAuthProblemException
- the HTTP response status code was not 200 (OK)
java.io.IOException
OAuthException
java.net.URISyntaxException
public OAuthMessage getAccessToken(OAuthAccessor accessor, java.lang.String httpMethod, java.util.Collection<? extends java.util.Map.Entry> parameters) throws java.io.IOException, OAuthException, java.net.URISyntaxException
accessor
- should contain a non-null requestToken and tokenSecret, and a
consumer that contains a consumerKey and consumerSecret. Also,
accessor.consumer.serviceProvider.accessTokenURL should be the
URL (determined by the service provider) for getting an access
token.httpMethod
- typically OAuthMessage.POST or OAuthMessage.GET, or null to
use the default method.parameters
- additional parameters for this request, or null to indicate
that there are no additional parameters.
OAuthProblemException
- the HTTP response status code was not 200 (OK)
java.io.IOException
OAuthException
java.net.URISyntaxException
public OAuthMessage invoke(OAuthAccessor accessor, java.lang.String httpMethod, java.lang.String url, java.util.Collection<? extends java.util.Map.Entry> parameters) throws java.io.IOException, OAuthException, java.net.URISyntaxException
httpMethod
- the HTTP request method, or null to use the default method
java.net.URISyntaxException
- the given url isn't valid syntactically
OAuthProblemException
- the HTTP response status code was not 200 (OK)
java.io.IOException
OAuthException
public OAuthMessage invoke(OAuthAccessor accessor, java.lang.String url, java.util.Collection<? extends java.util.Map.Entry> parameters) throws java.io.IOException, OAuthException, java.net.URISyntaxException
java.net.URISyntaxException
- the given url isn't valid syntactically
OAuthProblemException
- the HTTP response status code was not 200 (OK)
java.io.IOException
OAuthException
public OAuthMessage invoke(OAuthMessage request, ParameterStyle style) throws java.io.IOException, OAuthException
java.io.IOException
- failed to communicate with the service provider
OAuthProblemException
- the HTTP response status code was not 200 (OK)
OAuthException
public OAuthResponseMessage access(OAuthMessage request, ParameterStyle style) throws java.io.IOException
java.io.IOException
public OAuthMessage invoke(OAuthMessage request, OAuthClient.ParameterStyle style) throws java.io.IOException, OAuthException
java.io.IOException
OAuthException
public OAuthResponseMessage access(OAuthMessage request, OAuthClient.ParameterStyle style) throws java.io.IOException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |