diff options
author | developerKurt <mustafakurt.business@gmail.com> | 2020-01-02 09:17:23 +0300 |
---|---|---|
committer | developerKurt <mustafakurt.business@gmail.com> | 2020-01-02 09:17:23 +0300 |
commit | aff84ec3ae6faf7d930319329d8750634195445a (patch) | |
tree | 9a5bcf6da0ef088112de92be591d71e1a1d2f7d9 /src/main/java/org/traccar/helper/IpRetriever.java | |
parent | 1c43e31b622eba08b14079c03f9ad1861b4a0868 (diff) | |
download | traccar-server-aff84ec3ae6faf7d930319329d8750634195445a.tar.gz traccar-server-aff84ec3ae6faf7d930319329d8750634195445a.tar.bz2 traccar-server-aff84ec3ae6faf7d930319329d8750634195445a.zip |
Implemented project's code style
Diffstat (limited to 'src/main/java/org/traccar/helper/IpRetriever.java')
-rw-r--r-- | src/main/java/org/traccar/helper/IpRetriever.java | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/src/main/java/org/traccar/helper/IpRetriever.java b/src/main/java/org/traccar/helper/IpRetriever.java index 4bab93edb..814a78a4b 100644 --- a/src/main/java/org/traccar/helper/IpRetriever.java +++ b/src/main/java/org/traccar/helper/IpRetriever.java @@ -3,45 +3,45 @@ package org.traccar.helper; import javax.servlet.http.HttpServletRequest; /** - * Gets the client's IP address regardless of whether the server is behind a proxy/reverse proxy server or a load balancer. - * + * Gets the client's IP address regardless of whether + * the server is behind a proxy/reverse proxy server or a load balancer. */ -public final class IpRetriever - { - - - /** - * Retrieves the client's IP address. - * Handles the cases like whether the server is behind a proxy/reverse proxy server or a load balancer - * - * @param request {@link HttpServletRequest} instance - * @return client's IP address - */ +public final class IpRetriever { + + /** + * Retrieves the client's IP address. + * Handles the cases like whether the server is behind a proxy/reverse proxy server or a load balancer + * + * @param request {@link HttpServletRequest} instance + * @return client's IP address + */ public static String retrieveIP(HttpServletRequest request) { - if(request != null){ - String ipAddress = request.getHeader("X-FORWARDED-FOR"); + if (request != null) { + String ipAddress = request.getHeader("X-FORWARDED-FOR"); - if (ipAddress != null && !ipAddress.isEmpty()) { - return removeUnwantedData(ipAddress); - } - else{ - ipAddress = request.getRemoteAddr(); - return ipAddress; - } + if (ipAddress != null && !ipAddress.isEmpty()) { + return removeUnwantedData(ipAddress); + } else { + ipAddress = request.getRemoteAddr(); + return ipAddress; + } } else return null; } - /** - * If the server is behind a reverse proxy, the header value will also contain the IP's from load balancer and reverse proxy - * This method gets rid of them. - * - * @param ipAddress IP address value from the header - * @return IP address of the client - */ - private static String removeUnwantedData(String ipAddress){ + /** + * If the server is behind a reverse proxy, the header value will also contain the IP's from load balancer and reverse proxy + * This method gets rid of them. + * + * @param ipAddress IP address value from the header + * @return IP address of the client + */ + private static String removeUnwantedData(String ipAddress) { return ipAddress.contains(",") ? ipAddress.split(",")[0] : ipAddress; - } + } + + private IpRetriever() { + } } |