@Test public void testGetRemoteAddress() { HttpServletRequest mockedRequest = createMock(HttpServletRequest.class); expect(mockedRequest.getHeader("X-Forwarded-For")).andReturn(null); expect(mockedRequest.getHeader("Proxy-Client-IP")).andReturn("unknown"); expect(mockedRequest.getHeader("WL-Proxy-Client-IP")).andReturn(""); expect(mockedRequest.getHeader("HTTP_CLIENT_IP")).andReturn("unknown"); expect(mockedRequest.getHeader("HTTP_X_FORWARDED_FOR")).andReturn(REMOTE_ADDRESS); replay(mockedRequest); String remoteAddress = RequestUtils.getRemoteAddress(mockedRequest); assertEquals(REMOTE_ADDRESS, remoteAddress); verify(mockedRequest); }
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; }
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; } }
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; }  }
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; }  static String getRemoteAddress(HttpServletRequest request); static String getRemoteAddress(); }
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; }  static String getRemoteAddress(HttpServletRequest request); static String getRemoteAddress();  }