2

I'm using RESTEasy services in my application and now I'm forced to get the clients IP addresses. So the question is... how can I do that?. Thanks in advance

EDITED I've just came to a solution with servlet filter... but still.. can that be done inside of RESTEasy service?

Andrew
  • 2,663
  • 6
  • 28
  • 50

1 Answers1

16

You can annotate a Context in your resource like this:

@GET
@Path("/{id}")
public Response getMe(
            final @PathParam("id") String id,
            @Context HttpServletRequest req) {

     System.err.println(req.getRemoteAddr());
PeterMmm
  • 24,152
  • 13
  • 73
  • 111
  • 1
    This works well, but if you're behind a web server (Apache for instance), it will give you the IP of the server instead. If you want to get the actual IP of the original request, take a look at this answer: http://stackoverflow.com/questions/4678797/how-do-i-get-the-remote-address-of-a-client-in-servlet. – felipe_gdr Nov 22 '15 at 22:36