Thomas Diesler created CAMEL-15276:
--------------------------------------

             Summary: GeoLocationProvider may not get initialized properly
                 Key: CAMEL-15276
                 URL: https://issues.apache.org/jira/browse/CAMEL-15276
             Project: Camel
          Issue Type: Bug
          Components: camel-weather
    Affects Versions: 3.4.0
            Reporter: Thomas Diesler


WeatherConfiguration is constructed like this

{code}
    public WeatherConfiguration(WeatherComponent component) {
        this.component = notNull(component, "component");
        weatherQuery = new WeatherQuery(this);
        FreeGeoIpGeoLocationProvider geoLocationProvider = new 
FreeGeoIpGeoLocationProvider(component, geolocationAccessKey);
        weatherQuery.setGeoLocationProvider(geoLocationProvider);
    }
{code}

at which point the geolocationAccessKey may be unknown.

There is perhaps also some confusion here ...

{code}
    @Override
    protected Endpoint createEndpoint(String uri, String remaining, Map<String, 
Object> parameters) throws Exception {
        WeatherConfiguration configuration = new WeatherConfiguration(this);
        configuration.setGeolocationAccessKey(geolocationAccessKey);
        configuration.setGeolocationRequestHostIP(geolocationRequestHostIP);

        WeatherEndpoint endpoint = new WeatherEndpoint(uri, this, 
configuration);
        setProperties(endpoint, parameters);

        if (httpClient == null) {
            httpClient = HttpClients.createDefault();
        }

        return endpoint;
    }
{code}

which seems to set the geolocationAccessKey on the configuration from what is 
explicitly defined on the component.

A geolocationAccessKey defined on the endpoint Uri does not find its way to the 
GeoLocationProvider which is then used by WeatherQuery, which then leads to ...

{code}
            camelctx.addRoutes(new RouteBuilder() {
                @Override
                public void configure() throws Exception {
                    
from("weather:foo?geolocationRequestHostIP=redhat.com&geolocationAccessKey=" + 
GEOLOCATION_ACCESS_KEY + "&appid=" + OPENWEATHER_APP_ID)
                    .to("mock:result");
                }
            });
{code}

{code}
Caused by: java.lang.IllegalStateException: The geolocation service requires a 
mandatory geolocationAccessKey
        at 
org.apache.camel.component.weather.geolocation.FreeGeoIpGeoLocationProvider.getCurrentGeoLocation(FreeGeoIpGeoLocationProvider.java:43)
        at 
org.apache.camel.component.weather.WeatherQuery.getCurrentGeoLocation(WeatherQuery.java:150)
        at 
org.apache.camel.component.weather.WeatherQuery.getQuery(WeatherQuery.java:58)
        at 
org.apache.camel.component.weather.WeatherQuery.getQuery(WeatherQuery.java:38)
        at 
org.apache.camel.component.weather.WeatherConfiguration.getQuery(WeatherConfiguration.java:212)
        at 
org.apache.camel.component.weather.WeatherEndpoint.createConsumer(WeatherEndpoint.java:43)
{code}

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to