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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>