This is an automated email from the ASF dual-hosted git repository.
acosentino 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 2a8c64c2b37a CAMEL-21254 - Camel-Google-Big-Query: Cannot set a
different projectId from default in particular conditions (#21247)
2a8c64c2b37a is described below
commit 2a8c64c2b37a8129e5c1564610aa743f616e99e2
Author: Andrea Cosentino <[email protected]>
AuthorDate: Wed Feb 4 13:32:15 2026 +0100
CAMEL-21254 - Camel-Google-Big-Query: Cannot set a different projectId from
default in particular conditions (#21247)
Signed-off-by: Andrea Cosentino <[email protected]>
---
.../bigquery/GoogleBigQueryConnectionFactory.java | 15 +++++
.../google/bigquery/GoogleBigQueryEndpoint.java | 3 +-
.../bigquery/sql/GoogleBigQuerySQLEndpoint.java | 3 +-
.../unit/GoogleBigQueryConnectionFactoryTest.java | 64 ++++++++++++++++++++++
4 files changed, 83 insertions(+), 2 deletions(-)
diff --git
a/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryConnectionFactory.java
b/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryConnectionFactory.java
index c519ee1eeaa1..2e119ad6e558 100644
---
a/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryConnectionFactory.java
+++
b/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryConnectionFactory.java
@@ -41,6 +41,7 @@ public class GoogleBigQueryConnectionFactory {
private String serviceAccountKeyFile;
private String serviceURL;
+ private String projectId;
private BigQuery client;
private CamelContext camelContext;
private final Lock lock = new ReentrantLock();
@@ -86,6 +87,10 @@ public class GoogleBigQueryConnectionFactory {
BigQueryOptions.Builder builder = BigQueryOptions.newBuilder()
.setCredentials(credentials);
+ if (ObjectHelper.isNotEmpty(projectId)) {
+ builder.setProjectId(projectId);
+ }
+
if (ObjectHelper.isNotEmpty(serviceURL)) {
builder.setHost(serviceURL);
}
@@ -141,6 +146,16 @@ public class GoogleBigQueryConnectionFactory {
return this;
}
+ public String getProjectId() {
+ return projectId;
+ }
+
+ public GoogleBigQueryConnectionFactory setProjectId(String projectId) {
+ this.projectId = projectId;
+ resetClient();
+ return this;
+ }
+
private void resetClient() {
lock.lock();
try {
diff --git
a/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryEndpoint.java
b/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryEndpoint.java
index 85b7fa44b2a1..dee52470755e 100644
---
a/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryEndpoint.java
+++
b/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryEndpoint.java
@@ -69,7 +69,8 @@ public class GoogleBigQueryEndpoint extends DefaultEndpoint
implements EndpointS
if (connFactory == null) {
connFactory = new GoogleBigQueryConnectionFactory()
.setCamelContext(getCamelContext())
-
.setServiceAccountKeyFile(configuration.getServiceAccountKey());
+
.setServiceAccountKeyFile(configuration.getServiceAccountKey())
+ .setProjectId(configuration.getProjectId());
configuration.setConnectionFactory(connFactory);
}
bigQuery = connFactory.getDefaultClient();
diff --git
a/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLEndpoint.java
b/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLEndpoint.java
index 64adcad1b17f..1adbd07fef12 100644
---
a/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLEndpoint.java
+++
b/components/camel-google/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/sql/GoogleBigQuerySQLEndpoint.java
@@ -70,7 +70,8 @@ public class GoogleBigQuerySQLEndpoint extends
DefaultEndpoint {
if (connFactory == null) {
connFactory = new GoogleBigQueryConnectionFactory()
.setCamelContext(getCamelContext())
-
.setServiceAccountKeyFile(configuration.getServiceAccountKey());
+
.setServiceAccountKeyFile(configuration.getServiceAccountKey())
+ .setProjectId(configuration.getProjectId());
configuration.setConnectionFactory(connFactory);
}
bigQuery = connFactory.getDefaultClient();
diff --git
a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/GoogleBigQueryConnectionFactoryTest.java
b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/GoogleBigQueryConnectionFactoryTest.java
new file mode 100644
index 000000000000..198442707c89
--- /dev/null
+++
b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/GoogleBigQueryConnectionFactoryTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.bigquery.unit;
+
+import
org.apache.camel.component.google.bigquery.GoogleBigQueryConnectionFactory;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class GoogleBigQueryConnectionFactoryTest {
+
+ @Test
+ public void testProjectIdSetterGetter() {
+ GoogleBigQueryConnectionFactory factory = new
GoogleBigQueryConnectionFactory();
+
+ assertNull(factory.getProjectId());
+
+ factory.setProjectId("test-project-id");
+ assertEquals("test-project-id", factory.getProjectId());
+ }
+
+ @Test
+ public void testFluentApiForProjectId() {
+ GoogleBigQueryConnectionFactory factory = new
GoogleBigQueryConnectionFactory()
+ .setProjectId("my-project")
+ .setServiceAccountKeyFile("key.json")
+ .setServiceURL("https://bigquery.googleapis.com");
+
+ assertEquals("my-project", factory.getProjectId());
+ assertEquals("key.json", factory.getServiceAccountKeyFile());
+ assertEquals("https://bigquery.googleapis.com",
factory.getServiceURL());
+ }
+
+ @Test
+ public void testProjectIdResetsClient() {
+ GoogleBigQueryConnectionFactory factory = new
GoogleBigQueryConnectionFactory();
+
+ // Set project ID - this should reset the cached client (if any)
+ GoogleBigQueryConnectionFactory result =
factory.setProjectId("project-a");
+
+ // Verify fluent API returns the same factory
+ assertEquals(factory, result);
+ assertEquals("project-a", factory.getProjectId());
+
+ // Change project ID - should reset and update
+ factory.setProjectId("project-b");
+ assertEquals("project-b", factory.getProjectId());
+ }
+}