javarestjerseyrestful-url

How do I get the full request URL with host-name/ip of a rest call?


I need to get the full url with the host name or IP address from a restful request made to my rest service. Is there any way this can be done?

Similar to InetAddress ip = ip.getHostName(); in java.


Solution

  • With Jersey you can do the following

    String clientHost = req.getRemoteHost(); // req is HttpServletRequest
    String clientAddr = req.getRemoteAddr();