Search in sources :

Example 1 with Geocoder

use of com.google.code.geocoder.Geocoder in project camel by apache.

the class GeoCoderEndpoint method createGeocoder.

Geocoder createGeocoder() throws InvalidKeyException {
    HttpConnectionManager connectionManager = this.httpConnectionManager;
    if (connectionManager == null) {
        connectionManager = new MultiThreadedHttpConnectionManager();
    }
    HttpClient httpClient = new HttpClient(connectionManager);
    if (proxyHost != null && proxyPort != null) {
        httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
    }
    // validate that if proxy auth username is given then the proxy auth method is also provided
    if (proxyAuthUsername != null && proxyAuthMethod == null) {
        throw new IllegalArgumentException("Option proxyAuthMethod must be provided to use proxy authentication");
    }
    CompositeHttpConfigurer configurer = new CompositeHttpConfigurer();
    if (proxyAuthMethod != null) {
        configureProxyAuth(configurer, proxyAuthMethod, proxyAuthUsername, proxyAuthPassword, proxyAuthDomain, proxyAuthHost);
    }
    if (httpClientConfigurer != null) {
        configurer.addConfigurer(httpClientConfigurer);
    }
    configurer.configureHttpClient(httpClient);
    Geocoder geocoder;
    if (clientId != null) {
        geocoder = new AdvancedGeoCoder(httpClient, clientId, clientKey);
    } else {
        geocoder = new AdvancedGeoCoder(httpClient);
    }
    return geocoder;
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) AdvancedGeoCoder(com.google.code.geocoder.AdvancedGeoCoder) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) HttpConnectionManager(org.apache.commons.httpclient.HttpConnectionManager) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) CompositeHttpConfigurer(org.apache.camel.component.geocoder.http.CompositeHttpConfigurer) Geocoder(com.google.code.geocoder.Geocoder)

Example 2 with Geocoder

use of com.google.code.geocoder.Geocoder in project camel by apache.

the class GeoCoderProxyTest method testGeoCoder.

@Test
public void testGeoCoder() throws Exception {
    GeoCoderEndpoint endpoint = context.getEndpoint("geocoder:address:current?headersOnly=true&proxyHost=localhost&proxyPort=3128&proxyAuthMethod=Basic&proxyAuthUsername=proxy&proxyAuthPassword=proxy", GeoCoderEndpoint.class);
    Geocoder geocoder = endpoint.createGeocoder();
    GeocoderRequest req = new GeocoderRequest();
    req.setLocation(new LatLng("45.4643", "9.1895"));
    GeocodeResponse res = geocoder.geocode(req);
    log.info("Response {} ", res);
}
Also used : GeocodeResponse(com.google.code.geocoder.model.GeocodeResponse) LatLng(com.google.code.geocoder.model.LatLng) Geocoder(com.google.code.geocoder.Geocoder) GeocoderRequest(com.google.code.geocoder.model.GeocoderRequest) Test(org.junit.Test)

Aggregations

Geocoder (com.google.code.geocoder.Geocoder)2 AdvancedGeoCoder (com.google.code.geocoder.AdvancedGeoCoder)1 GeocodeResponse (com.google.code.geocoder.model.GeocodeResponse)1 GeocoderRequest (com.google.code.geocoder.model.GeocoderRequest)1 LatLng (com.google.code.geocoder.model.LatLng)1 CompositeHttpConfigurer (org.apache.camel.component.geocoder.http.CompositeHttpConfigurer)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 HttpConnectionManager (org.apache.commons.httpclient.HttpConnectionManager)1 MultiThreadedHttpConnectionManager (org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)1 Test (org.junit.Test)1