This documentation is for WSO2 API Manager 1.10.0 View documentation for the latest release.
Page Comparison - Adding Mediation Extensions (v.7 vs v.8) - API Manager 1.10.0 - WSO2 Documentation

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The API Gateway has a default mediation flow, which you can extend by adding custom mediation sequences. You create a custom mediation sequence either manually or using WSO2 tooling support (i.e., WSO2 Developer Studio), and then engage it per API or globally to all APIs of a specific tenant.  

Table of Contents
maxLevel3
minLevel3

Default mediation flow

The address endpoint of the WSO2 API Manager cannot be constructed dynamically. To achieve the requirement of a dynamic endpoint, you can use the default endpoint instead. The default endpoint sends the message to the address specified in the To header. The To header can be constructed dynamically. For example,

Code Block
languagexml
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="default-endpoint">
  <property name="service_ep" expression="fn:concat('http://jsonplaceholder.typicode.com/', 'posts/')"/>
  <header name="To" expression="get-property('service_ep')"/>
</sequence>

In this example, you have constructed the service_ep property dynamically and assigned the value of this property to the To header. The default endpoint sends the message to the address specified in the To header, in this case, http://jsonplaceholder.typicode.com/posts/.

Creating per-API extensions

Table of Contents
maxLevel4
minLevel4

Create and upload using WSO2 Developer Studio

The recommended way to engage a mediation extension sequence per API is to create a custom sequence using WSO2 Developer Studio, upload it via the APIM Perspective and then engage it using the API Publisher. The following tutorial demonstrates how to do this: Change the Default Mediation Flow of API Requests.

Create and upload manually in the API Publisher

You can also create a custom mediation sequence manually and upload it from the API Publisher itself. For instance, you can copy the above default mediation flow content into an XML file. In the Implement tab of the API, select the Enable Message Mediation check box and click Choose File in the In Flow or Out Flow field (for the example above, it needs to be uploaded to the In flow). Once the file is uploaded, save and publish the API. When you invoke the API, the request is sent to the endpoint referred to in the To header.

Create manually and save in the file system

Alternatively, you can name the mediation XML file in the pattern <API_NAME>:v<VERSION>--<DIRECTION> and save it directly in the following location:

...

The above sequence prints a log message on the console whenever the TwitterSearch API is invoked.

Creating global extensions

You can also engage mediation extension sequences to all APIs of a specific tenant at once. To do that, simply create the XML file with the naming pattern WSO2AM--Ext--<DIRECTION> and save it in the <APIM_HOME>/repository/deployment/server/synapse-configs/default/sequences directory.

...