use of com.google.code.geocoder.AdvancedGeoCoder in project opennms by OpenNMS.
the class GoogleGeocoderService method ensureInitialized.
public void ensureInitialized() throws GeocoderException {
if (m_geocoder == null) {
final HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
if (notEmpty(m_clientId) && notEmpty(m_clientKey)) {
try {
LOG.info("Initializing Google Geocoder using Client ID and Key.");
m_geocoder = new AdvancedGeoCoder(httpClient, m_clientId, m_clientKey);
} catch (final InvalidKeyException e) {
throw new GeocoderException("Unable to initialize Google Geocoder.", e);
}
}
if (m_geocoder == null) {
LOG.info("Initializing Google Geocoder using default configuration.");
m_geocoder = new AdvancedGeoCoder(httpClient);
}
/* Configure proxying, if necessary... */
final String httpProxyHost = System.getProperty("http.proxyHost");
final Integer httpProxyPort = Integer.getInteger("http.proxyPort");
if (httpProxyHost != null && httpProxyPort != null) {
LOG.info("Proxy configuration found, using {}:{} as HTTP proxy.", httpProxyHost, httpProxyPort);
httpClient.getHostConfiguration().setProxy(httpProxyHost, httpProxyPort);
} else {
LOG.info("No proxy configuration found.");
}
/* Limit retries... */
httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(1, true));
httpClient.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, timeout);
LOG.info("Google Geocoder initialized.");
}
}
use of com.google.code.geocoder.AdvancedGeoCoder 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;
}
Aggregations