WSO2 Save each request and response with requester IP in MYSQL Database

377 Views Asked by At

I have developed some APIs flow in WSO2 developer studio and host it on WSO2 EI Server.

And then i published those URLs to WSO2 API Publisher and implemented the oAuth2 security over there.

At last the client/consumer have access to the URLs from API Publisher.

Now what i want that every request and response of the service should be stored in MySQL external table.

Any idea what to do in WSO2 EI flow. or any other alternate.

1

There are 1 best solutions below

4
On

You need to store the request when it comes to the sequence in a property mediator and the same has to be done for response. You need to create a data service wherein you need to mention the query of MySQL else you can use a DB mediator. Next before ending the out sequence with a send or loopback or respond mediator you need to use clone mediator and call either the data service or DB mediator. For DB Mediator refer below link. https://docs.wso2.com/display/ESB500/Sample+361%3A+Introduction+to+DBReport+Mediator

Below is the code snippet

<sequence name="cloneTest" xmlns="http://ws.apache.org/ns/synapse">

    <in>
     <property expression="." name="requestBody" scope="default" type="STRING"/>

     <call>
     <endpoint key="conf:/custom/TestEP/BennerERPEndpoint.xml"/>
     </call>
     <property expression="." name="responseBody" scope="default" type="STRING"/>
        <clone sequential="false">
            <target>
                <sequence>
                    <log level="custom">
                        <property name="Into DB Mediator Sequence" value="DBMediator"/>
                    </log>
                    <sequence key="DBMediator"/>

                </sequence>
            </target>
            <target>
                <sequence>
                    <log level="custom">
                        <property name="Exiting" value="Exit"/>
                    </log>
                   <send/>
                </sequence>
            </target>
        </clone>
    </in>
</sequence>