GithubHelp home page GithubHelp logo

wassimyoussef / revamp-mediator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from athiththan11/revamp-mediator

0.0 0.0 0.0 5 KB

A custom mediation logic to convert payload attribute values using WSO2 Class Mediator extension

Java 100.00%

revamp-mediator's Introduction

Revamp Mediator

A custom implementation to convert the attribute values of payloads using WSO2 Class Mediator extensions.

Medium Story

Simply put, the mediation logic will do the following conversion

// original payload

{
    "post": "WSO2 Class Mediator: Revamp",
    "dev": {
        "name": "medium"
    }
}

to

// converted

{
    "post": "WSO2 Class Mediator: Revamp",
    "dev": {
        "name": "Athiththan"
    }
}

Build

Build the project by running ...

mvn clean package

Deploy

After a successful build, copy the revamp-mediator-1.0.0.jar artifact from the target folder and paste it inside <API-M HOME>/repository/components/lib folder. And specify the deployed class mediator inside your required synapse configuration file.

For this demo, I will be using the WSO2 API Manager (2.6.0) and I will choose the _TokenAPI_.xml from the API Synapse Configuraitons folder (You can find your API Synapse Configurtions inside the <API-M HOME>/repository/deployment/server/synapse-configs/default/api folder), which will look as follows ...

<api xmlns="http://ws.apache.org/ns/synapse" name="_WSO2AMTokenAPI_" context="/token">
    <resource methods="POST" url-mapping="/*" faultSequence="_token_fault_">
        <inSequence>
            <property name="uri.var.portnum" expression="get-property('keyManager.port')"/>
            <property name="uri.var.hostname" expression="get-property('keyManager.hostname')"/>
            <send>
                <endpoint>
                    <http uri-template="https://{uri.var.hostname}:{uri.var.portnum}/oauth2/token">
                        <timeout>
                            <duration>60000</duration>
                            <responseAction>fault</responseAction>
                        </timeout>
                    </http>
                </endpoint>
            </send>
        </inSequence>
        <outSequence>
            <send/>
        </outSequence>
    </resource>
    <handlers>
        <handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerCacheExtensionHandler"/>
        <handler class="org.wso2.carbon.apimgt.gateway.handlers.common.SynapsePropertiesHandler"/>
    </handlers>
</api>

Add our custom mediator inside the inSequence section, which will result in ...

    <inSequence>
        <!-- <property name="uri.var.portnum" expression="get-property('keyManager.port')"/>
        <property name="uri.var.hostname" expression="get-property('keyManager.hostname')"/>
        <send>
            <endpoint>
                <http uri-template="https://{uri.var.hostname}:{uri.var.portnum}/oauth2/token">
                    <timeout>
                        <duration>60000</duration>
                        <responseAction>fault</responseAction>
                    </timeout>
                </http>
            </endpoint>
        </send> -->

        <!-- convert dev.name to athiththan | revamp-mediator-1.0.0.jar -->
        <class name="com.athiththan.sample.CustomMediator" />
        <respond />
    </inSequence>

Run

Start your WSO2 API Manager server by executing the command from your <API-M HOME>/bin folder

sh wso2server.sh

or

wso2am-2.6.0

Test & Results

Use the following cUrl command to invoke the token endpoint to examine the mediation logic

curl -k --header "Content-Type: application/json" --request POST --data '{"post":"WSO2 Class Mediator: Revamp","dev":{"name":"medium"}}' https://<YOUR IP ADDRESS>/token

After a successful execution, You will find the results as follows

{"post":"WSO2 Class Mediator: Revamp","dev":{"name":"Athiththan"}}

revamp-mediator's People

Contributors

athiththan11 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.