Package org.wso2.carbon.connector.core
Class RefreshAccessToken
- java.lang.Object
-
- org.apache.synapse.mediators.AbstractMediator
-
- org.wso2.carbon.connector.core.AbstractConnector
-
- org.wso2.carbon.connector.core.RefreshAccessToken
-
- All Implemented Interfaces:
org.apache.synapse.aspects.AspectConfigurable
,org.apache.synapse.Mediator
,org.apache.synapse.SynapseArtifact
,Connector
- Direct Known Subclasses:
RefreshAccessTokenWithExpiry
public class RefreshAccessToken extends AbstractConnector
This class can be used by connectors to refresh OAuth 2.0 access tokens by setting the following mandatory properties in message context: uri.var.hostName, uri.var.refreshToken. By default this class constructs the refresh url in the format "{uri.var.hostName}/services/oauth2/token?grant_type=refresh_token&client_id= {uri.var.clientId}&client_secret={uri.var.clientSecret}&refresh_token={uri.var.refreshToken}&format=json". Here client_id and client_secret are optional. If you want to use a different url please set the custom url to uri.var.customRefreshUrl in message context prior to using this class mediator. After refresh call this will set the uri.var.accessToken, and uri.var.apiUrl (e.g: for Salesforce) in the message context to be used by subsequent calls.
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
ACCEPT_ENCODING
protected static String
CACHE_CONTROL
protected static String
PRAGMA
protected static String
PROPERTY_PREFIX
-
Constructor Summary
Constructors Constructor Description RefreshAccessToken()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connect(org.apache.synapse.MessageContext messageContext)
implements the connection logic to external API or custom service patternprotected void
extractAndSetPropertyAndRegistryResource(org.apache.synapse.MessageContext messageContext, String jsonResponse, org.apache.synapse.registry.Registry registry, String accessTokenRegistryPath)
protected String
getPostData(org.apache.synapse.MessageContext messageContext)
protected void
handleRefresh(org.apache.synapse.MessageContext messageContext, org.apache.synapse.registry.Registry registry, String accessTokenRegistryPath)
protected boolean
reuseSavedAccessToken(org.apache.synapse.MessageContext messageContext, org.apache.synapse.registry.Registry registry, String accessTokenRegistryPath)
-
Methods inherited from class org.wso2.carbon.connector.core.AbstractConnector
getParameter, mediate
-
Methods inherited from class org.apache.synapse.mediators.AbstractMediator
auditLog, auditWarn, configure, disableStatistics, disableTracing, divertMediationRoute, enableStatistics, enableTracing, getAspectConfiguration, getCommentsList, getDescription, getInputType, getLastSequenceFaultHandler, getLog, getMediatorName, getMediatorPosition, getOutputType, getRegisteredMediationFlowPoint, getShortDescription, getTraceState, getType, handleException, handleException, isBreakPoint, isContentAltering, isContentAware, isSkipEnabled, isStatisticsEnable, isTraceOn, isTraceOrDebugOn, isTracingEnabled, registerMediationFlowPoint, reportCloseStatistics, reportOpenStatistics, setBreakPoint, setCommentsList, setComponentStatisticsId, setDescription, setEffectiveTraceState, setMediatorPosition, setShortDescription, setSkipEnabled, setTraceState, shouldCaptureTracing, shouldTrace, shouldTrace, traceOrDebug, traceOrDebugWarn, unregisterMediationFlowPoint
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.synapse.Mediator
getMediatorName, getMediatorPosition, getShortDescription, getTraceState, getType, isContentAltering, isContentAware, reportCloseStatistics, reportOpenStatistics, setComponentStatisticsId, setMediatorPosition, setShortDescription, setTraceState
-
-
-
-
Field Detail
-
PROPERTY_PREFIX
protected static final String PROPERTY_PREFIX
- See Also:
- Constant Field Values
-
ACCEPT_ENCODING
protected static final String ACCEPT_ENCODING
- See Also:
- Constant Field Values
-
CACHE_CONTROL
protected static final String CACHE_CONTROL
- See Also:
- Constant Field Values
-
PRAGMA
protected static final String PRAGMA
- See Also:
- Constant Field Values
-
-
Method Detail
-
connect
public void connect(org.apache.synapse.MessageContext messageContext) throws ConnectException
Description copied from interface:Connector
implements the connection logic to external API or custom service pattern- Specified by:
connect
in interfaceConnector
- Specified by:
connect
in classAbstractConnector
- Throws:
ConnectException
- when error during conenction to APIs or unexpected errors
-
reuseSavedAccessToken
protected boolean reuseSavedAccessToken(org.apache.synapse.MessageContext messageContext, org.apache.synapse.registry.Registry registry, String accessTokenRegistryPath)
- Parameters:
messageContext
-registry
-accessTokenRegistryPath
-- Returns:
- returns a boolean. true - token refresh is needed. false - token refresh is not needed
-
handleRefresh
protected void handleRefresh(org.apache.synapse.MessageContext messageContext, org.apache.synapse.registry.Registry registry, String accessTokenRegistryPath) throws ConnectException
- Throws:
ConnectException
-
getPostData
protected String getPostData(org.apache.synapse.MessageContext messageContext)
-
extractAndSetPropertyAndRegistryResource
protected void extractAndSetPropertyAndRegistryResource(org.apache.synapse.MessageContext messageContext, String jsonResponse, org.apache.synapse.registry.Registry registry, String accessTokenRegistryPath) throws IOException, ConnectException, org.json.JSONException
- Throws:
IOException
ConnectException
org.json.JSONException
-
-