@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
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.
log
Constructor and Description |
---|
GetAndCacheOauthToken() |
Modifier and Type | Method and Description |
---|---|
protected void |
closeService() |
void |
doService(AdaptrisMessage msg)
Apply the service to the message.
|
java.lang.String |
getCacheKey() |
AdaptrisConnection |
getConnection()
Returns the
AdaptrisConnection to use. |
protected void |
initService() |
void |
prepare()
Prepare for initialisation.
|
void |
setCacheKey(java.lang.String cacheKey)
Set the key to the cache.
|
void |
setConnection(AdaptrisConnection c)
The connection to the cache where tokens will be stored.
|
void |
start()
Starts the component.
|
void |
stop()
Stop the component
|
GetAndCacheOauthToken |
withCacheKey(java.lang.String s) |
GetAndCacheOauthToken |
withConnection(AdaptrisConnection c) |
getAccessTokenBuilder, getAccessTokenWriter, setAccessTokenBuilder, setAccessTokenWriter, tokenWriterIfNull, tokenWriterToUse, withAccessTokenBuilder, withAccessTokenWriter
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
continueOnFailure, isBranching, setUniqueId
createName, createQualifier, isTrackingEndpoint
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
getUniqueId
close, init
public void prepare() throws CoreException
ComponentLifecycleExtension
prepare
in interface ComponentLifecycleExtension
prepare
in class OauthTokenGetter
CoreException
protected void initService() throws CoreException
initService
in class OauthTokenGetter
CoreException
public void start() throws CoreException
ComponentLifecycle
Once a component is started it should be ready to process messages. In the case of AdaptrisMessageConsumer
, calling start
will begin message delivery.
start
in interface ComponentLifecycle
start
in class OauthTokenGetter
CoreException
- wrapping any underlying Exception
spublic void stop()
ComponentLifecycle
A stopped component is not expected to be ready to process messages. In the case of AdaptrisMessageConsumer
, calling stop
will pause message delivery. Throwing a RuntimeException
may cause unintended consequences
stop
in interface ComponentLifecycle
stop
in class OauthTokenGetter
protected void closeService()
closeService
in class OauthTokenGetter
public void doService(AdaptrisMessage msg) throws ServiceException
Service
Apply the service to the message.
doService
in interface Service
msg
- the AdaptrisMessage
to processServiceException
- wrapping any underlying Exception
spublic void setConnection(AdaptrisConnection c)
If not expilicitly configured, will be defaulted to ExpiringMapCache
; 1 Hour + ExpirationPolicy.ACCESSED.
setConnection
in interface ConnectedService
c
- the AdaptrisConnection
to usepublic AdaptrisConnection getConnection()
ConnectedService
AdaptrisConnection
to use.getConnection
in interface ConnectedService
AdaptrisConnection
public GetAndCacheOauthToken withConnection(AdaptrisConnection c)
public java.lang.String getCacheKey()
public void setCacheKey(java.lang.String cacheKey)
cacheKey
- the key to the cache.public GetAndCacheOauthToken withCacheKey(java.lang.String s)