Home

Awesome

Dropwizard MaxMind Bundle Travis build status

This bundle adds MaxMind GeoIP2 support for dropwizard. This bundle compiles only on Java 8.

Dependencies

Usage

The bundle adds MaxMind GeoIP2 support for which makes it easier for geo ip information that is required by location aware services. The bundle works with the free light version of MaxMind GeoIP2 database as well.

Build instructions

Maven Dependency

Use the following repository:

<repository>
    <id>clojars</id>
    <name>Clojars repository</name>
    <url>https://clojars.org/repo</url>
</repository>

Use the following maven dependency:

<dependency>
    <groupId>io.dropwizard</groupId>
    <artifactId>dropwizard-maxmind</artifactId>
    <version>1.3.7</version>
</dependency>

Using MaxMind bundle

Configuration

maxmind:
  databaseFilePath: /path/to/maxmind/database/file.mmdb
  remoteIpHeader: "CLIENT-IP" #default is X-FORWARDED-FOR (when used behind a loadbalancer)
  cacheTTL: 120 #In seconds, Default is 300 seconds
  cacheMaxEntries: 102400 #Default is 10240
  enterprise: true #default: false. Enable maxmind enterprise database mode
  type: anonymous #If it is not a enterprise database; set the type of database that is being used. Supported: country, city, anonymous
  maxMindContext: false #If you need MaxMindInfo injection into resource methods; set it to true  

Bootstrap

    @Override
    public void initialize(final Bootstrap...) {
        bootstrap.addBundle(new MaxMindBundle() {
            
            public MaxMindConfig getMaxMindConfig(T configuration) {
                ...
            }
        });
    }

Headers stamped

MaxMindContext in Resource

Use MaxMindInfo which is much more convenient if you want easier access to all the stamped headers in a simple object model

@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
@Path("/")
public class MaxMindResource {

    @GET
    public Response maxMindInfoApi(@MaxMindContext final MaxMindInfo maxMindInfo) {
      // Do work and return something
        return Response.status(OK).entity(maxMindInfo).build();
    }
} 

LICENSE

Copyright 2016 Phaneesh Nagaraja phaneesh.n@gmail.com.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.