Class GetAndCacheOauthToken
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,ConnectedService
,MessageEventGenerator
,Service
,StateManagedComponent
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.
-
Field Summary
Fields inherited from class com.adaptris.core.ServiceImp
log
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
void
doService
(AdaptrisMessage msg) Apply the service to the message.Returns theAdaptrisConnection
to use.protected void
void
prepare()
Prepare for initialisation.void
setCacheKey
(String cacheKey) Set the key to the cache.void
The connection to the cache where tokens will be stored.void
start()
Starts the component.void
stop()
Stop the componentMethods inherited from class com.adaptris.core.http.oauth.OauthTokenGetter
getAccessTokenBuilder, getAccessTokenWriter, setAccessTokenBuilder, setAccessTokenWriter, tokenWriterIfNull, tokenWriterToUse, withAccessTokenBuilder, withAccessTokenWriter
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.adaptris.core.AdaptrisComponent
getUniqueId
Methods inherited from interface com.adaptris.core.ComponentLifecycle
close, init
Methods inherited from interface com.adaptris.core.MessageEventGenerator
createName, createQualifier, isTrackingEndpoint
Methods inherited from interface com.adaptris.core.Service
continueOnFailure, isBranching, setUniqueId
Methods inherited from interface com.adaptris.core.StateManagedComponent
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
-
Constructor Details
-
GetAndCacheOauthToken
public GetAndCacheOauthToken()
-
-
Method Details
-
prepare
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Specified by:
prepare
in interfaceComponentLifecycleExtension
- Overrides:
prepare
in classOauthTokenGetter
- Throws:
CoreException
-
initService
- Overrides:
initService
in classOauthTokenGetter
- Throws:
CoreException
-
start
Description copied from interface:ComponentLifecycle
Starts the component.Once a component is started it should be ready to process messages. In the case of
AdaptrisMessageConsumer
, calling start will begin message delivery.- Specified by:
start
in interfaceComponentLifecycle
- Overrides:
start
in classOauthTokenGetter
- Throws:
CoreException
- wrapping any underlyingException
s
-
stop
public void stop()Description copied from interface:ComponentLifecycle
Stop the componentA stopped component is not expected to be ready to process messages. In the case of
AdaptrisMessageConsumer
, calling stop will pause message delivery. Throwing aRuntimeException
may cause unintended consequences- Specified by:
stop
in interfaceComponentLifecycle
- Overrides:
stop
in classOauthTokenGetter
-
closeService
protected void closeService()- Overrides:
closeService
in classOauthTokenGetter
-
doService
Description copied from interface:Service
Apply the service to the message.
- Specified by:
doService
in interfaceService
- Parameters:
msg
- theAdaptrisMessage
to process- Throws:
ServiceException
- wrapping any underlyingException
s
-
setConnection
The connection to the cache where tokens will be stored.If not expilicitly configured, will be defaulted to
ExpiringMapCache
; 1 Hour + ExpirationPolicy.ACCESSED.- Specified by:
setConnection
in interfaceConnectedService
- Parameters:
c
- theAdaptrisConnection
to use
-
getConnection
Description copied from interface:ConnectedService
Returns theAdaptrisConnection
to use.- Specified by:
getConnection
in interfaceConnectedService
- Returns:
- the
AdaptrisConnection
-
withConnection
-
getCacheKey
-
setCacheKey
Set the key to the cache.- Parameters:
cacheKey
- the key to the cache.
-
withCacheKey
-