1

The title pretty much says it all, I have written a REST webservice in Java using JAX-RS and Jersey, and I would like to extract the I.P. address of the client that hits it in my code. If I have a class like this:

@Path("/service")
public class Service {

    @GET
    public void doAction () {

        // ...

    }

}

What do I do from there?

P.s. I'm not asking for debugging help, I'm asking how I can retrieve the IP address of the client that connects to my web service. @ANyarThar provided a good answer.

Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79

1 Answers1

3

How @Context HttpServletRequest as argument in your method,

@GET
public void doAction (@Context HttpServletRequest req) {
    //then get ip address
    String ipAddress = req.getRemoteHost();
}
Wundwin Born
  • 3,467
  • 19
  • 37