IBM Worklight 6: ¿Cómo obtendría la dirección IP del cliente en el lado del adaptador?

I want to have client ip address on adapter side but i don't know what is the worklight api for that. I search for it but no luck.

I used this api on client side code which is given below

WL.Device.getNetworkInfo(function (networkInfo) {
        console.log ("Ip address of device "+networkInfo.ipAddress);

It works fine and i can pass this to the adapter from client side. But i just wanted to know whether the same thing can be implemented on server side in adapter procedure.

And I also used this code which is given below

var request = WL.Server.getClientRequest();
    var userAgent = request.getHeader("User-Agent");

Can we get Ip address here using this API in adapter procedure.

preguntado el 12 de febrero de 14 a las 06:02

1 Respuestas

WL.Server.getClientRequest() will return a reference to HttpServletRequest Java object ( You can use Java APIs to get the info you need, e.g.

var request = WL.Server.getClientRequest();

Note that in case there are gateways/proxies between client and your WL server (and there most probably are) above APIs will get you info about proxies. In case you need the actual device IP you can use

var request = WL.Server.getClientRequest();
var IPAddress = request.getHeader('x-forwarded-for'); 


In order to iterate over headers enumeration and get the full list of request headers use following code:

    var headers = {};

var request = WL.Server.getClientRequest();
var headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()){
    var headerName = headerNames.nextElement();
    var headerValue = request.getHeader(headerName);
    headers[headerName] = headerValue;

Respondido el 16 de junio de 14 a las 14:06

I am getting null if i use request.getHeader('x-forwarded-for') and first approach i can't use because we have ateways/proxies/firewall/radware between client and your WL server. Please suggest what should we use. - vishal_g

Please update on this we are still facing the same issue not able to get actual client ip address. - vishal_g

in case your middleware strips this this info there's no really way of getting it. Try iterating through getHeaderNames() and see whether any header might contain the info you need. - Anton

Can you just help me out for iterating getHeaderNames() because while printing this , m getting as output so please let me know how should i iterate it and get the actual value. - vishal_g

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.