本文整理汇总了Java中com.maxmind.geoip2.exception.AddressNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java AddressNotFoundException类的具体用法?Java AddressNotFoundException怎么用?Java AddressNotFoundException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AddressNotFoundException类属于com.maxmind.geoip2.exception包,在下文中一共展示了AddressNotFoundException类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUnkownIpRequired
import com.maxmind.geoip2.exception.AddressNotFoundException; //导入依赖的package包/类
@Test(expected = AddressNotFoundException.class)
public void testUnkownIpRequired() throws Throwable {
GeoIpOperation op = setup(Arrays.asList(GeoProperty.LOCATION), true);
DummpyEvent devent = new DummpyEvent();
devent.setField("ip_address", "10.0.0.1");
InternalEvent ievent = new InternalEvent("", null, 0);
ievent.setEventObj(devent);
try {
op.perform(ievent);
} catch (OperationException e) {
throw e.getCause();
}
}
示例2: get
import com.maxmind.geoip2.exception.AddressNotFoundException; //导入依赖的package包/类
/**
* @param ipAddress IPv4 or IPv6 address to lookup.
* @return A <T> object with the data for the IP address
* @throws IOException if there is an error opening or reading from the file.
* @throws AddressNotFoundException if the IP address is not in our database
*/
private <T> T get(InetAddress ipAddress, Class<T> cls,
String type) throws IOException, AddressNotFoundException {
String databaseType = this.getMetadata().getDatabaseType();
if (!databaseType.contains(type)) {
String caller = Thread.currentThread().getStackTrace()[2]
.getMethodName();
throw new UnsupportedOperationException(
"Invalid attempt to open a " + databaseType
+ " database using the " + caller + " method");
}
ObjectNode node = jsonNodeToObjectNode(reader.get(ipAddress));
// We throw the same exception as the web service when an IP is not in
// the database
if (node == null) {
throw new AddressNotFoundException("The address "
+ ipAddress.getHostAddress() + " is not in the database.");
}
InjectableValues inject = new JsonInjector(locales, ipAddress.getHostAddress());
return this.om.reader(inject).treeToValue(node, cls);
}
示例3: getCountry
import com.maxmind.geoip2.exception.AddressNotFoundException; //导入依赖的package包/类
public Optional<Country> getCountry(InetAddress address) {
if (geoReader == null) {
return Optional.empty();
}
try {
return Optional.of(geoReader.country(address).getCountry());
} catch (AddressNotFoundException notFoundEx) {
//ignore
} catch (IOException | GeoIp2Exception ex) {
logger.error("Failed to lookup country of {}", address, ex);
}
return Optional.empty();
}
示例4: unknownAddress
import com.maxmind.geoip2.exception.AddressNotFoundException; //导入依赖的package包/类
private void unknownAddress(DatabaseReader reader) throws IOException,
GeoIp2Exception {
this.exception.expect(AddressNotFoundException.class);
this.exception
.expectMessage(containsString("The address 10.10.10.10 is not in the database."));
try {
reader.city(InetAddress.getByName("10.10.10.10"));
} finally {
reader.close();
}
}