Class GetAndCacheOauthToken
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.http.oauth.OauthTokenGetter
-
- com.adaptris.core.http.oauth.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 ofGetOauthToken
that automatically caches theAccessToken
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 aCacheConnection
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
Constructors Constructor Description GetAndCacheOauthToken()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeService()
void
doService(AdaptrisMessage msg)
Apply the service to the message.java.lang.String
getCacheKey()
AdaptrisConnection
getConnection()
Returns theAdaptrisConnection
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 componentGetAndCacheOauthToken
withCacheKey(java.lang.String s)
GetAndCacheOauthToken
withConnection(AdaptrisConnection c)
-
Methods 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
-
-
-
-
Method Detail
-
prepare
public void prepare() throws CoreException
Description copied from interface:ComponentLifecycleExtension
Prepare for initialisation.- Specified by:
prepare
in interfaceComponentLifecycleExtension
- Overrides:
prepare
in classOauthTokenGetter
- Throws:
CoreException
-
initService
protected void initService() throws CoreException
- Overrides:
initService
in classOauthTokenGetter
- Throws:
CoreException
-
start
public void start() throws CoreException
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
public void doService(AdaptrisMessage msg) throws ServiceException
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
public void setConnection(AdaptrisConnection c)
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
public AdaptrisConnection getConnection()
Description copied from interface:ConnectedService
Returns theAdaptrisConnection
to use.- Specified by:
getConnection
in interfaceConnectedService
- Returns:
- the
AdaptrisConnection
-
withConnection
public GetAndCacheOauthToken withConnection(AdaptrisConnection c)
-
getCacheKey
public java.lang.String getCacheKey()
-
setCacheKey
public void setCacheKey(java.lang.String cacheKey)
Set the key to the cache.- Parameters:
cacheKey
- the key to the cache.
-
withCacheKey
public GetAndCacheOauthToken withCacheKey(java.lang.String s)
-
-