views:

44

answers:

1

When using JAX-RS is there a way of getting information about who is calling the webservice? Can we get the ip or url of the calling application? If so how do you do it?

Thanks

+2  A: 

The below should work on Weblogic (servlet container).

Once you get the HttpServletRequest via the @Context, you can access any of the methods of HttpServletRequest.

@GET
@Produces("text/plain")
public String showIP(@Context HttpServletRequest hsr) {
   return hsr.getRemoteAddr();
}

Note that there is no way to figure out what the real client IP address if there are any proxies in between.

JoseK