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 635490292c1b CAMEL-27220: camel-google-sheets - the x-struct 
transformer writes to the configured spreadsheet, and the access token is sent 
only in the Authorization header (#30364)
635490292c1b is described below

commit 635490292c1bb622a4b38bb4d152542df2243f0e
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Nov 19 13:22:49 2026 +0100

    CAMEL-27220: camel-google-sheets - the x-struct transformer writes to the 
configured spreadsheet, and the access token is sent only in the Authorization 
header (#30364)
    
    The google-sheets:application-x-struct transformer no longer takes the
    spreadsheet from a spreadsheetId field of the JSON rows: the spreadsheet is
    the one of the CamelGoogleSheets.spreadsheetId header, or else the
    spreadsheetId option of the endpoint. Without the header, the transformer
    no longer sets the spreadsheet id headers to an empty value.
    
    The producer and the consumer no longer set the credential options on the
    request, so the accessToken option is no longer sent as the access_token
    query parameter; the OAuth credential of the client sends it in the
    Authorization header.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../google/sheets/GoogleSheetsConsumer.java        |   9 +-
 .../google/sheets/GoogleSheetsEndpoint.java        |  34 ++++++
 .../google/sheets/GoogleSheetsProducer.java        |   9 +-
 .../GoogleSheetsJsonStructDataTypeTransformer.java |  22 ++--
 .../sheets/GoogleSheetsRequestCredentialTest.java  | 116 +++++++++++++++++++++
 ...gleSheetsJsonStructDataTypeTransformerTest.java |  51 ++++++++-
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |  22 ++++
 7 files changed, 234 insertions(+), 29 deletions(-)

diff --git 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsConsumer.java
 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsConsumer.java
index f175f3406398..0faebbfca783 100644
--- 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsConsumer.java
+++ 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsConsumer.java
@@ -17,14 +17,11 @@
 package org.apache.camel.component.google.sheets;
 
 import java.util.Map;
-import java.util.Map.Entry;
 
 import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.google.sheets.internal.GoogleSheetsApiName;
-import org.apache.camel.spi.BeanIntrospection;
-import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiConsumer;
 
 /**
@@ -40,11 +37,7 @@ public class GoogleSheetsConsumer extends 
AbstractApiConsumer<GoogleSheetsApiNam
     protected Object doInvokeMethod(Map<String, Object> properties) throws 
RuntimeCamelException {
         AbstractGoogleClientRequest<?> request = (AbstractGoogleClientRequest) 
super.doInvokeMethod(properties);
         try {
-            BeanIntrospection beanIntrospection
-                    = 
PluginHelper.getBeanIntrospection(getEndpoint().getCamelContext());
-            for (Entry<String, Object> p : properties.entrySet()) {
-                beanIntrospection.setProperty(getEndpoint().getCamelContext(), 
request, p.getKey(), p.getValue());
-            }
+            ((GoogleSheetsEndpoint) getEndpoint()).configureRequest(request, 
properties);
             return request.execute();
         } catch (Exception e) {
             throw new RuntimeCamelException(e);
diff --git 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsEndpoint.java
 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsEndpoint.java
index 14d77cde6dbf..0dd7b670ae84 100644
--- 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsEndpoint.java
+++ 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsEndpoint.java
@@ -16,10 +16,15 @@
  */
 package org.apache.camel.component.google.sheets;
 
+import java.util.Collections;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
 import com.google.api.services.sheets.v4.Sheets;
 import org.apache.camel.Category;
 import org.apache.camel.Consumer;
@@ -29,12 +34,14 @@ import 
org.apache.camel.component.google.sheets.internal.GoogleSheetsApiCollecti
 import org.apache.camel.component.google.sheets.internal.GoogleSheetsApiName;
 import org.apache.camel.component.google.sheets.internal.GoogleSheetsConstants;
 import 
org.apache.camel.component.google.sheets.internal.GoogleSheetsPropertiesHelper;
+import org.apache.camel.spi.BeanIntrospection;
 import org.apache.camel.spi.BodyType;
 import org.apache.camel.spi.BodyType.Carrier;
 import org.apache.camel.spi.BodyTypes;
 import org.apache.camel.spi.EndpointServiceLocation;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiEndpoint;
 import org.apache.camel.support.component.ApiMethod;
 import org.apache.camel.support.component.ApiMethodPropertiesHelper;
@@ -70,6 +77,20 @@ import org.apache.camel.util.ObjectHelper;
 public class GoogleSheetsEndpoint extends 
AbstractApiEndpoint<GoogleSheetsApiName, GoogleSheetsConfiguration>
         implements EndpointServiceLocation {
 
+    /**
+     * The options that make up the credential of the client. The client sends 
the credential in the Authorization
+     * header, so they are not set on the request, where accessToken would 
become the access_token query parameter. The
+     * names are matched ignoring case, as a header such as 
CamelGoogleSheets.AccessToken sets the same property.
+     */
+    private static final Set<String> CREDENTIAL_OPTIONS;
+
+    static {
+        Set<String> options = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+        options.addAll(
+                List.of("clientId", "clientSecret", "accessToken", 
"refreshToken", "serviceAccountKey", "delegate"));
+        CREDENTIAL_OPTIONS = Collections.unmodifiableSet(options);
+    }
+
     @UriParam
     private GoogleSheetsConfiguration configuration;
     private final Lock clientLock = new ReentrantLock();
@@ -144,6 +165,19 @@ public class GoogleSheetsEndpoint extends 
AbstractApiEndpoint<GoogleSheetsApiNam
         return answer;
     }
 
+    /**
+     * Sets the options and headers on the request of the method, such as the 
standard parameters of the Google API,
+     * except the options of the credential, which the client already sends in 
the Authorization header.
+     */
+    void configureRequest(AbstractGoogleClientRequest<?> request, Map<String, 
Object> properties) throws Exception {
+        BeanIntrospection beanIntrospection = 
PluginHelper.getBeanIntrospection(getCamelContext());
+        for (Map.Entry<String, Object> p : properties.entrySet()) {
+            if (!CREDENTIAL_OPTIONS.contains(p.getKey())) {
+                beanIntrospection.setProperty(getCamelContext(), request, 
p.getKey(), p.getValue());
+            }
+        }
+    }
+
     @Override
     public Object getApiProxy(ApiMethod method, Map<String, Object> args) {
         return apiProxy;
diff --git 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsProducer.java
 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsProducer.java
index 15ed352b7fa3..6398ebd68357 100644
--- 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsProducer.java
+++ 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsProducer.java
@@ -17,14 +17,11 @@
 package org.apache.camel.component.google.sheets;
 
 import java.util.Map;
-import java.util.Map.Entry;
 
 import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.google.sheets.internal.GoogleSheetsApiName;
 import 
org.apache.camel.component.google.sheets.internal.GoogleSheetsPropertiesHelper;
-import org.apache.camel.spi.BeanIntrospection;
-import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.component.AbstractApiProducer;
 import org.apache.camel.support.component.ApiMethod;
 
@@ -43,11 +40,7 @@ public class GoogleSheetsProducer extends 
AbstractApiProducer<GoogleSheetsApiNam
         AbstractGoogleClientRequest<?> request
                 = (AbstractGoogleClientRequest) super.doInvokeMethod(method, 
properties);
         try {
-            BeanIntrospection beanIntrospection
-                    = 
PluginHelper.getBeanIntrospection(getEndpoint().getCamelContext());
-            for (Entry<String, Object> p : properties.entrySet()) {
-                beanIntrospection.setProperty(getEndpoint().getCamelContext(), 
request, p.getKey(), p.getValue());
-            }
+            ((GoogleSheetsEndpoint) getEndpoint()).configureRequest(request, 
properties);
             return request.execute();
         } catch (Exception e) {
             throw new RuntimeCamelException(e);
diff --git 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/transform/GoogleSheetsJsonStructDataTypeTransformer.java
 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/transform/GoogleSheetsJsonStructDataTypeTransformer.java
index 12b039c984da..4e3da51940f9 100644
--- 
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/transform/GoogleSheetsJsonStructDataTypeTransformer.java
+++ 
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/transform/GoogleSheetsJsonStructDataTypeTransformer.java
@@ -53,7 +53,9 @@ import org.apache.camel.util.json.Jsoner;
  * result of a get values operation) the transformer will transform into 
generic Json struct. When generic Json struct
  * is given as a message body transformer will transform into a proper 
ValueRange object that is ready to be used in an
  * update/append values operation. The Implementation also supports 
splitResults setting where a set of values is split
- * into its individual items.
+ * into its individual items. The Json struct of a row or column read from a 
spreadsheet has the id of the spreadsheet
+ * in its spreadsheetId field; when Json struct is transformed into a 
ValueRange this field is ignored, and the
+ * spreadsheet to write to is the one of the CamelGoogleSheets.spreadsheetId 
header or of the endpoint.
  */
 @DataTypeTransformer(name = "google-sheets:application-x-struct",
                      description = "Transforms to/from JSon data and Google 
Sheets ValueRange object")
@@ -95,7 +97,9 @@ public class GoogleSheetsJsonStructDataTypeTransformer 
extends Transformer {
     }
 
     /**
-     * Constructs proper ValueRange object from given generic Json struct.
+     * Constructs proper ValueRange object from given generic Json struct. The 
spreadsheet is the one of the
+     * CamelGoogleSheets.spreadsheetId header, or else the one of the 
endpoint; a spreadsheetId field of a row is left
+     * out of the values.
      */
     private ValueRange transformToValueRangeModel(
             Message message, String spreadsheetId, String range, String 
majorDimension, String valueInputOption,
@@ -110,14 +114,10 @@ public class GoogleSheetsJsonStructDataTypeTransformer 
extends Transformer {
                 final ArrayList<String> properties = 
createCoordinateNameSpec(range, majorDimension, columnNames);
 
                 for (String json : jsonBeans) {
+                    // a spreadsheetId field, which the rows read by this 
transformer have, is not a value, and does not
+                    // choose the spreadsheet: that is the 
CamelGoogleSheets.spreadsheetId header or the endpoint option
                     Map<String, Object> dataShape = readJsonObject(json);
 
-                    if (dataShape.containsKey("spreadsheetId")) {
-                        spreadsheetId = 
Optional.ofNullable(dataShape.remove("spreadsheetId"))
-                                .map(Object::toString)
-                                .orElse(spreadsheetId);
-                    }
-
                     List<Object> rangeValues = new ArrayList<>();
                     properties
                             .stream()
@@ -131,8 +131,10 @@ public class GoogleSheetsJsonStructDataTypeTransformer 
extends Transformer {
             valueRange.setMajorDimension(majorDimension);
             valueRange.setValues(values);
 
-            message.setHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID, 
spreadsheetId);
-            message.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"spreadsheetId", spreadsheetId);
+            if (ObjectHelper.isNotEmpty(spreadsheetId)) {
+                message.setHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID, 
spreadsheetId);
+                message.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"spreadsheetId", spreadsheetId);
+            }
             message.setHeader(GoogleSheetsStreamConstants.RANGE, range);
             message.setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + "range", 
range);
             message.setHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION, 
majorDimension);
diff --git 
a/components/camel-google/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/GoogleSheetsRequestCredentialTest.java
 
b/components/camel-google/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/GoogleSheetsRequestCredentialTest.java
new file mode 100644
index 000000000000..ae6518173899
--- /dev/null
+++ 
b/components/camel-google/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/GoogleSheetsRequestCredentialTest.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.google.sheets;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import com.google.api.client.json.Json;
+import com.google.api.client.testing.http.MockHttpTransport;
+import com.google.api.client.testing.http.MockLowLevelHttpRequest;
+import com.google.api.client.testing.http.MockLowLevelHttpResponse;
+import com.google.api.services.sheets.v4.model.ValueRange;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+/**
+ * The client sends the OAuth access token in the Authorization header; the 
request URL does not carry it.
+ */
+class GoogleSheetsRequestCredentialTest {
+
+    private static final String OAUTH = 
"clientId=id&clientSecret=secret&accessToken=atoken";
+
+    private final RecordingTransport transport = new RecordingTransport();
+
+    @Test
+    void shouldSendTheAccessTokenOfTheProducerOnlyInTheAuthorizationHeader() 
throws Exception {
+        try (CamelContext context = createContext()) {
+            ValueRange body = context.createProducerTemplate().requestBody(
+                    "google-sheets://data/get?spreadsheetId=abc&range=A1:B1&" 
+ OAUTH, null, ValueRange.class);
+
+            assertEquals(List.of(List.of("a", "b")), body.getValues());
+            assertSentWithTheTokenInTheHeaderOnly(transport.requests.get(0));
+        }
+    }
+
+    @Test
+    void shouldNotSendAnAccessTokenHeaderOnTheRequestWhateverItsCase() throws 
Exception {
+        for (String header : List.of("CamelGoogleSheets.accessToken", 
"CamelGoogleSheets.AccessToken")) {
+            transport.requests.clear();
+            try (CamelContext context = createContext()) {
+                context.createProducerTemplate().requestBodyAndHeader(
+                        
"google-sheets://data/get?spreadsheetId=abc&range=A1:B1&" + OAUTH, null, 
header, "htoken");
+
+                String url = transport.requests.get(0).getUrl();
+                assertFalse(url.contains("access_token"), header + " -> " + 
url);
+                assertFalse(url.contains("htoken"), header + " -> " + url);
+            }
+        }
+    }
+
+    @Test
+    void shouldSendTheAccessTokenOfTheConsumerOnlyInTheAuthorizationHeader() 
throws Exception {
+        try (CamelContext context = createContext()) {
+            MockEndpoint mock = context.getEndpoint("mock:result", 
MockEndpoint.class);
+            mock.expectedMinimumMessageCount(1);
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    
from("google-sheets://data/get?spreadsheetId=abc&range=A1:B1&delay=100&" + 
OAUTH)
+                            .to("mock:result");
+                }
+            });
+
+            mock.assertIsSatisfied();
+            assertSentWithTheTokenInTheHeaderOnly(transport.requests.get(0));
+        }
+    }
+
+    private static void 
assertSentWithTheTokenInTheHeaderOnly(MockLowLevelHttpRequest request) {
+        assertFalse(request.getUrl().contains("access_token"), 
request.getUrl());
+        assertFalse(request.getUrl().contains("atoken"), request.getUrl());
+        assertEquals("Bearer atoken", 
request.getFirstHeaderValue("Authorization"));
+    }
+
+    private CamelContext createContext() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        context.getComponent("google-sheets", GoogleSheetsComponent.class)
+                .setClientFactory(new 
BatchGoogleSheetsClientFactory(transport));
+        context.start();
+        return context;
+    }
+
+    private static final class RecordingTransport extends MockHttpTransport {
+
+        private final List<MockLowLevelHttpRequest> requests = new 
CopyOnWriteArrayList<>();
+
+        @Override
+        public MockLowLevelHttpRequest buildRequest(String method, String url) 
{
+            MockLowLevelHttpRequest request = new MockLowLevelHttpRequest(url);
+            request.setResponse(new 
MockLowLevelHttpResponse().setContentType(Json.MEDIA_TYPE)
+                    
.setContent("{\"range\":\"Sheet1!A1:B1\",\"majorDimension\":\"ROWS\",\"values\":[[\"a\",\"b\"]]}"));
+            requests.add(request);
+            return request;
+        }
+    }
+}
diff --git 
a/components/camel-google/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/transform/GoogleSheetsJsonStructDataTypeTransformerTest.java
 
b/components/camel-google/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/transform/GoogleSheetsJsonStructDataTypeTransformerTest.java
index 06de74a63b68..cf6f719aa18e 100644
--- 
a/components/camel-google/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/transform/GoogleSheetsJsonStructDataTypeTransformerTest.java
+++ 
b/components/camel-google/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/transform/GoogleSheetsJsonStructDataTypeTransformerTest.java
@@ -240,10 +240,11 @@ public class 
GoogleSheetsJsonStructDataTypeTransformerTest {
     @Test
     public void testTransformToValueRangeRowDimension() throws Exception {
         Exchange inbound = new DefaultExchange(camelContext);
+        inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"spreadsheetId", spreadsheetId);
         inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"range", "A1:B1");
 
         String model = "{" +
-                       "\"spreadsheetId\": \"" + spreadsheetId + "\"," +
+                       "\"spreadsheetId\": \"other-spreadsheet\"," +
                        "\"A\": \"a1\"," +
                        "\"B\": \"b1\"" +
                        "}";
@@ -252,6 +253,8 @@ public class GoogleSheetsJsonStructDataTypeTransformerTest {
         transformer.transform(inbound.getMessage(), DataType.ANY, 
DataType.ANY);
 
         Assertions.assertEquals(spreadsheetId, 
inbound.getMessage().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID));
+        Assertions.assertEquals(spreadsheetId,
+                
inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"spreadsheetId"));
         Assertions.assertEquals("A1:B1", 
inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE));
         Assertions.assertEquals(RangeCoordinate.DIMENSION_ROWS,
                 
inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION));
@@ -267,11 +270,12 @@ public class 
GoogleSheetsJsonStructDataTypeTransformerTest {
     @Test
     public void testTransformToValueRangeColumnNames() throws Exception {
         Exchange inbound = new DefaultExchange(camelContext);
+        inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"spreadsheetId", spreadsheetId);
         inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"range", "A1:B1");
         inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"columnNames", "Foo,Bar");
 
         String model = "{" +
-                       "\"spreadsheetId\": \"" + spreadsheetId + "\"," +
+                       "\"spreadsheetId\": \"other-spreadsheet\"," +
                        "\"Foo\": \"a1\"," +
                        "\"Bar\": \"b1\"" +
                        "}";
@@ -280,6 +284,8 @@ public class GoogleSheetsJsonStructDataTypeTransformerTest {
         transformer.transform(inbound.getMessage(), DataType.ANY, 
DataType.ANY);
 
         Assertions.assertEquals(spreadsheetId, 
inbound.getMessage().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID));
+        Assertions.assertEquals(spreadsheetId,
+                
inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"spreadsheetId"));
         Assertions.assertEquals("A1:B1", 
inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE));
         Assertions.assertEquals(RangeCoordinate.DIMENSION_ROWS,
                 
inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION));
@@ -292,15 +298,52 @@ public class 
GoogleSheetsJsonStructDataTypeTransformerTest {
         Assertions.assertEquals("b1", valueRange.getValues().get(0).get(1));
     }
 
+    @Test
+    public void testTransformToValueRangeKeepsTheSpreadsheetOfTheHeader() 
throws Exception {
+        Exchange inbound = new DefaultExchange(camelContext);
+        inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"spreadsheetId", spreadsheetId);
+        inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"range", "A1:B2");
+
+        inbound.getMessage().setBody("[{\"spreadsheetId\": \"other-1\", \"A\": 
\"a1\", \"B\": \"b1\"},"
+                                     + " {\"spreadsheetId\": \"other-2\", 
\"A\": \"a2\", \"B\": \"b2\"}]");
+
+        transformer.transform(inbound.getMessage(), DataType.ANY, 
DataType.ANY);
+
+        Assertions.assertEquals(spreadsheetId, 
inbound.getMessage().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID));
+        Assertions.assertEquals(spreadsheetId,
+                
inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"spreadsheetId"));
+
+        ValueRange valueRange = (ValueRange) 
inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"values");
+        Assertions.assertEquals(Arrays.asList(Arrays.asList("a1", "b1"), 
Arrays.asList("a2", "b2")), valueRange.getValues());
+    }
+
+    @Test
+    public void 
testTransformToValueRangeWithoutSpreadsheetHeaderLeavesTheSpreadsheetToTheEndpoint()
 throws Exception {
+        Exchange inbound = new DefaultExchange(camelContext);
+        inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"range", "A1:B1");
+
+        inbound.getMessage().setBody("{\"spreadsheetId\": 
\"other-spreadsheet\", \"A\": \"a1\", \"B\": \"b1\"}");
+
+        transformer.transform(inbound.getMessage(), DataType.ANY, 
DataType.ANY);
+
+        // no header, so the producer uses the spreadsheetId option of the 
endpoint
+        
Assertions.assertNull(inbound.getMessage().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID));
+        
Assertions.assertNull(inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX
 + "spreadsheetId"));
+
+        ValueRange valueRange = (ValueRange) 
inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"values");
+        Assertions.assertEquals(Collections.singletonList(Arrays.asList("a1", 
"b1")), valueRange.getValues());
+    }
+
     @Test
     public void testTransformToValueRangeColumnDimension() throws Exception {
         Exchange inbound = new DefaultExchange(camelContext);
+        inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"spreadsheetId", spreadsheetId);
         inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"range", "A1:A2");
         inbound.getMessage().setHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"majorDimension",
                 RangeCoordinate.DIMENSION_COLUMNS);
 
         String model = "{" +
-                       "\"spreadsheetId\": \"" + spreadsheetId + "\"," +
+                       "\"spreadsheetId\": \"other-spreadsheet\"," +
                        "\"#1\": \"a1\"," +
                        "\"#2\": \"a2\"" +
                        "}";
@@ -309,6 +352,8 @@ public class GoogleSheetsJsonStructDataTypeTransformerTest {
         transformer.transform(inbound.getMessage(), DataType.ANY, 
DataType.ANY);
 
         Assertions.assertEquals(spreadsheetId, 
inbound.getMessage().getHeader(GoogleSheetsStreamConstants.SPREADSHEET_ID));
+        Assertions.assertEquals(spreadsheetId,
+                
inbound.getMessage().getHeader(GoogleSheetsConstants.PROPERTY_PREFIX + 
"spreadsheetId"));
         Assertions.assertEquals("A1:A2", 
inbound.getMessage().getHeader(GoogleSheetsStreamConstants.RANGE));
         Assertions.assertEquals(RangeCoordinate.DIMENSION_COLUMNS,
                 
inbound.getMessage().getHeader(GoogleSheetsStreamConstants.MAJOR_DIMENSION));
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 98f7994bc4a8..d16d07edec42 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
@@ -257,6 +257,28 @@ option from the JAXB data format configured on the 
CamelContext (such as `camel.
 
 The SOAP data format (camel-soap) is built on the JAXB data format, and always 
ignores these headers.
 
+=== camel-google-sheets - the x-struct transformer writes to the configured 
spreadsheet
+
+When the `google-sheets:application-x-struct` data type transformer turns JSON 
rows into a `ValueRange`, a
+`spreadsheetId` field in a row no longer chooses the spreadsheet. The 
spreadsheet is the one of the
+`CamelGoogleSheets.spreadsheetId` header, or else the `spreadsheetId` option 
of the endpoint. The field is still left
+out of the row values. Before, the field of the last row replaced the 
spreadsheet id, also when the header was set.
+
+Without the `CamelGoogleSheets.spreadsheetId` header, the transformer no 
longer sets the spreadsheet id headers
+(before it set them to an empty value), so the `spreadsheetId` option of the 
endpoint applies.
+
+Routes that take the spreadsheet from the message body must set the 
`CamelGoogleSheets.spreadsheetId` header from it
+before the transformer, for example with `setHeader` and a JSONPath expression.
+
+=== camel-google-sheets - the OAuth access token is sent only in the 
Authorization header
+
+The producer and the consumer of `google-sheets` no longer copy the 
`accessToken` option onto the request as the
+`access_token` query parameter of the Google API. The access token is sent in 
the `Authorization` header by the OAuth
+credential of the client, as before, so the request URL no longer carries it. 
The other credential options
+(`clientId`, `clientSecret`, `refreshToken`, `serviceAccountKey` and 
`delegate`) are not set on the request either.
+A `CamelGoogleSheets.accessToken` header is ignored for the same reason; use a 
separate endpoint with its own
+`accessToken` to call with another token.
+
 === camel-jpa - query parameters from CamelJpaParameters header are bound 
literally
 
 In previous versions, string values supplied in the `CamelJpaParameters` 
header map were evaluated as Simple expressions by the JPA producer.

Reply via email to