com.sun.jersey.oauth.client
Class OAuthClientFilter

java.lang.Object
  extended by com.sun.jersey.api.client.filter.ClientFilter
      extended by com.sun.jersey.oauth.client.OAuthClientFilter
All Implemented Interfaces:
ClientHandler

public final class OAuthClientFilter
extends ClientFilter

Client filter adding OAuth authorization header to the HTTP request, if no authorization header is already present.

Note: This filter signs the request based on its request parameters. For this reason, you should invoke this filter after any others that modify any request parameters.

Example of usage:

 // baseline OAuth parameters for access to resource
 OAuthParameters params = new OAuthParameters().signatureMethod("HMAC-SHA1").
  consumerKey("key").setToken("accesskey")..version();

 // OAuth secrets to access resource
 OAuthSecrets secrets = new OAuthSecrets().consumerSecret("secret").setTokenSecret("accesssecret");

 // if parameters and secrets remain static, filter can be added to each web resource
 OAuthClientFilter filter = new OAuthClientFilter(client.getProviders(), params, secrets);

 // OAuth test server
 WebResource resource = client.resource("http://term.ie/oauth/example/request_token.php");

 resource.addFilter(filter);

 String response = resource.get(String.class);
 

Author:
Paul C. Bryan

Constructor Summary
OAuthClientFilter(Providers providers, OAuthParameters parameters, OAuthSecrets secrets)
          Constructs a new OAuth client filter with the specified providers.
 
Method Summary
 ClientResponse handle(ClientRequest request)
          Note: This method automatically sets the nonce and timestamp.
 
Methods inherited from class com.sun.jersey.api.client.filter.ClientFilter
getNext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OAuthClientFilter

public OAuthClientFilter(Providers providers,
                         OAuthParameters parameters,
                         OAuthSecrets secrets)
Constructs a new OAuth client filter with the specified providers.

Parameters:
providers - the registered providers from Client.getProviders() method.
parameters - the OAuth parameters to be used in signing requests.
secrets - the OAuth secrets to be used in signing requests.
Method Detail

handle

public ClientResponse handle(ClientRequest request)
                      throws ClientHandlerException
Note: This method automatically sets the nonce and timestamp.

Specified by:
handle in interface ClientHandler
Specified by:
handle in class ClientFilter
Parameters:
request - the HTTP request.
Returns:
the HTTP response.
Throws:
ClientHandlerException - if the client handler fails to process the request or response.


Copyright © 2013 Oracle Corporation. All Rights Reserved.