Spring Social

org.springframework.social.oauth2
Class AbstractOAuth2ApiBinding

java.lang.Object
  extended by org.springframework.social.oauth2.AbstractOAuth2ApiBinding
All Implemented Interfaces:
ApiBinding

public abstract class AbstractOAuth2ApiBinding
extends java.lang.Object
implements ApiBinding

Base class for OAuth 2-based provider API bindings.

Author:
Craig Walls

Constructor Summary
protected AbstractOAuth2ApiBinding()
          Constructs the API template without user authorization.
protected AbstractOAuth2ApiBinding(java.lang.String accessToken)
          Constructs the API template with OAuth credentials necessary to perform operations on behalf of a user.
 
Method Summary
protected  void configureRestTemplate(org.springframework.web.client.RestTemplate restTemplate)
          Subclassing hook to enable customization of the RestTemplate used to consume provider API resources.
protected  org.springframework.http.converter.ByteArrayHttpMessageConverter getByteArrayMessageConverter()
          Returns a ByteArrayHttpMessageConverter to be used by the internal RestTemplate when consuming image or other binary resources.
protected  org.springframework.http.converter.FormHttpMessageConverter getFormMessageConverter()
          Returns an FormHttpMessageConverter to be used by the internal RestTemplate.
protected  org.springframework.http.converter.json.MappingJacksonHttpMessageConverter getJsonMessageConverter()
          Returns a MappingJacksonHttpMessageConverter to be used by the internal RestTemplate.
protected  java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> getMessageConverters()
          Returns a list of HttpMessageConverters to be used by the internal RestTemplate.
protected  OAuth2Version getOAuth2Version()
          Returns the version of OAuth2 the API implements.
 org.springframework.web.client.RestTemplate getRestTemplate()
          Obtains a reference to the REST client backing this API binding and used to perform API calls.
 boolean isAuthorized()
          Returns true if this API binding has been authorized on behalf of a specific user.
 void setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
          Set the ClientHttpRequestFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractOAuth2ApiBinding

protected AbstractOAuth2ApiBinding()
Constructs the API template without user authorization. This is useful for accessing operations on a provider's API that do not require user authorization.


AbstractOAuth2ApiBinding

protected AbstractOAuth2ApiBinding(java.lang.String accessToken)
Constructs the API template with OAuth credentials necessary to perform operations on behalf of a user.

Parameters:
accessToken - the access token
Method Detail

setRequestFactory

public void setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
Set the ClientHttpRequestFactory. This is useful when custom configuration of the request factory is required, such as configuring custom SSL details.

Parameters:
requestFactory - the request factory

isAuthorized

public boolean isAuthorized()
Description copied from interface: ApiBinding
Returns true if this API binding has been authorized on behalf of a specific user. If so, calls to the API are signed with the user's authorization credentials, indicating an application is invoking the API on a user's behalf. If not, API calls do not contain any user authorization information. Callers can use this status flag to determine if API operations requiring authorization can be invoked.

Specified by:
isAuthorized in interface ApiBinding
See Also:
MissingAuthorizationException

getRestTemplate

public org.springframework.web.client.RestTemplate getRestTemplate()
Obtains a reference to the REST client backing this API binding and used to perform API calls. Callers may use the RestTemplate to invoke other API operations not yet modeled by the binding interface. Callers may also modify the configuration of the RestTemplate to support unit testing the API binding with a mock server in a test environment. During construction, subclasses may apply customizations to the RestTemplate needed to invoke a specific API.

See Also:
RestTemplate.setMessageConverters(java.util.List), RestTemplate.setErrorHandler(org.springframework.web.client.ResponseErrorHandler)

getOAuth2Version

protected OAuth2Version getOAuth2Version()
Returns the version of OAuth2 the API implements. By default, returns OAuth2Version.BEARER indicating versions of OAuth2 that apply the bearer token scheme. Subclasses may override to return another version.

See Also:
OAuth2Version

configureRestTemplate

protected void configureRestTemplate(org.springframework.web.client.RestTemplate restTemplate)
Subclassing hook to enable customization of the RestTemplate used to consume provider API resources. An example use case might be to configure a custom error handler. Note that this method is called after the RestTemplate has been configured with the message converters returned from getMessageConverters().

Parameters:
restTemplate - the RestTemplate to configure.

getMessageConverters

protected java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> getMessageConverters()
Returns a list of HttpMessageConverters to be used by the internal RestTemplate. By default, this includes a StringHttpMessageConverter, a MappingJacksonHttpMessageConverter, a ByteArrayHttpMessageConverter, and a FormHttpMessageConverter. The FormHttpMessageConverter is set to use "UTF-8" character encoding. Override this method to add additional message converters or to replace the default list of message converters.


getFormMessageConverter

protected org.springframework.http.converter.FormHttpMessageConverter getFormMessageConverter()
Returns an FormHttpMessageConverter to be used by the internal RestTemplate. By default, the message converter is set to use "UTF-8" character encoding. Override to customize the message converter (for example, to set supported media types or message converters for the parts of a multipart message). To remove/replace this or any of the other message converters that are registered by default, override the getMessageConverters() method instead.


getJsonMessageConverter

protected org.springframework.http.converter.json.MappingJacksonHttpMessageConverter getJsonMessageConverter()
Returns a MappingJacksonHttpMessageConverter to be used by the internal RestTemplate. Override to customize the message converter (for example, to set a custom object mapper or supported media types). To remove/replace this or any of the other message converters that are registered by default, override the getMessageConverters() method instead.


getByteArrayMessageConverter

protected org.springframework.http.converter.ByteArrayHttpMessageConverter getByteArrayMessageConverter()
Returns a ByteArrayHttpMessageConverter to be used by the internal RestTemplate when consuming image or other binary resources. By default, the message converter supports "image/jpeg", "image/gif", and "image/png" media types. Override to customize the message converter (for example, to set supported media types). To remove/replace this or any of the other message converters that are registered by default, override the getMessageConverters() method instead.


Spring Social