use of com.maxmind.geoip2.DatabaseReader in project druid by druid-io.
the class WikipediaIrcDecoder method openGeoIpDb.
private DatabaseReader openGeoIpDb(File geoDb) {
try {
DatabaseReader reader = new DatabaseReader(geoDb);
log.info("Using geo ip database at [%s].", geoDb);
return reader;
} catch (IOException e) {
throw new RuntimeException("Could not open geo db at [" + geoDb.getAbsolutePath() + "].", e);
}
}
use of com.maxmind.geoip2.DatabaseReader in project OpenAM by OpenRock.
the class Adaptive method checkGeoLocation.
protected int checkGeoLocation() {
int retVal = 0;
String countryCode;
if (debug.messageEnabled()) {
debug.message("{}.checkGeoLocation: GeoLocation database location = {}", ADAPTIVE, geoLocationDatabase);
}
DatabaseReader db = getLookupService(geoLocationDatabase);
if (db == null) {
debug.error("{}.checkGeoLocation: GeoLocation database lookup returns null", ADAPTIVE);
return geoLocationScore;
}
if (geoLocationValues == null) {
debug.error("{}.checkGeoLocation: The property '{}' is null", ADAPTIVE, GEO_LOCATION_VALUES);
return geoLocationScore;
}
try {
countryCode = getCountryCode(db, clientIP);
} catch (IOException e) {
if (debug.warningEnabled()) {
debug.warning("{}.checkGeoLocation: #getCountryCode :: An IO error happened", ADAPTIVE, e);
}
return geoLocationScore;
} catch (GeoIp2Exception e) {
if (debug.warningEnabled()) {
debug.warning("{}.checkGeoLocation: #getCountryCode :: An error happened when looking up the IP", ADAPTIVE, e);
}
return geoLocationScore;
}
if (debug.messageEnabled()) {
debug.message("{}.checkGeoLocation: {} returns {}", ADAPTIVE, clientIP, countryCode);
}
StringTokenizer st = new StringTokenizer(geoLocationValues, "|");
while (st.hasMoreTokens()) {
if (countryCode.equalsIgnoreCase(st.nextToken())) {
if (debug.messageEnabled()) {
debug.message("{}.checkGeoLocation: Found Country Code : {}", ADAPTIVE, countryCode);
}
retVal = geoLocationScore;
break;
}
}
if (!geoLocationInvert) {
retVal = geoLocationScore - retVal;
}
return retVal;
}
use of com.maxmind.geoip2.DatabaseReader in project GNS by MobilityFirst.
the class GeoIPUtils method getLocation_City.
/**
* This method is used for test, whether a static method can be called by active code
* @param ip
* @param dbReader
* @return a GeoIP response
*/
public static CityResponse getLocation_City(String ip, DatabaseReader dbReader) {
try {
InetAddress ipAddress = InetAddress.getByName(ip);
CityResponse response = dbReader.city(ipAddress);
return response;
} catch (IOException | GeoIp2Exception e) {
return null;
}
}
use of com.maxmind.geoip2.DatabaseReader in project PretendYoureXyzzy by ajanata.
the class GeoIP method makeReader.
private synchronized DatabaseReader makeReader() {
LOG.info("Attempting to create GeoIP database reader");
initialized = true;
if (reader != null) {
return reader;
}
final String dbPath = propertiesProvider.get().getProperty("geoip.db");
if (StringUtils.isNotBlank(dbPath)) {
final File db = new File(dbPath);
try {
reader = new DatabaseReader.Builder(db).withCache(new CHMCache()).build();
} catch (final IOException e) {
LOG.error("Unable to create database reader", e);
reader = null;
}
} else {
reader = null;
}
return reader;
}
use of com.maxmind.geoip2.DatabaseReader in project nutch by apache.
the class GeoIPDocumentCreator method createDocFromCityDb.
public static NutchDocument createDocFromCityDb(String serverIp, NutchDocument doc, DatabaseReader reader) throws UnknownHostException, IOException, GeoIp2Exception {
addIfNotNull(doc, "ip", serverIp);
CityResponse response = reader.city(InetAddress.getByName(serverIp));
City city = response.getCity();
// 'Minneapolis'
addIfNotNull(doc, "cityName", city.getName());
// 50
addIfNotNull(doc, "cityConfidence", city.getConfidence());
addIfNotNull(doc, "cityGeoNameId", city.getGeoNameId());
Continent continent = response.getContinent();
addIfNotNull(doc, "continentCode", continent.getCode());
addIfNotNull(doc, "continentGeoNameId", continent.getGeoNameId());
addIfNotNull(doc, "continentName", continent.getName());
Country country = response.getCountry();
// 'US'
addIfNotNull(doc, "countryIsoCode", country.getIsoCode());
// 'United States'
addIfNotNull(doc, "countryName", country.getName());
// 99
addIfNotNull(doc, "countryConfidence", country.getConfidence());
addIfNotNull(doc, "countryGeoName", country.getGeoNameId());
Location location = response.getLocation();
// 44.9733,
addIfNotNull(doc, "latLon", location.getLatitude() + "," + location.getLongitude());
// -93.2323
// 3
addIfNotNull(doc, "accRadius", location.getAccuracyRadius());
// 'America/Chicago'
addIfNotNull(doc, "timeZone", location.getTimeZone());
addIfNotNull(doc, "metroCode", location.getMetroCode());
Postal postal = response.getPostal();
// '55455'
addIfNotNull(doc, "postalCode", postal.getCode());
// 40
addIfNotNull(doc, "postalConfidence", postal.getConfidence());
RepresentedCountry rCountry = response.getRepresentedCountry();
addIfNotNull(doc, "countryType", rCountry.getType());
Subdivision subdivision = response.getMostSpecificSubdivision();
// 'Minnesota'
addIfNotNull(doc, "subDivName", subdivision.getName());
// 'MN'
addIfNotNull(doc, "subDivIdoCode", subdivision.getIsoCode());
// 90
addIfNotNull(doc, "subDivConfidence", subdivision.getConfidence());
addIfNotNull(doc, "subDivGeoNameId", subdivision.getGeoNameId());
return doc;
}
Aggregations