views:

48

answers:

3

Hi, I am writing a Java Rest Web Service and need the caller's IP Address. It thought I saw this in the cookie once, but know don't see it. Is there a consistent place to get this information? I saw one example of using an "OperationalContext" to get it, but that was not java.

Thanks

A: 

Assuming you are making your "web service" with servlets, the rather simple method call .getRemoteAddr() on the request object will give you the callers IP address.

mbanzon
oh you were faster :)
kukudas
Not servlets, but Restful Web Services (different, right?).. and I don't have an object that has a getremoteAddr() method.
Doug Houck
A: 

I think you can get the ip through the request object if i'm not mistaken request.getRemoteAddr() or so.

kukudas
Maybe I am missing something, but I don't have a request object. This is a JAX-RS Restful Web service. I do have access to a Request context object, but that does not have a getRemoteAddr() method and seems to be related to "conditional Gets"... whatever those are.
Doug Houck
Hm.. can't you do something like @Context HttpServletRequest request and then use this object request.getRemoteAddr() ?
kukudas
A: 

Ok... I can get the request object that you guys mentioned above by use of the HttpServletRequest Context annotation. I had seen that before, but had lost it somehow. Thank you both for the insight.

Doug Houck