Thursday, April 14, 2016

How to get the Client's IP Address in WSO2 API Manager/ WSO2 ESB

Middleware solutions are designed to communicate with multiple parties and most of them are integrations. While integration different systems, It is required to validate the requests and collect statistics. When it comes to collecting statistics, Client's / Request Originator's IP Address plays a vital role.

In order to publish the client's IP to the stat collector, We need to extract the client's IP from the request received to the server.

When the deployment contains WSO2 API Manager or WSO2 Enterprise Service Bus, We can obtain the client's IP address using a property mediator in the InSequence.

If the deployment has a Load Balancer in front of ESB/APIManager, We can use X-Forwarded-For Header property as explained in the blog post of Firzhan.

In a deployment which doest not has Load Balancer in front of WSO2 ESB / API Manager, We can use REMOTE_ADDR to obtain the client's IP Address.

We can extract it as follows with using a property mediator.


 <property name="api.ut.REMOTE_ADDR"
                            expression="get-property('axis2','REMOTE_ADDR')"/&gt

Then we can use it in the sequence. As an example, if we extract the IP Address as above and log it, synapse configuration for it will look like bellow.


<property name="api.ut.REMOTE_ADDR"
                            expression="get-property('axis2','REMOTE_ADDR')"/>
                  <log level="full">
                     <property name="Actual Remote Address"
                               expression="get-property('api.ut.REMOTE_ADDR')"/>
                  </log>

You can use this in the InSequence of ESB or API Manager to obtain the client's IP Address.

2 comments:

  1. I tried this but always giving me localhost address 127.0.0.1 but when i am accessing my application using my IP then it should give IP address...

    ReplyDelete
  2. It's also easy to guess if the password is simply "password" or "admin". Make sure that this password is set to something secure to prevent unwanted access. 192.168.0.1.1

    ReplyDelete