Skip to content

Commit

Permalink
Fix various ClassNotFoundExceptions for spring-redis extension
Browse files Browse the repository at this point in the history
Relates #5962
  • Loading branch information
jamesnetherton committed Apr 11, 2024
1 parent ee206ec commit dfe70e0
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 66 deletions.
8 changes: 2 additions & 6 deletions extensions-jvm/spring-redis/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
1 change: 1 addition & 0 deletions extensions-support/spring/shade/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
38 changes: 38 additions & 0 deletions integration-tests-jvm/spring-redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,25 @@
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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
18 changes: 18 additions & 0 deletions integration-tests-jvm/spring-redis/src/test/resources/redis.conf
Original file line number Diff line number Diff line change
@@ -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
10 changes: 0 additions & 10 deletions poms/bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
10 changes: 0 additions & 10 deletions poms/bom/src/main/generated/flattened-full-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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} -->
Expand Down Expand Up @@ -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>
Expand Down
Loading

0 comments on commit dfe70e0

Please sign in to comment.