davsclaus opened a new pull request, #29000:
URL: https://github.com/apache/camel/pull/29000

   Fixes [CAMEL-26170](https://issues.apache.org/jira/browse/CAMEL-26170).
   
   ### 1. Nominatim with no results failed with IllegalArgumentException
   
   **What was wrong:** `GeoCoderNominatimProducer.extractResult` set 
`CamelGeoCoderStatus` to `OK` for any non-empty answer. For an address that 
Nominatim does not find, it answers `[]`. The brackets were cut off and 
`JsonPath.parse("")` threw `IllegalArgumentException: json string can not be 
null or empty`, so the exchange failed.
   
   Same method, same kind of bug: for a latitude and longitude with no place 
(for example at sea), Nominatim's reverse answers `{"error":"Unable to 
geocode"}` (see `format_json.py` in Nominatim). The producer set `OK` and no 
other headers. An error answer such as `{"error":{"code":400,"message":"..."}}` 
also got `OK`.
   
   **What changed:**
   - The answer is trimmed, the array brackets are cut off, and an empty result 
is `ZERO_RESULTS`.
   - An `error` text (`Unable to geocode`) is `ZERO_RESULTS`. An `error` object 
is `ERROR` (the existing, so far unused, `GeocoderStatus.ERROR`).
   - The body is still the raw answer of Nominatim (for example `[]`), as 
before.
   
   **Tests:** `GeoCoderNominatimZeroResultsTest` covers `[]`, `Unable to 
geocode` and an error object. All three failed before the fix (1 error with the 
`IllegalArgumentException`, 2 failures with status `OK`).
   
   ### 2. Two unit tests called the real nominatim.openstreetmap.org
   
   **What changed:** `GeoCoderNominatimTest` and `GeoCoderNominatimAddressTest` 
now run against a local HTTP server (JDK `HttpServer`, in the new 
`GeoCoderNominatimTestSupport`) that answers responses recorded once from 
nominatim.openstreetmap.org (`src/test/resources/nominatim/`). They keep their 
old assertions and also check the status, and the lat/lng or postal code.
   
   ### Docs and generated files
   - `geocoder-component.adoc`: says when the status is `ZERO_RESULTS` or 
`ERROR` with Nominatim.
   - `@BodyTypes` description of the endpoint: the Nominatim array is empty for 
no results. `geocoder.json` and the catalog copies of the JSON and doc are 
regenerated.
   - Upgrade guide 4.24: new `camel-geocoder` entry, since the status of a 
reverse lookup with no place, and of an error answer, changes from `OK`.
   
   ### Not changed
   - `queryForString` does not look at the HTTP status code; the body of any 
answer goes to `extractResult`. A non-JSON error page (for example an HTML 5xx 
from a proxy) is still parsed as JSON. Left as is to keep this PR focused.
   
   Module build: `mvn clean install -Psourcecheck` in 
`components/camel-geocoder`: 9 tests, 0 failures, 4 skipped (the Google tests 
need `CAMEL_GEOCODER_APIKEY`).
   
   _Claude Code on behalf of Claus Ibsen (davsclaus)_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to