How to use restful web services to obtain remote / client IP addresses in Java?
I wrote rest web service in my project Web service calls may come from different machines I need to find the IP address through the rest WebService
From this link request Getremoteaddr() to use this
But I can't use getremoteaddr() Because my request and response are in XML format
I'm at rest service The Tomcat server uses the post method I have sent the request as XML format
How do I get an IP address?
Solution
Suppose you are using jax-rs:
@GET Produces("application/xlm") public String getData(@Context HttpServletRequest request){ String ip = request.getRemoteAddr(); }
@Context annotations allow you to inject instances
> javax. ws. rs.core. HttpHeaders,> javax. ws. rs.core. UriInfo,> javax. ws. rs.core. Request,> javax. servlet. HttpServletRequest,> javax. servlet. HttpServletResponse,> javax. servlet. ServletConfig,> javax. servlet. ServletContext, and > javax ws. rs.core. Securitycontext object