Iv'e been using this guide: https://spring.io/guides/gs/rest-service to create a RESTFul web service, my issue I am having is that I do not know how to get information such as the clients IP address, is this possible with this API?
Thanks,
Iv'e been using this guide: https://spring.io/guides/gs/rest-service to create a RESTFul web service, my issue I am having is that I do not know how to get information such as the clients IP address, is this possible with this API?
Thanks,
In your Spring Rest Controller you can add HttpServletRequest to get client info.
Example
@GetMapping("/dummyurl")
public Boolean syncWithServNow(HttpServletRequest httpReq, @RequestParam("username") String username) {
System.out.println(httpReq.getRemoteAddr()); // Line 1
}
In most cases it will work. In case like url is accessed by web server over a proxy server or has a load balancer this will do.
httpReq.getHeader("X-FORWARDED-FOR");