Quantcast
Channel: SCN : All Content - SAP HANA Cloud Platform Developer Center
Viewing all articles
Browse latest Browse all 3285

Getting IP address of connected user in servlet

$
0
0

Getting the IP address of the client connecting to an HCP servlet should be easy.

 

(eg if using Spring MVC)

 

@Controller
@RequestMapping(value = "MyIPAddress")
public class GetIPAddressServlet {  @RequestMapping(method = RequestMethod.GET, produces = "application/json")  @ResponseBody  public String get(HttpServletRequest request, HttpServletResponse response) {  return "{\"ipaddress\":" + request.getRemoteAddr() +"\"}";
}  }

However, this always returns the IP address of what I can only guess is a reverse proxy server that is feeding requests to my app.

 

How do I get access to the real client's IP address? Is it possible? or do I have do do something client side to speak to another (non HCP) server to do the same thing and then send it to HCP?

 

The IP address is getting logged in the HTTP access log - so it must be available somewhere, but how do I get it in my application?

 

Thanks for any pointers!

 

Cheers,

 

Chris


Viewing all articles
Browse latest Browse all 3285

Trending Articles