class RequestUtils {

  public static String getRemoteAddress(HttpServletRequest request) {
    String ip = null;
    for (String header : headersToCheck) {
      ip = request.getHeader(header);
      if (!isRemoteAddressUnknown(ip)) {
        break;
      }
    }
    if (isRemoteAddressUnknown(ip)) {
      ip = request.getRemoteAddr();
    }
    if (containsMultipleRemoteAddresses(ip)) {
       ip = ip.substring(0, ip.indexOf(","));
    }
    return ip;
  }

}