WSO2 API Manager is a complete solution for publishing APIs, creating and managing a developer community and for routing API traffic in a scalable manner. It leverages the integration, security and governance components from the WSO2 Enterprise Service Bus, WSO2 Identity Server, and WSO2 Governance Registry. In addition, as it is powered by the WSO2 Business Activity Monitor (BAM), the WSO2 API Manager is ready for massively scalable deployments immediately.
...
Application access tokens are generated at the application level and valid for all APIs that you associate to the application. These tokens have a fixed expiration time, which is set to 60 minutes 3600 seconds by default. You can change this to a longer time, even for several weeks. Consumers can regenerate the access token directly from the API Store. To change the default expiration time, you open the <APIM_HOME>/repository/conf/identity.xml
file and change the value of the element <ApplicationAccessTokenDefaultValidityPeriod>
. If you set a negative value, the token never expires. This value only applies to the new applications you create.
Application user access token
...
- Open the API Publisher (
https://<hostname>:9443/publisher)
and log in asapicreator
if you haven't done so already. - Click the
PhoneVerification
API to open it and then click the Edit link right next to the API's name. This opens the API in its edit mode. - Click the Edit Swagger Definition button.
When the Swagger definition of the API opens, navigate to the GET method, add two the following parameters to it as
PhoneNumber
andLicenseKey
and document their descriptionsand remove the existing body parameter. The code is given below:Anchor thisStep thisStep Code Block parameters: - description: Give the phone number to be validated name: PhoneNumber type: string required: "True" paramType: query - description: "Give the license key. If you don't have any, enter 0" name: LicenseKey type: string required: "True" paramType: query
- Click Save once the changes are done. In a later section, we will see how these parameters appear to subscribers in the API Console of the API Store.
...
- Log in to the API Publisher as
apicreator
if you are not logged in already. - Click on the
PhoneVerification
API and then the Copy button that appears in its Overview tab. Give a new version number (e.g., 2.0.0) and click Done.
Tip Tip: The Default Version option means that you make this version the default in a group of different versions of the API. A default API can be invoked without specifying the version number in the URL. For example, if you mark http://host:port/youtube/2.0 as the default version when the API has 1.0 and 3.0 versions as well, requests made to http://host:port/youtube/ get automatically routed to version 2.0.
If you mark any version of an API as the default, you get two API URLs in its Overview page in the API Store. One URL is with the version and the other is without. You can invoke a default version using both URLs.
If you mark an unpublished API as the default, the previous default, published API will still be used as the default until the new default API is published (or prototyped).
...
Click the APIs menu in the API Store and then click on the API that you want to invoke. When the API opens, go to its API Console tab.
Expand the GET method of the resource
CheckPhoneNumber
. Note the parameters that you added in this step now appearing with their descriptions in the console.Give sample values to the
PhoneNumber
andLicenseKey
and click Try it Out to invoke the API.Tip Tip: If you cannot invoke the API's HTTPS endpoint (causes the SSLPeerUnverified exception), it could be because the security certificate issued by the server is not trusted by your browser. To resolve this issue, access the HTTPS endpoint directly from your browser and accept the security certificate.
Note the response for the API invocation. As we used a valid phone number in this example, the response is valid.
...
Steps below explain how to configure WSO2 BAM 2.45.10 with the API Manager. Let's do the configurations first.
Do the following changes in
<APIM_HOME>/repository/conf/api-manager.xml
file:- Enable API usage tracking by setting the
<APIUsageTracking>
element to true - Set the Thrift port to 7614
- Uncomments and set the data source used for getting BAM statistics in
<DataSourceName>
element. - Set <BAMServerURL> to tcp://<BAM host IP>:7614/ where <BAM host IP> is the machine IP address. Do not use localhost unless you're in a disconnected mode.
Code Block language xml <APIUsageTracking> <!-- Enable/Disable the API usage tracker. --> <Enabled>true</Enabled> <PublisherClass>org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageDataBridgeDataPublisher</PublisherClass> <ThriftPort>7614</ThriftPort> <BAMServerURL>tcp://<BAM host IP>:7614/</BAMServerURL> <BAMUsername>admin</BAMUsername> <BAMPassword>admin</BAMPassword> <!-- JNDI name of the data source to be used for getting BAM statistics. This data source should be defined in the master-datasources.xml file in conf/datasources directory. --> <DataSourceName>jdbc/WSO2AM_STATS_DB</DataSourceName> </APIUsageTracking>
- Enable API usage tracking by setting the
Specify the datasource definition in
<APIM_HOME>/repository/conf/datasources/master-datasources.xml
file as follows.Code Block language xml <datasource> <name>WSO2AM_STATS_DB</name> <description>The datasource used for getting statistics to API Manager</description> <jndiConfig> <name>jdbc/WSO2AM_STATS_DB</name> </jndiConfig> <definition type="RDBMS"> <configuration> <!-- JDBC URL to query the database --> <url>jdbc:h2:<BAM_HOME>/repository/database/APIMGTSTATS_DB;AUTO_SERVER=TRUE</url> <username>wso2carbon</username> <password>wso2carbon</password> <driverClassName>org.h2.Driver</driverClassName> <maxActive>50</maxActive> <maxWait>60000</maxWait> <testOnBorrow>true</testOnBorrow> <validationQuery>SELECT 1</validationQuery> <validationInterval>30000</validationInterval> </configuration> </definition> </datasource>
Save the database driver JAR inside both
<AM_HOME>/repository/components/lib
and<BAM_HOME>/repository/components/lib
folders.Next, prepare BAM to collect and analyze statistics from API manager.
- Download WSO2 BAM 2.45.1 0 or later from location: http://wso2.com/products/business-activity-monitor.
Change port offset of BAM to 3 by editing the file
<BAM_HOME>/repository/conf/carbon.xml
file (search for the offset node).Code Block language html/xml <Offset>3</Offset>
This increments all ports used by the server by 3, which means the BAM server will run on port 9446. Port offset is used to increment the default port by a given value. It avoids possible port conflicts when multiple WSO2 products run in same host.
- Do the following changes in
In
:Copy<BAM_HOME>/repository/conf/datasources/bam_datasources.xml
file, copy/paste
WSO2_AMSTATS_DB
definition from API Manager'smaster-datasources.xml
file. You edited it in step 2. Replace the port of
WSO2BAM_CASSANDRA_DATASOURCE
in URL (jdbc:cassandra://localhost:9163/EVENT_KS
). Note that localhost is used here; not the machine IP.Note - Do not edit the
WSO2BAM_UTIL_DATASOURCE
, which is using the offset - Cassandra is bound by default on localhost, unless you change the data-bridge/data-bridge-config.xml file
Copy the file - Do not edit the
Restart the BAM server by running
<BAM_HOME>/bin/wso2server.[sh/bat]
.
Let's see the statistics now.Generate some traffic via the API Gateway (invoke the Cdyne API we use in this guide) and wait a few seconds.
- Connect to the API Publisher as a creator or publisher.
In the publisher role, you are able to see all stats and as creator, you see stats specific to the APIs you create. - Click the Statistics menu. We show the sample statistics here, but you will see graphs specific to your instance.
- Similarly, API subscribers can also see statistics though the API Store. Click the Statistics menu as follows:
<APIM_HOME>/statistics/API_Manager_Analytics.tbox
to directory <BAM_HOME>/repository/deployment/server/bam-toolbox
. If this folder is not in the BAM installation directory by default, create it. The toolbox describes the information collected, how to analyze the data, as well as the location of the database where the analyzed data is stored.
Open <BAM_HOME>/repository/
conf/etc/hector-config.xml file and change the port to localhost:9163. You must add the other nodes too when configuring a clustered setup.
language | xml |
---|
...