Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-15276

GeoLocationProvider may not get initialized properly

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.4.0
    • Fix Version/s: 3.5.0
    • Component/s: camel-weather
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      WeatherConfiguration is constructed like this

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

      at which point the geolocationAccessKey may be unknown.

      There is perhaps also some confusion here ...

          @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;
          }
      

      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 ...

                  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");
                      }
                  });
      
      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)
      

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                acosentino Andrea Cosentino
                Reporter:
                tdiesler Thomas Diesler
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: