NIFI-549: Fixed NPE

This commit is contained in:
Mark Payne 2015-04-27 12:01:36 -04:00
parent 0759660897
commit ba96e43a8e
1 changed files with 11 additions and 2 deletions

View File

@ -189,8 +189,17 @@ public class GeoEnrichIP extends AbstractProcessor {
final Map<String, String> attrs = new HashMap<>(); final Map<String, String> attrs = new HashMap<>();
attrs.put(new StringBuilder(ipAttributeName).append(".geo.lookup.micros").toString(), String.valueOf(stopWatch.getDuration(TimeUnit.MICROSECONDS))); attrs.put(new StringBuilder(ipAttributeName).append(".geo.lookup.micros").toString(), String.valueOf(stopWatch.getDuration(TimeUnit.MICROSECONDS)));
attrs.put(new StringBuilder(ipAttributeName).append(".geo.city").toString(), response.getCity().getName()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.city").toString(), response.getCity().getName());
attrs.put(new StringBuilder(ipAttributeName).append(".geo.latitude").toString(), response.getLocation().getLatitude().toString());
attrs.put(new StringBuilder(ipAttributeName).append(".geo.longitude").toString(), response.getLocation().getLongitude().toString()); final Double latitude = response.getLocation().getLatitude();
if ( latitude != null ) {
attrs.put(new StringBuilder(ipAttributeName).append(".geo.latitude").toString(), latitude.toString());
}
final Double longitude = response.getLocation().getLongitude();
if ( longitude != null ) {
attrs.put(new StringBuilder(ipAttributeName).append(".geo.longitude").toString(), longitude.toString());
}
int i = 0; int i = 0;
for (final Subdivision subd : response.getSubdivisions()) { for (final Subdivision subd : response.getSubdivisions()) {
attrs.put(new StringBuilder(ipAttributeName).append(".geo.subdivision.").append(i).toString(), subd.getName()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.subdivision.").append(i).toString(), subd.getName());