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
commit 1b04bc8d6b9a6f37dd75a5246cdaef63243f8586 Author: Claus Ibsen <[email protected]> AuthorDate: Sat Oct 24 20:26:14 2026 +0200 CAMEL-26091: camel-aws2-redshift - the producer uses the client the endpoint builds (#28344) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../aws2/redshift/data/RedshiftData2Producer.java | 20 ++--- .../data/RedshiftData2ProducerOwnClientTest.java | 85 ++++++++++++++++++++++ 2 files changed, 95 insertions(+), 10 deletions(-) diff --git a/components/camel-aws/camel-aws2-redshift/src/main/java/org/apache/camel/component/aws2/redshift/data/RedshiftData2Producer.java b/components/camel-aws/camel-aws2-redshift/src/main/java/org/apache/camel/component/aws2/redshift/data/RedshiftData2Producer.java index b576f773ce93..b51af9131dd8 100644 --- a/components/camel-aws/camel-aws2-redshift/src/main/java/org/apache/camel/component/aws2/redshift/data/RedshiftData2Producer.java +++ b/components/camel-aws/camel-aws2-redshift/src/main/java/org/apache/camel/component/aws2/redshift/data/RedshiftData2Producer.java @@ -49,16 +49,16 @@ public class RedshiftData2Producer extends DefaultProducer { @Override public void process(final Exchange exchange) throws Exception { switch (determineOperation(exchange)) { - case listDatabases -> listDatabases(getConfiguration().getAwsRedshiftDataClient(), exchange); - case listSchemas -> listSchemas(getConfiguration().getAwsRedshiftDataClient(), exchange); - case listStatements -> listStatements(getConfiguration().getAwsRedshiftDataClient(), exchange); - case listTables -> listTables(getConfiguration().getAwsRedshiftDataClient(), exchange); - case describeTable -> describeTable(getConfiguration().getAwsRedshiftDataClient(), exchange); - case executeStatement -> executeStatement(getConfiguration().getAwsRedshiftDataClient(), exchange); - case batchExecuteStatement -> batchExecuteStatement(getConfiguration().getAwsRedshiftDataClient(), exchange); - case cancelStatement -> cancelStatement(getConfiguration().getAwsRedshiftDataClient(), exchange); - case describeStatement -> describeStatement(getConfiguration().getAwsRedshiftDataClient(), exchange); - case getStatementResult -> getStatementResult(getConfiguration().getAwsRedshiftDataClient(), exchange); + case listDatabases -> listDatabases(getEndpoint().getAwsRedshiftDataClient(), exchange); + case listSchemas -> listSchemas(getEndpoint().getAwsRedshiftDataClient(), exchange); + case listStatements -> listStatements(getEndpoint().getAwsRedshiftDataClient(), exchange); + case listTables -> listTables(getEndpoint().getAwsRedshiftDataClient(), exchange); + case describeTable -> describeTable(getEndpoint().getAwsRedshiftDataClient(), exchange); + case executeStatement -> executeStatement(getEndpoint().getAwsRedshiftDataClient(), exchange); + case batchExecuteStatement -> batchExecuteStatement(getEndpoint().getAwsRedshiftDataClient(), exchange); + case cancelStatement -> cancelStatement(getEndpoint().getAwsRedshiftDataClient(), exchange); + case describeStatement -> describeStatement(getEndpoint().getAwsRedshiftDataClient(), exchange); + case getStatementResult -> getStatementResult(getEndpoint().getAwsRedshiftDataClient(), exchange); default -> throw new IllegalArgumentException("Unsupported operation"); } } diff --git a/components/camel-aws/camel-aws2-redshift/src/test/java/org/apache/camel/component/aws2/redshift/data/RedshiftData2ProducerOwnClientTest.java b/components/camel-aws/camel-aws2-redshift/src/test/java/org/apache/camel/component/aws2/redshift/data/RedshiftData2ProducerOwnClientTest.java new file mode 100644 index 000000000000..ac229c0bbd29 --- /dev/null +++ b/components/camel-aws/camel-aws2-redshift/src/test/java/org/apache/camel/component/aws2/redshift/data/RedshiftData2ProducerOwnClientTest.java @@ -0,0 +1,85 @@ +/* + * 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.aws2.redshift.data; + +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import com.sun.net.httpserver.HttpServer; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.services.redshiftdata.model.ListDatabasesResponse; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; + +/** + * The producer uses the client that the endpoint builds from the access key and the secret key, when no + * RedshiftDataClient is given. The calls go to a local stub of the Redshift Data API. + */ +public class RedshiftData2ProducerOwnClientTest extends CamelTestSupport { + + private final List<String> targets = new CopyOnWriteArrayList<>(); + private HttpServer server; + + @Override + protected void setupResources() throws Exception { + server = HttpServer.create(new InetSocketAddress("localhost", 0), 0); + server.createContext("/", exchange -> { + targets.add(exchange.getRequestHeaders().getFirst("X-Amz-Target")); + byte[] answer = "{\"Databases\":[\"dev\",\"prod\"]}".getBytes(StandardCharsets.UTF_8); + exchange.getResponseHeaders().add("Content-Type", "application/x-amz-json-1.1"); + exchange.sendResponseHeaders(200, answer.length); + try (OutputStream out = exchange.getResponseBody()) { + out.write(answer); + } + }); + server.start(); + } + + @Override + protected void cleanupResources() throws Exception { + if (server != null) { + server.stop(0); + } + } + + @Test + public void listDatabasesWithTheClientOfTheEndpoint() { + Object body = template.requestBody("direct:listDatabases", ""); + + ListDatabasesResponse response = assertInstanceOf(ListDatabasesResponse.class, body); + assertEquals(List.of("dev", "prod"), response.databases()); + assertEquals(List.of("RedshiftData.ListDatabases"), targets); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:listDatabases") + .to("aws2-redshift-data://test?operation=listDatabases&accessKey=xxx&secretKey=yyy®ion=eu-west-1" + + "&overrideEndpoint=true&uriEndpointOverride=http://localhost:" + server.getAddress().getPort()); + } + }; + } +}
