GeoIp Article PR (#789)

* GEO Ip Article first commit.

* Changes in controller and flow as per review by Kevin.

* Removed this file from spring-mvc-java as I had worked on spring-mvc-xml
and this was commited by mistake.

* Some fix in service usage as i was initializing service, intializing the
db in the each requests.

* Changes for Integration Testing Config. Renaming the test file for the
same purpose.

* Removed integration profile.
This commit is contained in:
Parth Joshi
2016-11-19 03:32:52 +05:30
committed by KevinGilmore
parent a46208fc4f
commit 224a3a8a42
6 changed files with 234 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
package com.baeldung.spring.service;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import com.baeldung.spring.form.GeoIP;
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.exception.GeoIp2Exception;
import com.maxmind.geoip2.model.CityResponse;
public class RawDBDemoGeoIPLocationService{
private DatabaseReader dbReader;
public RawDBDemoGeoIPLocationService() throws IOException {
File database = new File("C:\\Users\\Parth Joshi\\Desktop\\GeoLite2-City.mmdb\\GeoLite2-City.mmdb");
dbReader = new DatabaseReader.Builder(database).build();
}
public GeoIP getLocation(String ip) throws IOException, GeoIp2Exception {
InetAddress ipAddress = InetAddress.getByName(ip);
CityResponse response = dbReader.city(ipAddress);
String cityName = response.getCity().getName();
String latitude = response.getLocation().getLatitude().toString();
String longitude = response.getLocation().getLongitude().toString();
return new GeoIP(ip, cityName, latitude, longitude);
}
}