コード例 #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;
  }
コード例 #2
0
ファイル: GeoLookupUtil.java プロジェクト: SIDN/entrada
  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();
  }