on 2014 Jan 20 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?
Request clarification before answering.
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
| User | Count |
|---|---|
| 9 | |
| 7 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.