es.prodevelop.pui9.utils.PuiRequestUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of es.prodevelop.pui9.services Show documentation
Show all versions of es.prodevelop.pui9.services Show documentation
Support for business layer (BO)
package es.prodevelop.pui9.utils;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import com.google.common.net.HttpHeaders;
/**
* Utility class to extract information from the Request
*
* @author Marc Gil - [email protected]
*/
public class PuiRequestUtils {
private PuiRequestUtils() {
}
/**
* Extract the real client IP from the request
*
* @param request The request
* @return The client IP
*/
public static String extractIp(HttpServletRequest request) {
String ip = Optional.ofNullable(request.getHeader(HttpHeaders.X_FORWARDED_FOR)).orElse(request.getRemoteAddr());
if (ip.contains(",")) {
ip = ip.split(",")[0];
}
if (ip.contains(":")) {
ip = request.getRemoteAddr();
}
return ip;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy