Ing. Luca Stucchi
Ing. Luca Stucchi

Reputation: 3277

MaxMind GeoIP2 (version 2.7.0) not usable in GAE

I am trying to use MaxMind GeoIP2 on Google App Engine. Locally it works, but when I deploy it on GAE I get an error because of a restricted class

java.lang.NoClassDefFoundError: java.nio.MappedByteBuffer is a restricted class. Please see the Google App Engine developer's guide for more details.
    at java.nio.channels.FileChannel.map(FileChannel.java)
    at com.maxmind.db.BufferHolder.<init>(BufferHolder.java:31)
    at com.maxmind.db.Reader.<init>(Reader.java:116)
    at com.maxmind.geoip2.DatabaseReader.<init>(DatabaseReader.java:39)
    at com.maxmind.geoip2.DatabaseReader.<init>(DatabaseReader.java:27)
    at com.maxmind.geoip2.DatabaseReader$Builder.build(DatabaseReader.java:133)

Is there any "trick", like using a particular version of GeoIP2, that will not use this error ? I use version 2.7.0 via gradle

compile group: "com.maxmind.geoip2", name: "geoip2", version: "2.7.0"

Anybody tried with legacy version of GeoIP ? Any luck there ? My only aim is to understand how to use this library, if possible, or to find an alternative one that offers the same capability (obtaining ISO code of the country from the IP)

Upvotes: 0

Views: 301

Answers (3)

Mark Doyle
Mark Doyle

Reputation: 4874

GAE supplies this in a request header to your app:

String visitorCountry = request.getHeader("X-AppEngine-Country");

Note that it may be empty on the dev server, but populated when deployed.

Upvotes: 1

Greg Oschwald
Greg Oschwald

Reputation: 1735

You should be able to use the memory mode in GeoIP2 on GAE instead:

DatabaseReader reader = new DatabaseReader.Builder(dbFile)
         .fileMode(Reader.FileMode.MEMORY).build();

Upvotes: 2

Ing. Luca Stucchi
Ing. Luca Stucchi

Reputation: 3277

If GeoIP2 can't be deployed on GAE, I found out that GeoIP Legacy can, and in particular I set in gradle:

compile group: "com.maxmind.geoip", name: "geoip-api", version: "1.3.1"

With the associated GeoIP.dat file that can be downloaded here

This version runs on GAE without any problem

Upvotes: 0

Related Questions