cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Capturing of IP Address through Java Code

Former Member
0 Likes
1,414

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?

View Entire Topic
Former Member
0 Likes

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

Former Member
0 Likes

Hi Patralekha,

Thanks for replying. For using the HttpServletRequest in my WD Java code, I need to add the servlet.jar into my DC right? I'll try that way and comeback.