Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

The API Gateway has a default mediation flow that is executed in each API invocation. You can do additional custom mediation for the messages in the API Gateway by extending its mediation flow. An extension is provided as a synapse mediation sequence.

You can design all sequences using a tool like WSO2 Developer Studio, and store the sequence.xml file in the governance registry. The registry collection where sequences are stored is customsequences, which is available by default in apimgt governance registry location. The registry path is /_system/governance/apimgt/customsequences. Store the InSequence files in apimgt/customsequences/in folder and the OutSequence files in apimgt/customsequences/out folder. For example, if you have an in sequence file as testInSequence, you must save it in /_system/governance/apimgt/customsequences/in/testInSequence.xml and if you have an out sequence file as testOutSequence, save it in /_system/governance/apimgt/customsequences/out/testOutSequence.xml.

There are two ways to apply mediation extensions to messages. They are as follows:

...

Given below is the naming pattern of the sequence to follow when creating a global extension sequence.

...

Given below is the naming pattern to follow when creating of a per-API extension sequence.

...

Code Block
titleAPI Extension Sequence Example
<sequence xmlns="http://ws.apache.org/ns/synapse" name="admin--TwitterSearch:v1.0.0--In">
    <log level="custom">
        <property name="TRACE" value="API Mediation Extension"/>
    </log>
</sequence>
Info

NOTE: The tenant username must be given as <username>-AT-<domain> in the configuration. For example, if the tenant username is testuser and the domain is wso2.com, then the name attribute in the above configuration must be testuser-AT-wso2.com--TwitterSearch:v1.0.0–In. The @ sign must given as AT.

To test the code in super-tenant mode, copy it to an XML file (e.g., twittersearch_ext.xml) and save the file in the <APIM_HOME>/repository/deployment/server/synapse-configs/default/sequences directory, if you are using a standalone server. In multi-tenant mode, copy the file to the tenant's synapse sequence folder. For example, if tenant id is 1, then copy it to <API_Gateway>/repository/tenants/1/synapse-configs/default/sequences folder. 

...

Alternatively to the above approach, you can also attach extension sequences to an API using the API Publisher Web interface , at the time the API is created. Log in to the API Publisher (https://localhost:9443/publisher) and click Add from the left panel. In the Add New API page that opens, navigate down to the Sequences section. There, you can select In/Out sequences for the API from the drop-down lists. For example,

...

To populate these drop-down lists, you can write custom sequences using a tool like WSO2 Developer Studio and store the sequence.xml file in the API Manager governance registry. For more information, see must add mediation sequences as explained in the beginning.

Invoking the extension sequences

When an API is published, a file with its synapse configuration gets is created on the API Gateway. This synapse configuration has a set of handlers as shown in the following example:

...