class ServletRequestUtil {

    public static String getRemoteAddress(final HttpServletRequest request) {
        String addr = request.getRemoteAddr();
        if (LOOPBACK_ADDRESS.equals(addr)) {
            String xff = request.getHeader(XFF_HEADER);
            if (xff != null) {
                String[] addrs = xff.split(",");
                final String xffAddr = addrs[addrs.length - 1].trim();
                if (InetAddresses.isInetAddress(xffAddr)) {
                    addr = xffAddr;
                }
            }
        }
        return addr;
    }

}