apim_4xx_support_multiple_analytics_publishers APIM manage workflow with multiple roles APIM 3.0.0 per API based subscription workflow Logging internal HTTP requests Log APIM analytics events to a file Monetization and sample with WSO2 API Manager 2.6.0 Share application and subscription among a set of specific groups or roles WSO2 APIM Correlating analytics event with correlationID APIM analytics distinguish production and sandbox traffic APIM 2.x.x analytics internal and analytics tuneup Configure APIM(Next release) Key Manager User stores APIM(Next release) working with key manager DAS 3.x Parse system variables to Spark Context Revoke OAuth application In APIM 2.1.0 Next WSO2 APIM powered by WSO2 Ballerina Configure WSO2 APIM Analytics on Cluster environment Configure WSO2 DAS 3.1.0 for WSO2 APIM 2.0.0 Analytics WSO2 APIM publishing custom statistics WSO2 APIM Error codes Working with WSO2 message tracer Use DAS admin service to query using Spark SQL Configure WSO2 APIM Analytics using XML WSO2 APIM Generating and Retrieving Custom Statistics Understanding WSO2 APIM Statistics Model Publishing WSO2 APIM 1.10.x Runtime Statistics to DAS with RDBMS Publishing_APIM_1100_Runtime_Statistics_to_DAS Aggregate functions with WSO2 DAS REST API Create a cApp for WSO2 DAS Debugging WSO2 Products using OSGI console. Publishing APIM Runtime Statistics to DAS Deploy cApp on WSO2 DAS How to configure and start the Accumulo minicluster How to setup DNS server on Ubuntu and Ubuntu server How to use Java Reflection how to install apache web server on ubuntu and ubuntu server How to install Mail server on Ubuntu and Ubuntu server How to install squirrelmail webmail client on Ubuntu and Ubuntu Server Pass and return String value to JNI method Pass and return numeric value to JNI method Calling a C Function from the Java Programming Language using JNI AXIS 2 Sample web service Client with maven and eclipse How to setup AXIS 2 with Apache Tomcat AXIS 2 Sample web service with maven and eclipse Robot framework Sample with Selenium Robot framework Custom Library Sample Behaviour-Driven Development with JBehave and Eclipse Play Audio with Netbeans and linking with LibVLC Implement LibVLC based player with QT-part2 Simple Audio playing sample with LibVLC How to install LibVLC on Ubuntu Implement LibVLC based player with QT-part1
APIM 3.0.0 per API based subscription workflow
  1. Introduction

    By default, subscription workflow applies to all the APIs. But in case if you need to apply workflow only for the selected APIs, there is no way to achieve that. But this can be achieved via the available workflow extensions.

    The solution we are going to implement is, apply the workflow by checking the properties of an API. An example use case is as below. In case if you have two types of APIs name secured and public. But you need to review and approve subscription creation for secured APIs. Subscription creation for the public APIs is approved without user approval. Let’s see how we can implement this in APIM 3.0.0. Type of the API is defined as an API property and it is done by the API developer.

    The default subscription workflow implementation for workflow engines is “org.wso2.carbon.apimgt.impl.workflow.SubscriptionCreationWSWorkflowExecutor”. We can extend the implementation and apply the new logic by overriding its implementation. In the workflow extension, we can check the API properties and check API contain a property “type” with a “secured” value. In such cases, we engage the user approval workflow. If the above property is not there, subscription creation completes without user interaction.

  2. Prerequisites
    • WSO2 API Manager 3.0.0
    • WSO2 Enterprise Integrator 6.5.0
    • Configure API Manager for subscription workflow according to the official document
  3. Implementation
    • Create a new maven project and include the following dependency
    • Add a new java class that extends the “SubscriptionCreationWSWorkflowExecutor”
    • Override the method “execute” with the following content.
                          SubscriptionWorkflowDTO subsWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
                          APIIdentifier apiIdentifier = new APIIdentifier(subsWorkflowDTO.getApiProvider(), subsWorkflowDTO.getApiName(),
                          try {
                              APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer();
                              API api = apiConsumer.getAPI(apiIdentifier);
                              if (api.getAdditionalProperties().containsKey(WF_TYPE) && WF_TYPE_SECURED
                                      .equalsIgnoreCase(api.getAdditionalProperties().get(WF_TYPE).toString())) {
                                  return super.execute(workflowDTO);
                          } catch (APIManagementException e) {
                              log.error("Error occurred while processing workflow request.", e);
                              throw new WorkflowException("Error occurred while processing workflow request.", e);
                          //Default flow: complete the subscription creation
                          WorkflowResponse workflowResponse = complete(workflowDTO);
                          return workflowResponse;
    • In this code sample, it will get the API ID and API object from the workflow details DTO it gets. Once the API properties are read, check “apiType” property is defined. If the property is defined and its value is “secured” execute the user approval workflow. Otherwise, it completes the workflow by approving the subscription.
    • Build the project and copy target/com.rukspot.sample.apimgt.workflow.apibase-1.0-SNAPSHOT.jar to <APIM_HOME>/repository/components/lib/ directory
    • Edit the /_system/governance/apimgt/applicationdata/workflow-extensions.xml registry resource and define the “SubscriptionCreation” workflow extension as follow.
                          <SubscriptionCreation executor="com.rukspot.sample.apimgt.workflow.apibase.SubscriptionWorkflow">
                               <Property name="serviceEndpoint">http://localhost:9765/services/SubscriptionApprovalWorkFlowProcess/</Property>
                               <Property name="username">admin</Property>
                               <Property name="password">admin</Property>
                               <Property name="callbackURL">https://localhost:8243/services/WorkflowCallbackService</Property>
    • Restart the APIM server
  4. Testing
      • Create an API with “apiType” property which is value is “secured”
      • Create another API without the above property
      • Create an application to subscribe to the above API
      • Subscribe to the above APIs.
      • You will see, “securedAPI” subscription is not yet activated.
      • The admin portal will list approval tasks for the above APIs.
      • Once the subscription is approved, it’s subscription status changed to “UNBLOCKED” in the dev portal.
  5. Code Sample

    Please find the sample code from GitHub

Add Comment

* Required information
Powered by Commentics

Comments (0)

No comments yet. Be the first!