Package com.maxmind.geoip2.model

Examples of com.maxmind.geoip2.model.AbstractCityResponse


        } catch (HttpResponseException e) {
            int status = e.getStatusCode();
            if ((status >= 400) && (status < 500)) {
                WebServiceClient.handle4xxStatus(e.getContent(), status, uri);
            } else if ((status >= 500) && (status < 600)) {
                throw new HttpException("Received a server error (" + status
                        + ") for " + uri, status, uri.toURL());
            }

            throw new HttpException("Received a very surprising HTTP status ("
                    + status + ") for " + uri, status, uri.toURL());
        }
    }
View Full Code Here


    private static void handle4xxStatus(String body, int status, GenericUrl uri)
            throws GeoIp2Exception, HttpException {

        if (body == null) {
            throw new HttpException("Received a " + status + " error for "
                    + uri + " with no body", status, uri.toURL());
        }

        Map<String, String> content;
        try {
            ObjectMapper mapper = new ObjectMapper();
            content = mapper.readValue(body,
                    new TypeReference<HashMap<String, String>>() {
                    });
            handleErrorWithJsonBody(content, body, status, uri);
        } catch (HttpException e) {
            throw e;
        } catch (IOException e) {
            throw new HttpException("Received a " + status + " error for "
                    + uri + " but it did not include the expected JSON body: "
                    + body, status, uri.toURL());
        }
    }
View Full Code Here

            HttpException {
        String error = content.get("error");
        String code = content.get("code");

        if (error == null || code == null) {
            throw new HttpException(
                    "Response contains JSON but it does not specify code or error keys: "
                            + body, status, uri.toURL());
        }

        if (code.equals("IP_ADDRESS_NOT_FOUND")
View Full Code Here

        } else if (code.equals("OUT_OF_QUERIES")) {
            throw new OutOfQueriesException(error);
        }

        // These should be fairly rare
        throw new InvalidRequestException(error, code, uri.toURL());
    }
View Full Code Here

        } else if (code.equals("AUTHORIZATION_INVALID")
                || code.equals("LICENSE_KEY_REQUIRED")
                || code.equals("USER_ID_REQUIRED")) {
            throw new AuthenticationException(error);
        } else if (code.equals("OUT_OF_QUERIES")) {
            throw new OutOfQueriesException(error);
        }

        // These should be fairly rare
        throw new InvalidRequestException(error, code, uri.toURL());
    }
View Full Code Here

        try {
            final InetAddress address = InetAddress.getByName(customerRemoteAddr);
           
            final DatabaseReader databaseReader = new DatabaseReader.Builder(getCityDataBase()).build();

            final CityResponse cityResponse = databaseReader.city(address);
            if(cityResponse != null){
                return cityResponse.getCity();
               
            }
        } catch (AddressNotFoundException e) {
            logger.warn("Geoloc city, can't find this address:" + customerRemoteAddr);
        } catch (FileNotFoundException e) {
View Full Code Here

    public void testNames() throws IOException, GeoIp2Exception {
        WebServiceClient client = new WebServiceClient.Builder(42,
                "abcdef123456").testTransport(this.transport)
                .locales(Arrays.asList("zh-CN", "ru")).build();

        CityResponse city = client.city(InetAddress.getByName("1.1.1.2"));
        assertEquals("country.getContinent().getName() does not return 北美洲",
                "北美洲", city.getContinent().getName());
        assertEquals("country.getCountry().getName() does not return 美国", "美国",
                city.getCountry().getName());
        assertEquals("toString() returns getName()", city.getCountry()
                .getName(), city.getCountry().getName());
    }
View Full Code Here

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

        CityResponse city = client.city(InetAddress.getByName("1.1.1.2"));
        assertEquals(
                "country.getCountry().getName() does not return объединяет государства",
                "объединяет государства", city.getCountry().getName());

    }
View Full Code Here

    @Test
    public void testFallback() throws IOException, GeoIp2Exception {
        WebServiceClient client = new WebServiceClient.Builder(42,
                "abcdef123456").testTransport(this.transport)
                .locales(Arrays.asList("pt", "en", "zh-CN")).build();
        CityResponse city = client.city(InetAddress.getByName("1.1.1.2"));
        assertEquals("en is returned when pt is missing", city.getContinent()
                .getName(), "North America");

    }
View Full Code Here

    @Test
    public void noFallback() throws IOException, GeoIp2Exception {
        WebServiceClient client = new WebServiceClient.Builder(42,
                "abcdef123456").testTransport(this.transport)
                .locales(Arrays.asList("pt", "es", "af")).build();
        CityResponse city = client.city(InetAddress.getByName("1.1.1.2"));

        assertNull("null is returned when locale is not available", city
                .getContinent().getName());
    }
View Full Code Here

TOP

Related Classes of com.maxmind.geoip2.model.AbstractCityResponse

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.