This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 9897be1adbdc CAMEL-27200: camel-geocoder - use the language option,
and trim the latitude and longitude of a reverse lookup (#30433)
9897be1adbdc is described below
commit 9897be1adbdc76b3c4d2ffbdc8216abd80592139
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Nov 19 18:55:20 2026 +0100
CAMEL-27200: camel-geocoder - use the language option, and trim the
latitude and longitude of a reverse lookup (#30433)
The language option was never used. Nominatim now gets it as the
accept-language parameter, and Google as the language parameter of the
geocode and reverse geocode requests. Nominatim no longer sends the
longitude with a leading space when the latlng value has a space after
the comma, as the latlng header set by the producer has.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../apache/camel/catalog/components/geocoder.json | 2 +-
components/camel-geocoder/pom.xml | 5 +
.../apache/camel/component/geocoder/geocoder.json | 2 +-
.../camel/component/geocoder/GeoCoderEndpoint.java | 7 +-
.../component/geocoder/GeoCoderGoogleProducer.java | 16 ++-
.../geocoder/GeoCoderNominatimProducer.java | 15 ++-
.../geocoder/GeoCoderGoogleLanguageTest.java | 116 +++++++++++++++++++++
.../geocoder/GeoCoderNominatimLanguageTest.java | 95 +++++++++++++++++
.../geocoder/GeoCoderNominatimTestSupport.java | 13 ++-
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 8 ++
.../dsl/GeoCoderEndpointBuilderFactory.java | 5 +-
11 files changed, 273 insertions(+), 11 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/geocoder.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/geocoder.json
index 16e6babb55f6..986baee7d375 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/geocoder.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/geocoder.json
@@ -49,7 +49,7 @@
"address": { "index": 0, "kind": "path", "displayName": "Address",
"group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "The geo address which should be prefixed with
address:" },
"latlng": { "index": 1, "kind": "path", "displayName": "Latlng", "group":
"producer", "label": "", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The geo latitude and longitude which should be prefixed with
latlng:" },
"headersOnly": { "index": 2, "kind": "parameter", "displayName": "Headers
Only", "group": "producer", "label": "", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "description": "Whether to only enrich the
Exchange with headers, and leave the body as-is." },
- "language": { "index": 3, "kind": "parameter", "displayName": "Language",
"group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "en", "description": "The language to use." },
+ "language": { "index": 3, "kind": "parameter", "displayName": "Language",
"group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "en", "description": "The language of the
answer (such as the address, the country and the city), as a language code such
as en, de or fr. It is sent as the accept-language parameter to Nominatim and
as the language parameter to Google." },
"serverUrl": { "index": 4, "kind": "parameter", "displayName": "Server
URL", "group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "URL to the geocoder server. Mandatory for
Nominatim server." },
"type": { "index": 5, "kind": "parameter", "displayName": "GeoCoding
Type", "group": "producer", "label": "", "required": false, "type": "enum",
"javaType": "org.apache.camel.component.geocoder.GeoCoderType", "enum": [
"NOMINATIM", "GOOGLE" ], "deprecated": false, "autowired": false, "secret":
false, "description": "Type of GeoCoding server. Supported Nominatim and
Google." },
"lazyStartProducer": { "index": 6, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produc [...]
diff --git a/components/camel-geocoder/pom.xml
b/components/camel-geocoder/pom.xml
index 8203169de631..09f269d09519 100644
--- a/components/camel-geocoder/pom.xml
+++ b/components/camel-geocoder/pom.xml
@@ -72,6 +72,11 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git
a/components/camel-geocoder/src/generated/resources/META-INF/org/apache/camel/component/geocoder/geocoder.json
b/components/camel-geocoder/src/generated/resources/META-INF/org/apache/camel/component/geocoder/geocoder.json
index 16e6babb55f6..986baee7d375 100644
---
a/components/camel-geocoder/src/generated/resources/META-INF/org/apache/camel/component/geocoder/geocoder.json
+++
b/components/camel-geocoder/src/generated/resources/META-INF/org/apache/camel/component/geocoder/geocoder.json
@@ -49,7 +49,7 @@
"address": { "index": 0, "kind": "path", "displayName": "Address",
"group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "The geo address which should be prefixed with
address:" },
"latlng": { "index": 1, "kind": "path", "displayName": "Latlng", "group":
"producer", "label": "", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The geo latitude and longitude which should be prefixed with
latlng:" },
"headersOnly": { "index": 2, "kind": "parameter", "displayName": "Headers
Only", "group": "producer", "label": "", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "description": "Whether to only enrich the
Exchange with headers, and leave the body as-is." },
- "language": { "index": 3, "kind": "parameter", "displayName": "Language",
"group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "en", "description": "The language to use." },
+ "language": { "index": 3, "kind": "parameter", "displayName": "Language",
"group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "en", "description": "The language of the
answer (such as the address, the country and the city), as a language code such
as en, de or fr. It is sent as the accept-language parameter to Nominatim and
as the language parameter to Google." },
"serverUrl": { "index": 4, "kind": "parameter", "displayName": "Server
URL", "group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "URL to the geocoder server. Mandatory for
Nominatim server." },
"type": { "index": 5, "kind": "parameter", "displayName": "GeoCoding
Type", "group": "producer", "label": "", "required": false, "type": "enum",
"javaType": "org.apache.camel.component.geocoder.GeoCoderType", "enum": [
"NOMINATIM", "GOOGLE" ], "deprecated": false, "autowired": false, "secret":
false, "description": "Type of GeoCoding server. Supported Nominatim and
Google." },
"lazyStartProducer": { "index": 6, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produc [...]
diff --git
a/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java
b/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java
index c4f13de0717e..98ee4ff793a5 100644
---
a/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java
+++
b/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderEndpoint.java
@@ -59,7 +59,10 @@ public class GeoCoderEndpoint extends DefaultEndpoint
implements EndpointService
private String address;
@UriPath
private String latlng;
- @UriParam(defaultValue = "en")
+ @UriParam(defaultValue = "en",
+ description = "The language of the answer (such as the address,
the country and the city), as a language code"
+ + " such as en, de or fr. It is sent as the
accept-language parameter to Nominatim and as the language"
+ + " parameter to Google.")
private String language = "en";
@UriParam(label = "security", security = "secret", description = "Client
ID to access Google GeoCoding server.")
private String clientId;
@@ -128,7 +131,7 @@ public class GeoCoderEndpoint extends DefaultEndpoint
implements EndpointService
}
/**
- * The language to use.
+ * The language of the answer, as a language code such as en, de or fr.
*/
public void setLanguage(String language) {
this.language = language;
diff --git
a/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderGoogleProducer.java
b/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderGoogleProducer.java
index cb002490b13e..6727d9f50180 100644
---
a/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderGoogleProducer.java
+++
b/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderGoogleProducer.java
@@ -21,6 +21,7 @@ import java.util.Locale;
import com.google.maps.GeoApiContext;
import com.google.maps.GeocodingApi;
+import com.google.maps.GeocodingApiRequest;
import com.google.maps.GeolocationApi;
import com.google.maps.errors.InvalidRequestException;
import com.google.maps.errors.OverDailyLimitException;
@@ -35,6 +36,7 @@ import com.google.maps.model.GeolocationResult;
import com.google.maps.model.LatLng;
import org.apache.camel.Exchange;
import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -73,7 +75,7 @@ public class GeoCoderGoogleProducer extends DefaultProducer {
LatLng latLng = new LatLng(Double.parseDouble(lat),
Double.parseDouble(lng));
LOG.debug("Geocode for lat/lng {}", latlng);
- GeocodingResult[] results =
GeocodingApi.reverseGeocode(context, latLng).await();
+ GeocodingResult[] results =
withLanguage(GeocodingApi.reverseGeocode(context, latLng)).await();
LOG.debug("Geocode response {}", Arrays.toString(results));
@@ -89,7 +91,7 @@ public class GeoCoderGoogleProducer extends DefaultProducer {
} else {
LOG.debug("Geocode for address {}", address);
- GeocodingResult[] results = GeocodingApi.geocode(context,
address).await();
+ GeocodingResult[] results =
withLanguage(GeocodingApi.geocode(context, address)).await();
LOG.debug("Geocode response {}", Arrays.toString(results));
if (results != null) {
@@ -129,7 +131,7 @@ public class GeoCoderGoogleProducer extends DefaultProducer
{
// address - reverse geocode
LOG.debug("Geocode - reverse geocode for location {}", resLatlng);
- GeocodingResult[] results = GeocodingApi.reverseGeocode(context,
result.location).await();
+ GeocodingResult[] results =
withLanguage(GeocodingApi.reverseGeocode(context, result.location)).await();
LOG.debug("Geocode response {}", Arrays.toString(results));
@@ -138,6 +140,14 @@ public class GeoCoderGoogleProducer extends
DefaultProducer {
}
}
+ private GeocodingApiRequest withLanguage(GeocodingApiRequest request) {
+ String language = endpoint.getLanguage();
+ if (ObjectHelper.isNotEmpty(language)) {
+ request.language(language);
+ }
+ return request;
+ }
+
private void setLatLngToExchangeHeader(LatLng location, Exchange exchange)
{
double resLat = location.lat;
double resLng = location.lng;
diff --git
a/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderNominatimProducer.java
b/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderNominatimProducer.java
index af3932601e5d..3cd8eb48de33 100644
---
a/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderNominatimProducer.java
+++
b/components/camel-geocoder/src/main/java/org/apache/camel/component/geocoder/GeoCoderNominatimProducer.java
@@ -28,6 +28,7 @@ import com.jayway.jsonpath.Option;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.StringHelper;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
@@ -73,8 +74,9 @@ public class GeoCoderNominatimProducer extends
DefaultProducer {
String geocoded = null;
if (latlng != null) {
- String lat = StringHelper.before(latlng, ",");
- String lng = StringHelper.after(latlng, ",");
+ // the latlng header this producer sets has a space after the comma
+ String lat = StringHelper.before(latlng, ",").trim();
+ String lng = StringHelper.after(latlng, ",").trim();
LOG.debug("Geocode for lat/lng {}", latlng);
geocoded = query(lat, lng);
@@ -94,6 +96,7 @@ public class GeoCoderNominatimProducer extends
DefaultProducer {
params.put("format", "jsonv2");
params.put("lat", dlat);
params.put("lon", dlon);
+ addLanguage(params);
return queryForString("reverse", params);
}
@@ -104,10 +107,18 @@ public class GeoCoderNominatimProducer extends
DefaultProducer {
params.put("addressdetails", "1");
params.put("q", address);
params.put("limit", "1");
+ addLanguage(params);
return queryForString("search", params);
}
+ private void addLanguage(Map<String, String> params) {
+ String language = endpoint.getLanguage();
+ if (ObjectHelper.isNotEmpty(language)) {
+ params.put("accept-language", language);
+ }
+ }
+
private String queryForString(String operation, Map<String, String>
params) throws IOException {
String url = endpoint.getServerUrl();
if (!url.endsWith("/")) {
diff --git
a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderGoogleLanguageTest.java
b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderGoogleLanguageTest.java
new file mode 100644
index 000000000000..0bbc93289a64
--- /dev/null
+++
b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderGoogleLanguageTest.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.geocoder;
+
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import com.google.maps.GeoApiContext;
+import com.sun.net.httpserver.HttpServer;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Runs the Google producer against a local HTTP server, to check the language
parameter of the requests.
+ */
+public class GeoCoderGoogleLanguageTest extends CamelTestSupport {
+
+ private final Map<String, String> queries = new ConcurrentHashMap<>();
+ private HttpServer server;
+
+ @Override
+ protected void setupResources() throws Exception {
+ server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
+ server.createContext("/", exchange -> {
+ String query = exchange.getRequestURI().getRawQuery();
+ queries.put(exchange.getRequestURI().getPath(), query != null ?
query : "");
+ byte[] bytes =
"{\"status\":\"OK\",\"results\":[]}".getBytes(StandardCharsets.UTF_8);
+ exchange.getResponseHeaders().add("Content-Type",
"application/json; charset=utf-8");
+ exchange.sendResponseHeaders(200, bytes.length);
+ try (OutputStream body = exchange.getResponseBody()) {
+ body.write(bytes);
+ }
+ });
+ server.start();
+ }
+
+ @Override
+ protected void cleanupResources() throws Exception {
+ if (server != null) {
+ server.stop(0);
+ }
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext camelContext = super.createCamelContext();
+ GeoApiContext geoApiContext = new GeoApiContext.Builder()
+ .apiKey("AIzaTest")
+ .baseUrlOverride("http://127.0.0.1:" +
server.getAddress().getPort())
+ .disableRetries()
+ .build();
+ camelContext.getComponent("geocoder",
GeoCoderComponent.class).setGeoApiContext(geoApiContext);
+ return camelContext;
+ }
+
+ @Test
+ public void testGeocodeSendsLanguage() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.expectedHeaderReceived(GeoCoderConstants.STATUS,
GeocoderStatus.ZERO_RESULTS);
+
+ template.sendBody("direct:address", "Test");
+
+ MockEndpoint.assertIsSatisfied(context);
+
assertThat(queries.get("/maps/api/geocode/json")).contains("address=Paris").contains("language=fr");
+ }
+
+ @Test
+ public void testReverseGeocodeSendsLanguage() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.expectedHeaderReceived(GeoCoderConstants.STATUS,
GeocoderStatus.ZERO_RESULTS);
+
+ template.sendBody("direct:latlng", "Test");
+
+ MockEndpoint.assertIsSatisfied(context);
+
assertThat(queries.get("/maps/api/geocode/json")).contains("latlng=").contains("language=de");
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:address")
+ .to("geocoder:address:Paris?language=fr")
+ .to("mock:result");
+
+ from("direct:latlng")
+
.to("geocoder:latlng:48.85661400,2.35222190?language=de")
+ .to("mock:result");
+ }
+ };
+ }
+}
diff --git
a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderNominatimLanguageTest.java
b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderNominatimLanguageTest.java
new file mode 100644
index 000000000000..141ab26b3844
--- /dev/null
+++
b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderNominatimLanguageTest.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.geocoder;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class GeoCoderNominatimLanguageTest extends
GeoCoderNominatimTestSupport {
+
+ @Test
+ public void testSearchSendsLanguage() throws Exception {
+ answerFromResource("search", "search-calle-marie-curie.json");
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.expectedHeaderReceived(GeoCoderConstants.STATUS,
GeocoderStatus.OK);
+
+ template.sendBody("direct:french", "Test");
+
+ MockEndpoint.assertIsSatisfied(context);
+ assertThat(lastQuery("search")).contains("accept-language=fr");
+ }
+
+ @Test
+ public void testDefaultLanguageIsEnglish() throws Exception {
+ answerFromResource("search", "search-calle-marie-curie.json");
+
+ template.sendBody("direct:default", "Test");
+
+ assertThat(lastQuery("search")).contains("accept-language=en");
+ }
+
+ @Test
+ public void testEmptyLanguageIsNotSent() throws Exception {
+ answerFromResource("search", "search-calle-marie-curie.json");
+
+ template.sendBody("direct:noLanguage", "Test");
+
+
assertThat(lastQuery("search")).isNotNull().doesNotContain("accept-language");
+ }
+
+ @Test
+ public void testReverseSendsLanguageAndTrimmedLatLng() throws Exception {
+ answerFromResource("reverse", "reverse-sevilla.json");
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.expectedHeaderReceived(GeoCoderConstants.STATUS,
GeocoderStatus.OK);
+
+ // the latlng header as the producer sets it, with a space after the
comma
+ template.sendBodyAndHeader("direct:french", "Test",
GeoCoderConstants.LATLNG, "37.38605170, -5.99255350");
+
+ MockEndpoint.assertIsSatisfied(context);
+ assertThat(lastQuery("reverse"))
+ .contains("accept-language=fr")
+ .contains("lat=37.38605170")
+ .contains("lon=-5.99255350")
+ .doesNotContain("lon=+")
+ .doesNotContain("lon=%20");
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:french")
+
.to("geocoder:address:Paris?type=NOMINATIM&language=fr&serverUrl=RAW(" +
serverUrl() + ")")
+ .to("mock:result");
+
+ from("direct:default")
+
.to("geocoder:address:Paris?type=NOMINATIM&serverUrl=RAW(" + serverUrl() + ")");
+
+ from("direct:noLanguage")
+
.to("geocoder:address:Paris?type=NOMINATIM&language=&serverUrl=RAW(" +
serverUrl() + ")");
+ }
+ };
+ }
+}
diff --git
a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderNominatimTestSupport.java
b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderNominatimTestSupport.java
index ed1d5c8c9235..32f876cc26a8 100644
---
a/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderNominatimTestSupport.java
+++
b/components/camel-geocoder/src/test/java/org/apache/camel/component/geocoder/GeoCoderNominatimTestSupport.java
@@ -34,13 +34,17 @@ import org.apache.camel.test.junit6.CamelTestSupport;
public abstract class GeoCoderNominatimTestSupport extends CamelTestSupport {
private final Map<String, String> answers = new ConcurrentHashMap<>();
+ private final Map<String, String> queries = new ConcurrentHashMap<>();
private HttpServer server;
@Override
protected void setupResources() throws Exception {
server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
server.createContext("/", exchange -> {
- String answer = answers.get(exchange.getRequestURI().getPath());
+ String path = exchange.getRequestURI().getPath();
+ String query = exchange.getRequestURI().getRawQuery();
+ queries.put(path, query != null ? query : "");
+ String answer = answers.get(path);
byte[] bytes = answer != null ?
answer.getBytes(StandardCharsets.UTF_8) : new byte[0];
exchange.getResponseHeaders().add("Content-Type",
"application/json; charset=utf-8");
exchange.sendResponseHeaders(answer != null ? 200 : 404,
bytes.length > 0 ? bytes.length : -1);
@@ -72,6 +76,13 @@ public abstract class GeoCoderNominatimTestSupport extends
CamelTestSupport {
answers.put("/" + operation, json);
}
+ /**
+ * The raw query string of the last request of the given operation (search
or reverse), or null when there was none.
+ */
+ protected String lastQuery(String operation) {
+ return queries.get("/" + operation);
+ }
+
/**
* Sets the answer of the given operation (search or reverse) from a
recorded response in
* src/test/resources/nominatim.
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index d39fdc1afed9..030202611019 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -10424,3 +10424,11 @@ component or the endpoint is used as it is.
The new `tlsTrustCertsFilePath` option sets a PEM file with the certificates
of the certificate authorities to trust,
for a broker whose certificate is not signed by an authority that the JVM
trusts.
+
+=== camel-geocoder - the language option is used
+
+The `language` option (default `en`) is now sent with each request: as the
`accept-language` parameter to Nominatim
+and as the `language` parameter to Google. Before, the option was ignored, so
Nominatim answered in the local language
+of the place (for example `Deutschland` for Germany) and Google in its own
default language. The address, country,
+city and region headers and the body now come in English unless `language` is
set to another language code. Set
+`language` to an empty value to get the previous answers.
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/GeoCoderEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/GeoCoderEndpointBuilderFactory.java
index 3a12f0c34ffe..619a17154d1a 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/GeoCoderEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/GeoCoderEndpointBuilderFactory.java
@@ -78,7 +78,10 @@ public interface GeoCoderEndpointBuilderFactory {
return this;
}
/**
- * The language to use.
+ * The language of the answer (such as the address, the country and the
+ * city), as a language code such as en, de or fr. It is sent as the
+ * accept-language parameter to Nominatim and as the language parameter
+ * to Google.
*
* The option is a: <code>java.lang.String</code> type.
*