Claus Ibsen created CAMEL-27200:
-----------------------------------
Summary: camel-geocoder - language option is never used; reverse
lookup lon not trimmed
Key: CAMEL-27200
URL: https://issues.apache.org/jira/browse/CAMEL-27200
Project: Camel
Issue Type: Bug
Components: camel-geocoder
Reporter: Claus Ibsen
h3. 1. The language option is ignored
The endpoint has a {{language}} option (default {{en}}), but
{{GeoCoderEndpoint.getLanguage()}} has no caller. Neither producer passes it on:
* {{GeoCoderNominatimProducer}} builds the {{search}} and {{reverse}} requests
itself ({{format}}, {{addressdetails}}, {{q}}, {{limit}} / {{lat}}, {{lon}})
and sends neither an {{accept-language}} query parameter nor an
{{Accept-Language}} header. An {{Accept-Language}} header on the message is not
used either.
* {{GeoCoderGoogleProducer}} calls {{GeocodingApi.geocode(...)}} /
{{reverseGeocode(...)}} without {{.language(...)}}.
Reproduce with a recording HTTP server as Nominatim:
{noformat}
geocoder:address:Paris?type=NOMINATIM&serverUrl=RAW(http://localhost:8080)&language=fr
{noformat}
The request is {{GET /search?q=Paris&addressdetails=1&format=jsonv2&limit=1}},
with no language. The answer (display_name, country, city...) is in the server
default language.
h3. 2. Reverse lookup sends the longitude with a leading space
{{GeoCoderNominatimProducer.process}} splits the {{latlng}} value (header
{{CamelGeoCoderLatlng}} or the endpoint option) with
{{StringHelper.before/after(latlng, ",")}} and does not trim. The producer
itself sets that header as {{"lat, lng"}} (with a space) in
{{setLatLngToExchangeHeader}}, so feeding the result of one lookup into a
reverse lookup sends {{lon=+-5.99255350}} (a space before the value). Nominatim
happens to accept it today, but the value should be trimmed. The Google
producer is not affected ({{Double.parseDouble}} trims).
h3. Where
*
{{components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderNominatimProducer.java}}:
{{query(String address)}}, {{query(String lat, String lon)}}, {{process}}
*
{{components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderGoogleProducer.java}}:
{{process}}
h3. Suggested fix
* Nominatim: add {{params.put("accept-language", endpoint.getLanguage())}} to
both queries (when not empty).
* Google: pass {{.language(endpoint.getLanguage())}} on the geocode and reverse
geocode requests.
* Trim {{lat}} and {{lng}} after splitting.
Found while adding options to the {{nominatim-geocode-action}} Kamelet: it
cannot offer a language option because of (1).
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)