I am using the following code to get the IP address form a client.
public String getIp(@Context HttpServletRequest requestContext, @Context SecurityContext context) {
    HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    String ipAddress = request.getHeader("X-FORWARDED-FOR");
    if (ipAddress == null) {
        ipAddress = request.getRemoteAddr();
    }
    return ipAddress;
}
However, when it executes, it returns 0:0:0:0:0:0:0:1. It is running on my local pc, and I would expect it to return good ol 127.0.0.1. Any ideas why not?


0:0:0:0:0:0:0:1is an IPv6 IP address. You need to ensure you set it to IPv4 if you want only the IPv4 response. See @Javier's answer.