on 01-20-2014 8:08 AM
Dear All,
I have a situation in my Webdynpro Java Application where I have to capture the IP address of the end user's PC. I use the below code for capturing IP:
IWDRequest req = WDProtocolAdapter.getProtocolAdapter().getRequestObject();
String ipAddress = req.getClientHostName();
The problem is, the code is working perfectly in Quality system, but not in Production system. The IP which is captured in the Production system is the Portal IP itself. Is the problem has to do with some Network settings or the code has to be changed?
Hi Patralekha,
Thanks for that helpful link you provided. I was able to do some workarounds by adding servlet.jar as external library to my DC. The below code is what I wrote in my DC:
HttpServletRequest request=(HttpServletRequest)TaskBinder.getCurrentTask().getProtocolAdapter().getRequestObjectInternal().getProtocolRequest();
String ip = request.getHeader("X-Forwarded-For");
messageManager.reportSuccess("X-Forwarded-For: "+ip);
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getHeader("Proxy-Client-IP");
messageManager.reportSuccess("Proxy-Client-IP: "+ip);
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getHeader("WL-Proxy-Client-IP");
messageManager.reportSuccess("WL-Proxy-Client-IP: "+ip);
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getHeader("HTTP_CLIENT_IP");
messageManager.reportSuccess("HTTP_CLIENT_IP: "+ip);
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
messageManager.reportSuccess("HTTP_X_FORWARDED_FOR: "+ip);
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getRemoteAddr();
messageManager.reportSuccess("getRemoteAddr: "+ip);
ip = null
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getRemoteHost();
messageManager.reportSuccess("getRemoteHost: "+ip);
}
For all the messages except the last two messages, I get null as the answer. For request.getRemoteAddr() and request.getRemoteHost(), it is returning the proxy.
Can anyone please help on this or guide me in the right path?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is one issue in
request.getRemoteAddr()
The problem, is that the IP we get is not always the correct IP. For example if our server is behind a load balancer, the method “request.getRemoteAddr” returns the IP of the load balancer and not the IP of the remote client. Another common example, is that the client is behind some proxy or even several proxies. The IP we will get will not be the correct IP.
Check following link:
Thanks for the link Patralekha.
I see that, there also the code accesses 'X-Forwarded-For' parameter. It seems that parameter will be false by default in SAP Webdispatcher. We have asked the basis team to configure that. Since it is PRD server, unfortunately we can't do that at this time. Once that is done and if my code works, I will update this place
Can you please try following code.
You may not get the real client IP if a the client is behind a proxy, you will get the IP of the proxy and not the client. However, the proxy may include the requesting client IP in a special HTTP header.
HttpServletRequest req=(HttpServletRequest)TaskBinder.getcurrentTask().getProtocolAdapter().getRequestObjectInternal().getProtocolRequest();
req.getHeader("X-Forwarded_For);
Thanks,
Patralekha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sujai
There was a similar issue faced by me while in ITS.
You have to cross check with internet settings+port+clear histrory and other popins.
Also in the code where URL is provided : Check the path should be proper, not refering to sap logon files present in local drives, so as to make system independent.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.