maxmind / GeoIP2-java

Java API for GeoIP2 webservice client and database reader
https://maxmind.github.io/GeoIP2-java/
Apache License 2.0
782 stars 205 forks source link

PROBLEM, GeoIP2 with Wowza Streaming Engine :( #82

Closed MythodeaLoL closed 7 years ago

MythodeaLoL commented 7 years ago

Hello, I can not integrate GeoIP2 with Wowza, what could be happening? The GeoIP version (1) worked perfectly.

Wowza Code:

import com.maxmind.geoip2.*;
import com.maxmind.geoip2.exception.GeoIp2Exception;
import com.maxmind.geoip2.model.CityResponse;
import com.maxmind.geoip2.record.City;
import com.maxmind.geoip2.record.Country;
import com.maxmind.geoip2.record.Location;
import com.maxmind.geoip2.record.Postal;
import com.maxmind.geoip2.record.Subdivision;
import com.maxmind.db.*;

    public static final String DATABASE_CITY_PATH = "C:/wowza/GeoIP2-City.mmdb";

    public void onAppStart(IApplicationInstance appInstance) {
        appInstance.setStreamNameAliasProvider(this);
        this.applicationInstance = appInstance;
        this.vHostName = appInstance.getVHost();

        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance(); 
            // A File object pointing to your GeoLite2 database
               File dbFile = new File(DATABASE_CITY_PATH);
               getLogger().info("DATABASE_CITY_PATH: "+DATABASE_CITY_PATH);
               // This creates the DatabaseReader object,
               // which should be reused across lookups.

               DatabaseReader reader = new DatabaseReader.Builder(dbFile).build();

               // A IP Address
               InetAddress ipAddress = InetAddress.getByName("128.101.101.101");

               // Get City info
               CityResponse response = reader.city(ipAddress);

               // Country Info
               Country country = response.getCountry();
               System.out.println("Country IsoCode: "+ country.getIsoCode()); // 'US'
               System.out.println("Country Name: "+ country.getName()); // 'United States'
               System.out.println(country.getNames().get("zh-CN")); //

               Subdivision subdivision = response.getMostSpecificSubdivision();
               System.out.println("Subdivision Name: " +subdivision.getName()); // 'Minnesota'
               System.out.println("Subdivision IsoCode: "+subdivision.getIsoCode()); // 'MN'

               // City Info.
               City city = response.getCity();
               System.out.println("City Name: "+ city.getName()); // 'Minneapolis'

               // Postal info
               Postal postal = response.getPostal();
               System.out.println(postal.getCode()); // '55455'

               // Geo Location info.
               Location location = response.getLocation();

               // Latitude
               System.out.println("Latitude: "+ location.getLatitude()); // 44.9733

               // Longitude
               System.out.println("Longitude: "+ location.getLongitude()); // -93.2323

        } catch (Exception e) { 
            getLogger().error("Error loading plugins: "+e.toString());
        }
    }

Here is a link with more explanations. http://pt.stackoverflow.com/q/180286/8984 Because the old version works, but the new one, GeoIP2 did not work @oschwald ?

oschwald commented 7 years ago

It is hard to say what is going on. GeoIP2 and related modules do not show up in the stack trace that you posted. You might have better luck contacting Wowza.

MythodeaLoL commented 7 years ago

The responses of the wowza team can take a long time if they respond. I think I'll have to choose to use php. Thanks anyway.