Package com.maxmind.geoip2

Examples of com.maxmind.geoip2.HostTest


    @Test
    public void noLocale() throws IOException, GeoIp2Exception {
        WebServiceClient client = new WebServiceClient.Builder(42,
                "abcdef123456").testTransport(this.transport).build();
        CityResponse city = client.city(InetAddress.getByName("1.1.1.2"));
        assertEquals("en is returned when no locales are specified", city
                .getContinent().getName(), "North America");

    }
View Full Code Here


    public void testMissing() throws IOException, GeoIp2Exception {
        WebServiceClient client = new WebServiceClient.Builder(42,
                "abcdef123456").testTransport(this.transport)
                .locales(Arrays.asList("en")).build();

        CityResponse city = client.city(InetAddress.getByName("1.1.1.2"));
        assertNotNull(city.getCity());
        assertNull("null is returned when names object is missing", city
                .getCity().getName());
    }
View Full Code Here

    public Country geolocAndGetCountry(final String customerRemoteAddr) throws Exception {
        try {
            final InetAddress address = InetAddress.getByName(customerRemoteAddr);
           
            final DatabaseReader databaseReader = new DatabaseReader.Builder(getCountryDataBase()).build();
            final CountryResponse countryResponse = databaseReader.country(address);
            if(countryResponse != null){
                return countryResponse.getCountry();
            }
        } catch (AddressNotFoundException e) {
            logger.warn("Geoloc country, can't find this address:" + customerRemoteAddr);
        } catch (FileNotFoundException e) {
            logger.error("Geoloc country, can't find database MaxMind", e);
View Full Code Here

    private final WebServiceClient client = new WebServiceClient.Builder(42,
            "abcdef123456").testTransport(this.transport).build();

    @Test
    public void testDefaults() throws IOException, GeoIp2Exception {
        InsightsResponse insights = this.client.insights(InetAddress
                .getByName("1.2.3.13"));

        assertTrue(insights.toString().startsWith("Insights"));

        City city = insights.getCity();
        assertNotNull(city);
        assertNull(city.getConfidence());

        Continent continent = insights.getContinent();
        assertNotNull(continent);
        assertNull(continent.getCode());

        Country country = insights.getCountry();
        assertNotNull(country);

        Location location = insights.getLocation();
        assertNotNull(location);
        assertNull(location.getAccuracyRadius());
        assertNull(location.getLatitude());
        assertNull(location.getLongitude());
        assertNull(location.getMetroCode());
        assertNull(location.getTimeZone());
        assertEquals("Location []", location.toString());

        MaxMind maxmind = insights.getMaxMind();
        assertNotNull(maxmind);
        assertNull(maxmind.getQueriesRemaining());

        assertNotNull(insights.getPostal());

        Country registeredCountry = insights.getRegisteredCountry();
        assertNotNull(registeredCountry);

        RepresentedCountry representedCountry = insights
                .getRepresentedCountry();
        assertNotNull(representedCountry);
        assertNull(representedCountry.getType());

        List<Subdivision> subdivisions = insights.getSubdivisions();
        assertNotNull(subdivisions);
        assertTrue(subdivisions.isEmpty());

        Subdivision subdiv = insights.getMostSpecificSubdivision();
        assertNotNull(subdiv);
        assertNull(subdiv.getIsoCode());
        assertNull(subdiv.getConfidence());

        Traits traits = insights.getTraits();
        assertNotNull(traits);
        assertNull(traits.getAutonomousSystemNumber());
        assertNull(traits.getAutonomousSystemOrganization());
        assertNull(traits.getDomain());
        assertNull(traits.getIpAddress());
View Full Code Here

        HttpTransport transport = new TestTransport();
        WebServiceClient client = new WebServiceClient.Builder(42,
                "abcdef123456").host("blah.com").testTransport(transport)
                .build();

        InsightsResponse insights = client.insights(InetAddress
                .getByName("128.101.101.101"));
        assertEquals(insights.getTraits().getIpAddress(), "128.101.101.101");
    }
View Full Code Here

    Matcher ipMatch = ipPattern.matcher(user);
    boolean anonymous = ipMatch.matches();
    if(anonymous) {
      try {
        final InetAddress ip = InetAddress.getByName(ipMatch.group());
        final Omni lookup = geoLookup.omni(ip);

        dimensions.put("continent", lookup.getContinent().getName());
        dimensions.put("country", lookup.getCountry().getName());
        dimensions.put("region", lookup.getMostSpecificSubdivision().getName());
        dimensions.put("city", lookup.getCity().getName());
      } catch(UnknownHostException e) {
        log.error(e, "invalid ip [%s]", ipMatch.group());
      } catch(IOException e) {
        log.error(e, "error looking up geo ip");
      } catch(GeoIp2Exception e) {
View Full Code Here

        model.addAttribute(ModelConstants.GEOLOC_REMOTE_ADDRESS, remoteAddress);
       
    final Country country = geolocService.geolocAndGetCountry(remoteAddress);
        model.addAttribute(ModelConstants.GEOLOC_COUNTRY, country);

        final City city = geolocService.geolocAndGetCity(remoteAddress);
        model.addAttribute(ModelConstants.GEOLOC_CITY, city);

        overrideDefaultSeoPageTitleAndMainContentTitle(request, modelAndView, FoUrls.PREHOME.getKey());

        return modelAndView;
View Full Code Here

            final Country country = geolocAndGetCountry(remoteAddress);
            geolocData.setRemoteAddress(remoteAddress);
            if(country != null
                    && StringUtils.isNotEmpty(country.getIsoCode())){
                geolocData.setCountry(country);
                final City city = geolocAndGetCity(remoteAddress);
                geolocData.setCity(city);
            }
        }
        return geolocData;
    }
View Full Code Here

   
    /**
     *
     */
    public String geolocAndGetCityName(final String customerRemoteAddr) throws Exception {
        final City city = geolocAndGetCity(customerRemoteAddr);
        return city.getName();
    }
View Full Code Here

     *
     */
    protected EngineEcoSession handleGeolocData(final HttpServletRequest request, EngineEcoSession engineEcoSession, final GeolocData geolocData) throws Exception {
        if (geolocData != null) {
            // FIND LATITUDE/LONGITUDE BY CITY/COUNTRY
            City city = geolocData.getCity();
            Country country = geolocData.getCountry();
            GeolocCity geolocCity = geolocService.getGeolocCityByCityAndCountry(city.getName(), country.getName());
            if (geolocCity != null) {
                geolocData.setLatitude(geolocCity.getLatitude());
                geolocData.setLongitude(geolocCity.getLongitude());
            } else {
                // LATITUDE/LONGITUDE DOESN'T EXIST - WE USE GOOGLE GEOLOC TO FOUND IT
                geolocCity = geolocService.geolocByCityAndCountry(city.getName(), country.getName());
                if (geolocCity != null) {
                    geolocData.setLatitude(geolocCity.getLatitude());
                    geolocData.setLongitude(geolocCity.getLongitude());
                }
            }
View Full Code Here

TOP

Related Classes of com.maxmind.geoip2.HostTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.