Example #1
0
  public Country geolocAndGetCountry(final String customerRemoteAddr) throws Exception {
    if (StringUtils.isNotEmpty(customerRemoteAddr)) {
      if (!unknownValueList.contains(customerRemoteAddr)) {
        try {
          final InetAddress address = InetAddress.getByName(customerRemoteAddr);

          final DatabaseReader databaseReader =
              new DatabaseReader.Builder(getCountryDataBase()).build();
          final CountryResponse countryResponse = databaseReader.country(address);
          if (countryResponse != null) {
            return countryResponse.getCountry();
          }
        } catch (AddressNotFoundException e) {
          logger.warn("Geoloc country, can't find this address: '" + customerRemoteAddr + "'");
        } catch (FileNotFoundException e) {
          logger.error("Geoloc country, can't find database MaxMind", e);
        } catch (Exception e) {
          logger.error(
              "Geoloc country, exception to find country with this address: '"
                  + customerRemoteAddr
                  + "'",
              e);
        }
      } else {
        logger.debug(
            "Geoloc country, can't find address (private navigation): '"
                + customerRemoteAddr
                + "'");
      }
    } else {
      logger.debug("Geoloc country, can't find address, value is empty.");
    }
    return null;
  }
Example #2
0
  public City geolocAndGetCity(final String customerRemoteAddr) throws Exception {
    try {
      final InetAddress address = InetAddress.getByName(customerRemoteAddr);

      final DatabaseReader databaseReader = new DatabaseReader.Builder(getCityDataBase()).build();

      final CityResponse cityResponse = databaseReader.city(address);
      if (cityResponse != null) {
        return cityResponse.getCity();
      }
    } catch (AddressNotFoundException e) {
      logger.warn("Geoloc city, can't find this address:" + customerRemoteAddr);
    } catch (FileNotFoundException e) {
      logger.error("Geoloc city, can't find database MaxMind", e);
    } catch (Exception e) {
      logger.error("Geoloc city, can't find this city with this address:" + customerRemoteAddr, e);
    }
    return null;
  }
Example #3
0
  public String lookupCountry(InetAddress addr) {
    CountryResponse response = null;

    try {
      response = reader.country(addr);
    } catch (Exception e) {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("No country found for: " + addr);
      }
      return null;
    }
    return response.getCountry().getIsoCode();
  }
Example #4
0
  public String lookupCity(String ip) {
    CityResponse response = null;

    try {
      response = reader.city(InetAddress.getByName(ip));
    } catch (Exception e) {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("No city found for: " + ip);
      }
      return null;
    }

    return response.getCity().getName();
  }
  public static LocationInfo getLocationInfo(String ipAddr) {

    CityResponse rsp;

    try {
      rsp = dbReader.city(InetAddress.getByName(ipAddr));

      return new LocationInfo(
          rsp.getCity().getName(),
          rsp.getCountry().getName(),
          rsp.getLocation().getLatitude(),
          rsp.getLocation().getLongitude());
    } catch (UnknownHostException e) {
      logger.error(e.getMessage());
    } catch (IOException e) {
      logger.error(e.getMessage());
    } catch (GeoIp2Exception e) {
      logger.error(e.getMessage());
    }

    return null;
  }