Class GetAndCacheOauthToken

  • All Implemented Interfaces:
    AdaptrisComponent, ComponentLifecycle, ComponentLifecycleExtension, ConnectedService, MessageEventGenerator, Service, StateManagedComponent

    @ComponentProfile(summary="Get a cached OAUTH token or get a token and cache it",
                      since="3.10.1",
                      tag="service,http,https,oauth",
                      recommended=CacheConnection.class)
    public class GetAndCacheOauthToken
    extends OauthTokenGetter
    implements ConnectedService
    Variation of GetOauthToken that automatically caches the AccessToken in the cache of your choosing.

    If the 'key' exists in the cache, then that is retrieved, and used. If it does not, then the configured AccessTokenBuilder is used to generate the access token; which is cached against the specified key. If an expiry is available, then that's used to as the expiry for the token within the cache. Bear in mind that not all caches support a per-item-expiry; ExpiringMapCache does and by default a CacheConnection with this configured will be used.

    Note that previously you would have composed a chain of services to achieve the same thing (probably involving CheckCacheService or similar); this just simplifies that chain into a single step since you almost certainly want to cache the access token.

    In the adapter configuration file this class is aliased as get-and-cache-oauth-token which is the preferred alternative to the fully qualified classname when building your configuration.