Class GenerateAccessToken

  • All Implemented Interfaces:
    org.apache.synapse.aspects.AspectConfigurable, org.apache.synapse.Mediator, org.apache.synapse.SynapseArtifact, Connector

    public class GenerateAccessToken
    extends AbstractConnector
    This class can be used by connectors to generate OAuth 2.0 access tokens by setting the following mandatory property in message context: uri.var.hostName. By default this class constructs the token generation url in the format "{uri.var.tokenEndpointUrl}?grant_type=client_credentials&client_id= {uri.var.clientId}&client_secret={uri.var.clientSecret}&format=json". Here client_id and client_secret are mandatory. If you want to use a different url please set the custom url to uri.var.authorizationUrl in message context prior to using this class mediator. After token generation call this will set the uri.var.accessToken in the message context to be used by subsequent calls.
    • 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 pattern
      protected 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 handleTokenGeneration​(org.apache.synapse.MessageContext messageContext, org.apache.synapse.registry.Registry registry, String accessTokenRegistryPath)  
      • 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 interface org.apache.synapse.Mediator

        getMediatorName, getMediatorPosition, getShortDescription, getTraceState, getType, isContentAltering, isContentAware, reportCloseStatistics, reportOpenStatistics, setComponentStatisticsId, setMediatorPosition, setShortDescription, setTraceState
      • Methods inherited from interface org.apache.synapse.SynapseArtifact

        getDescription, setDescription
    • Constructor Detail

      • GenerateAccessToken

        public GenerateAccessToken()
    • 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 interface Connector
        Specified by:
        connect in class AbstractConnector
        Throws:
        ConnectException - when error during conenction to APIs or unexpected errors
      • handleTokenGeneration

        protected void handleTokenGeneration​(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