This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push: new dfe70e0326 Fix various ClassNotFoundExceptions for spring-redis extension dfe70e0326 is described below commit dfe70e0326944b1780bff289403aa0964cf6a440 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Thu Apr 11 10:20:11 2024 +0100 Fix various ClassNotFoundExceptions for spring-redis extension Relates #5962 --- extensions-jvm/spring-redis/runtime/pom.xml | 8 +-- extensions-support/spring/shade/core/pom.xml | 1 + integration-tests-jvm/spring-redis/pom.xml | 38 +++++++++++++++ .../spring/redis/it/SpringRedisProducers.java | 54 ++++++++++++++++++++ .../spring/redis/it/SpringRedisResource.java | 27 +++++----- .../spring/redis/it/SpringRedisRoutes.java | 46 +++++++++++++++++ .../component/spring/redis/it/SpringRedisTest.java | 21 ++++++-- .../spring/redis/it/SpringRedisTestResource.java | 57 ++++++++++++++++++++++ .../spring-redis/src/test/resources/redis.conf | 18 +++++++ poms/bom/pom.xml | 10 ---- poms/bom/src/main/generated/flattened-full-pom.xml | 10 ---- .../src/main/generated/flattened-reduced-pom.xml | 10 ---- .../generated/flattened-reduced-verbose-pom.xml | 10 ---- .../camel-quarkus-banned-dependencies-spring.xml | 1 + .../enforcer-rules/quarkus-banned-dependencies.xsl | 2 +- 15 files changed, 247 insertions(+), 66 deletions(-) diff --git a/extensions-jvm/spring-redis/runtime/pom.xml b/extensions-jvm/spring-redis/runtime/pom.xml index d4c5020303..67761890d3 100644 --- a/extensions-jvm/spring-redis/runtime/pom.xml +++ b/extensions-jvm/spring-redis/runtime/pom.xml @@ -48,12 +48,8 @@ <artifactId>camel-quarkus-support-spring</artifactId> </dependency> <dependency> - <groupId>org.springframework.data</groupId> - <artifactId>spring-data-redis</artifactId> - </dependency> - <dependency> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-spring-data-commons-api</artifactId> + <groupId>org.springframework</groupId> + <artifactId>spring-expression</artifactId> </dependency> </dependencies> diff --git a/extensions-support/spring/shade/core/pom.xml b/extensions-support/spring/shade/core/pom.xml index 7e3aa3937a..bbe8c335ba 100644 --- a/extensions-support/spring/shade/core/pom.xml +++ b/extensions-support/spring/shade/core/pom.xml @@ -66,6 +66,7 @@ <include>org/springframework/core/io/**</include> <include>org/springframework/core/log/**</include> <include>org/springframework/core/metrics/**</include> + <include>org/springframework/core/serializer/**</include> <include>org/springframework/core/task/**</include> <include>org/springframework/lang/**</include> <include>org/springframework/util/*</include> diff --git a/integration-tests-jvm/spring-redis/pom.xml b/integration-tests-jvm/spring-redis/pom.xml index 4d5148866d..782029b34c 100644 --- a/integration-tests-jvm/spring-redis/pom.xml +++ b/integration-tests-jvm/spring-redis/pom.xml @@ -31,6 +31,10 @@ <description>Integration tests for Camel Quarkus Spring Redis extension</description> <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct</artifactId> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-spring-redis</artifactId> @@ -51,6 +55,27 @@ <artifactId>rest-assured</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>testcontainers</artifactId> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit4-mock</artifactId> + <scope>test</scope> + </dependency> </dependencies> <profiles> @@ -63,6 +88,19 @@ </activation> <dependencies> <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-spring-redis-deployment</artifactId> diff --git a/integration-tests-jvm/spring-redis/src/main/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisProducers.java b/integration-tests-jvm/spring-redis/src/main/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisProducers.java new file mode 100644 index 0000000000..0cd1425b04 --- /dev/null +++ b/integration-tests-jvm/spring-redis/src/main/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisProducers.java @@ -0,0 +1,54 @@ +/* + * 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.quarkus.component.spring.redis.it; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Named; +import org.apache.camel.component.redis.RedisConfiguration; +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.springframework.data.redis.connection.RedisPassword; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; + +@ApplicationScoped +public class SpringRedisProducers { + + @ConfigProperty(name = "redis.host") + String host; + + @ConfigProperty(name = "redis.port") + int port; + + @SuppressWarnings("unchecked") + @Named("redisTemplate") + RedisTemplate<String, String> produceRedisTemplate() { + RedisConfiguration redisConfiguration = new RedisConfiguration(); + + RedisStandaloneConfiguration conf = new RedisStandaloneConfiguration(); + conf.setPassword(RedisPassword.of("p4ssw0rd")); + conf.setHostName(host); + conf.setPort(port); + JedisConnectionFactory connectionFactory = new JedisConnectionFactory(conf); + redisConfiguration.setConnectionFactory(connectionFactory); + + RedisTemplate<String, String> redisTemplate = (RedisTemplate<String, String>) redisConfiguration.getRedisTemplate(); + connectionFactory.start(); + + return redisTemplate; + } +} diff --git a/integration-tests-jvm/spring-redis/src/main/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisResource.java b/integration-tests-jvm/spring-redis/src/main/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisResource.java index e40b5a2d14..430b75430c 100644 --- a/integration-tests-jvm/spring-redis/src/main/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisResource.java +++ b/integration-tests-jvm/spring-redis/src/main/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisResource.java @@ -23,28 +23,25 @@ import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; -import org.apache.camel.CamelContext; -import org.jboss.logging.Logger; +import org.apache.camel.ProducerTemplate; @Path("/spring-redis") @ApplicationScoped public class SpringRedisResource { - - private static final Logger LOG = Logger.getLogger(SpringRedisResource.class); - - private static final String COMPONENT_SPRING_REDIS = "spring-redis"; @Inject - CamelContext context; + ProducerTemplate template; + + @Path("/set") + @GET + public Response set() throws Exception { + template.sendBody("direct:set", "foo"); + return Response.ok().build(); + } - @Path("/load/component/spring-redis") + @Path("/exists") @GET @Produces(MediaType.TEXT_PLAIN) - public Response loadComponentSpringRedis() throws Exception { - /* This is an autogenerated test */ - if (context.getComponent(COMPONENT_SPRING_REDIS) != null) { - return Response.ok().build(); - } - LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_SPRING_REDIS); - return Response.status(500, COMPONENT_SPRING_REDIS + " could not be loaded from the Camel context").build(); + public String exists() throws Exception { + return template.requestBody("direct:exists", null, String.class); } } diff --git a/integration-tests-jvm/spring-redis/src/main/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisRoutes.java b/integration-tests-jvm/spring-redis/src/main/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisRoutes.java new file mode 100644 index 0000000000..40fe406d36 --- /dev/null +++ b/integration-tests-jvm/spring-redis/src/main/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisRoutes.java @@ -0,0 +1,46 @@ +/* + * 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.quarkus.component.spring.redis.it; + +import jakarta.enterprise.context.ApplicationScoped; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.redis.RedisConstants; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +@ApplicationScoped +public class SpringRedisRoutes extends RouteBuilder { + static final String KEY = "test-key"; + + @ConfigProperty(name = "redis.host") + String host; + + @ConfigProperty(name = "redis.port") + int port; + + @Override + public void configure() throws Exception { + from("direct:set") + .setHeader(RedisConstants.COMMAND).constant("SET") + .setHeader(RedisConstants.KEY).constant(KEY) + .toF("spring-redis://%s:%d?redisTemplate=#redisTemplate", host, port); + + from("direct:exists") + .setHeader(RedisConstants.COMMAND).constant("EXISTS") + .setHeader(RedisConstants.KEY).constant(KEY) + .toF("spring-redis://%s:%d?redisTemplate=#redisTemplate", host, port); + } +} diff --git a/integration-tests-jvm/spring-redis/src/test/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisTest.java b/integration-tests-jvm/spring-redis/src/test/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisTest.java index 49363b9079..63fd6be1c8 100644 --- a/integration-tests-jvm/spring-redis/src/test/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisTest.java +++ b/integration-tests-jvm/spring-redis/src/test/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisTest.java @@ -16,19 +16,32 @@ */ package org.apache.camel.quarkus.component.spring.redis.it; +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import org.junit.jupiter.api.Test; +import org.testcontainers.shaded.org.awaitility.Awaitility; @QuarkusTest +@QuarkusTestResource(SpringRedisTestResource.class) class SpringRedisTest { @Test - public void loadComponentSpringRedis() { - /* A simple autogenerated test */ - RestAssured.get("/spring-redis/load/component/spring-redis") + public void setKey() throws InterruptedException { + RestAssured.get("/spring-redis/set") .then() .statusCode(200); - } + Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> { + String result = RestAssured.get("/spring-redis/exists") + .then() + .statusCode(200) + .extract() + .body() + .asString(); + return result.equals("true"); + }); + } } diff --git a/integration-tests-jvm/spring-redis/src/test/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisTestResource.java b/integration-tests-jvm/spring-redis/src/test/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisTestResource.java new file mode 100644 index 0000000000..a800d665d1 --- /dev/null +++ b/integration-tests-jvm/spring-redis/src/test/java/org/apache/camel/quarkus/component/spring/redis/it/SpringRedisTestResource.java @@ -0,0 +1,57 @@ +/* + * 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.quarkus.component.spring.redis.it; + +import java.util.Map; + +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; +import org.eclipse.microprofile.config.ConfigProvider; +import org.testcontainers.containers.BindMode; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; + +public class SpringRedisTestResource implements QuarkusTestResourceLifecycleManager { + private static final String REDIS_IMAGE_NAME = ConfigProvider.getConfig().getValue("redis.container.image", String.class); + private static final int REDIS_PORT = 6379; + + private GenericContainer<?> container; + + @Override + public Map<String, String> start() { + container = new GenericContainer<>(REDIS_IMAGE_NAME) + .withExposedPorts(REDIS_PORT) + .withClasspathResourceMapping("redis.conf", "/usr/local/etc/redis", BindMode.READ_ONLY) + .waitingFor(Wait.forListeningPort()); + + container.start(); + + return Map.of( + "redis.host", container.getHost(), + "redis.port", container.getMappedPort(REDIS_PORT).toString()); + } + + @Override + public void stop() { + try { + if (container != null) { + container.stop(); + } + } catch (Exception e) { + // ignored + } + } +} diff --git a/integration-tests-jvm/spring-redis/src/test/resources/redis.conf b/integration-tests-jvm/spring-redis/src/test/resources/redis.conf new file mode 100644 index 0000000000..ff0ce75826 --- /dev/null +++ b/integration-tests-jvm/spring-redis/src/test/resources/redis.conf @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +requirepass p4ssw0rd diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 7b58c4563d..9bb941bb82 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -2416,12 +2416,6 @@ <groupId>org.apache.camel</groupId> <artifactId>camel-spring-redis</artifactId> <version>${camel.version}</version> - <exclusions> - <exclusion> - <groupId>org.springframework.data</groupId> - <artifactId>spring-data-redis</artifactId> - </exclusion> - </exclusions> </dependency> <dependency> <groupId>org.apache.camel</groupId> @@ -7092,10 +7086,6 @@ <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> </exclusion> - <exclusion> - <groupId>org.springframework.data</groupId> - <artifactId>spring-data-commons</artifactId> - </exclusion> </exclusions> </dependency> <dependency> diff --git a/poms/bom/src/main/generated/flattened-full-pom.xml b/poms/bom/src/main/generated/flattened-full-pom.xml index dd84e6b2ba..53d443db48 100644 --- a/poms/bom/src/main/generated/flattened-full-pom.xml +++ b/poms/bom/src/main/generated/flattened-full-pom.xml @@ -2353,12 +2353,6 @@ <groupId>org.apache.camel</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>camel-spring-redis</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <version>4.5.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> - <exclusions> - <exclusion> - <groupId>org.springframework.data</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> - <artifactId>spring-data-redis</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> - </exclusion> - </exclusions> </dependency> <dependency> <groupId>org.apache.camel</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> @@ -7014,10 +7008,6 @@ <groupId>org.springframework</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>spring-oxm</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> </exclusion> - <exclusion> - <groupId>org.springframework.data</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> - <artifactId>spring-data-commons</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> - </exclusion> </exclusions> </dependency> <dependency> diff --git a/poms/bom/src/main/generated/flattened-reduced-pom.xml b/poms/bom/src/main/generated/flattened-reduced-pom.xml index d14d1e54e3..e1b89a1e22 100644 --- a/poms/bom/src/main/generated/flattened-reduced-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-pom.xml @@ -2353,12 +2353,6 @@ <groupId>org.apache.camel</groupId> <artifactId>camel-spring-redis</artifactId> <version>4.5.0</version> - <exclusions> - <exclusion> - <groupId>org.springframework.data</groupId> - <artifactId>spring-data-redis</artifactId> - </exclusion> - </exclusions> </dependency> <dependency> <groupId>org.apache.camel</groupId> @@ -6919,10 +6913,6 @@ <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> </exclusion> - <exclusion> - <groupId>org.springframework.data</groupId> - <artifactId>spring-data-commons</artifactId> - </exclusion> </exclusions> </dependency> <dependency> diff --git a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml index 387486f3a5..1074dd23b0 100644 --- a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml @@ -2353,12 +2353,6 @@ <groupId>org.apache.camel</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>camel-spring-redis</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <version>4.5.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> - <exclusions> - <exclusion> - <groupId>org.springframework.data</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> - <artifactId>spring-data-redis</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> - </exclusion> - </exclusions> </dependency> <dependency> <groupId>org.apache.camel</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> @@ -6919,10 +6913,6 @@ <groupId>org.springframework</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>spring-oxm</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> </exclusion> - <exclusion> - <groupId>org.springframework.data</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> - <artifactId>spring-data-commons</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> - </exclusion> </exclusions> </dependency> <dependency> diff --git a/tooling/enforcer-rules/camel-quarkus-banned-dependencies-spring.xml b/tooling/enforcer-rules/camel-quarkus-banned-dependencies-spring.xml index eea71b99c3..597f965d80 100644 --- a/tooling/enforcer-rules/camel-quarkus-banned-dependencies-spring.xml +++ b/tooling/enforcer-rules/camel-quarkus-banned-dependencies-spring.xml @@ -77,6 +77,7 @@ <include>org.springframework:spring-tx</include> <include>org.springframework.amqp:spring-amqp</include> <include>org.springframework.amqp:spring-rabbit</include> + <include>org.springframework.data:spring-data-commons</include><!-- required by camel-spring-redis --> <include>org.springframework.data:spring-data-keyvalue</include><!-- required by camel-spring-redis --> <include>org.springframework.data:spring-data-redis</include><!-- required by camel-spring-redis --> <include>org.springframework.retry:spring-retry</include> diff --git a/tooling/enforcer-rules/quarkus-banned-dependencies.xsl b/tooling/enforcer-rules/quarkus-banned-dependencies.xsl index a6a82e45aa..c073a318e1 100644 --- a/tooling/enforcer-rules/quarkus-banned-dependencies.xsl +++ b/tooling/enforcer-rules/quarkus-banned-dependencies.xsl @@ -30,5 +30,5 @@ <!-- This is to remove some entries from --> <!-- https://github.com/quarkusio/quarkus/blob/main/independent-projects/enforcer-rules/src/main/resources/enforcer-rules/quarkus-banned-dependencies.xml --> <!-- before passing it to Maven enforcer plugin --> - <xsl:template match="//bannedDependencies/excludes/exclude[contains(text(), 'org.springframework:spring-')]"/> + <xsl:template match="//bannedDependencies/excludes/exclude[contains(text(), 'org.springframework:spring-') or contains(text(), 'org.springframework.data:spring-')]"/> </xsl:stylesheet>