You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2021/08/25 10:12:29 UTC
[camel-quarkus] branch main updated: Add additional test coverage
to messaging extesnions
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 e6da932 Add additional test coverage to messaging extesnions
e6da932 is described below
commit e6da932d3da2fc13a5d2372dcd632cde77557257
Author: James Netherton <ja...@gmail.com>
AuthorDate: Tue Aug 24 16:56:41 2021 +0100
Add additional test coverage to messaging extesnions
* Request / reply
* POJO consuming / producing
* Dynamically computed destinations
---
.../jms/artemis/it/JmsArtemisResource.java | 13 +++++
.../component/jms/artemis/it/JmsArtemisTest.java | 17 +++++++
.../component/jms/qpid/it/QpidJmsResource.java | 12 +++++
.../quarkus/component/jms/qpid/it/JmsQpidTest.java | 17 +++++++
integration-tests/messaging/common/pom.xml | 34 +++++++++++++
.../messaging/it/MessagingCommonResource.java | 29 +++++++++++
.../messaging/it/MessagingCommonRoutes.java | 11 ++++
.../messaging/it/MessagingPojoConsumer.java | 58 ++++++++++++++++++++++
.../messaging/it/AbstractMessagingTest.java | 27 ++++++++++
integration-tests/messaging/jms/pom.xml | 34 +++++++++++++
.../camel/quarkus/messaging/jms/JmsProducers.java | 49 ++++++++++++++++++
.../camel/quarkus/messaging/jms/JmsResource.java | 26 ++++++++++
.../camel/quarkus/messaging/jms/JmsRoutes.java | 4 ++
.../messaging/jms/AbstractJmsMessagingTest.java | 41 +++++++++++++++
integration-tests/messaging/sjms/pom.xml | 34 +++++++++++++
.../sjms/{SjmsRoutes.java => SjmsProducers.java} | 30 +++++------
.../camel/quarkus/messaging/sjms/SjmsResource.java | 14 ++++++
.../camel/quarkus/messaging/sjms/SjmsRoutes.java | 4 ++
.../messaging/sjms/AbstractSjmsMessagingTest.java | 26 ++++++++++
19 files changed, 466 insertions(+), 14 deletions(-)
diff --git a/integration-tests/jms-artemis-client/src/main/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisResource.java b/integration-tests/jms-artemis-client/src/main/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisResource.java
index d742c93..3503e82 100644
--- a/integration-tests/jms-artemis-client/src/main/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisResource.java
+++ b/integration-tests/jms-artemis-client/src/main/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisResource.java
@@ -20,10 +20,14 @@ import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.jms.ConnectionFactory;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+
@ApplicationScoped
@Path("/messaging/jms/artemis")
public class JmsArtemisResource {
@@ -31,10 +35,19 @@ public class JmsArtemisResource {
@Inject
ConnectionFactory connectionFactory;
+ @Produce("jms:queue:pojoProduce")
+ ProducerTemplate pojoProducer;
+
@GET
@Path("/connection/factory")
@Produces(MediaType.TEXT_PLAIN)
public String connectionFactoryImplementation() {
return connectionFactory.getClass().getName();
}
+
+ @POST
+ @Path("/pojo/producer")
+ public void pojoProducer(String message) {
+ pojoProducer.sendBody(message);
+ }
}
diff --git a/integration-tests/jms-artemis-client/src/test/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisTest.java b/integration-tests/jms-artemis-client/src/test/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisTest.java
index f13a396..15bbf7e 100644
--- a/integration-tests/jms-artemis-client/src/test/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisTest.java
+++ b/integration-tests/jms-artemis-client/src/test/java/org/apache/camel/quarkus/component/jms/artemis/it/JmsArtemisTest.java
@@ -24,6 +24,7 @@ import org.apache.camel.quarkus.messaging.jms.AbstractJmsMessagingTest;
import org.apache.camel.quarkus.test.support.activemq.ActiveMQTestResource;
import org.junit.jupiter.api.Test;
+import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
@QuarkusTest
@@ -38,4 +39,20 @@ class JmsArtemisTest extends AbstractJmsMessagingTest {
.statusCode(200)
.body(startsWith("javax.jms.ConnectionFactory"));
}
+
+ @Test
+ public void testPojoProducer() {
+ String message = "Camel Quarkus Artemis JMS Pojo Producer";
+
+ RestAssured.given()
+ .body(message)
+ .post("/messaging/jms/artemis/pojo/producer")
+ .then()
+ .statusCode(204);
+
+ RestAssured.get("/messaging/{queueName}", "pojoProduce")
+ .then()
+ .statusCode(200)
+ .body(is(message));
+ }
}
diff --git a/integration-tests/jms-qpid-amqp-client/src/main/java/org/apache/camel/quarkus/component/jms/qpid/it/QpidJmsResource.java b/integration-tests/jms-qpid-amqp-client/src/main/java/org/apache/camel/quarkus/component/jms/qpid/it/QpidJmsResource.java
index 8918378..586218f 100644
--- a/integration-tests/jms-qpid-amqp-client/src/main/java/org/apache/camel/quarkus/component/jms/qpid/it/QpidJmsResource.java
+++ b/integration-tests/jms-qpid-amqp-client/src/main/java/org/apache/camel/quarkus/component/jms/qpid/it/QpidJmsResource.java
@@ -20,10 +20,14 @@ import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.jms.ConnectionFactory;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+
@ApplicationScoped
@Path("/messaging/jms/qpid")
public class QpidJmsResource {
@@ -31,6 +35,9 @@ public class QpidJmsResource {
@Inject
ConnectionFactory connectionFactory;
+ @Produce("jms:queue:pojoProduce")
+ ProducerTemplate pojoProducer;
+
@GET
@Path("/connection/factory")
@Produces(MediaType.TEXT_PLAIN)
@@ -38,4 +45,9 @@ public class QpidJmsResource {
return connectionFactory.getClass().getName();
}
+ @POST
+ @Path("/pojo/producer")
+ public void pojoProducer(String message) {
+ pojoProducer.sendBody(message);
+ }
}
diff --git a/integration-tests/jms-qpid-amqp-client/src/test/java/org/apache/camel/quarkus/component/jms/qpid/it/JmsQpidTest.java b/integration-tests/jms-qpid-amqp-client/src/test/java/org/apache/camel/quarkus/component/jms/qpid/it/JmsQpidTest.java
index f5a8dce..bcdd445 100644
--- a/integration-tests/jms-qpid-amqp-client/src/test/java/org/apache/camel/quarkus/component/jms/qpid/it/JmsQpidTest.java
+++ b/integration-tests/jms-qpid-amqp-client/src/test/java/org/apache/camel/quarkus/component/jms/qpid/it/JmsQpidTest.java
@@ -24,6 +24,7 @@ import org.apache.camel.quarkus.messaging.jms.AbstractJmsMessagingTest;
import org.apache.camel.quarkus.test.support.activemq.ActiveMQTestResource;
import org.junit.jupiter.api.Test;
+import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
@QuarkusTest
@@ -38,4 +39,20 @@ class JmsQpidTest extends AbstractJmsMessagingTest {
.statusCode(200)
.body(startsWith("org.amqphub.quarkus.qpid"));
}
+
+ @Test
+ public void testPojoProducer() {
+ String message = "Camel Quarkus qPid AMQP Pojo Producer";
+
+ RestAssured.given()
+ .body(message)
+ .post("/messaging/jms/qpid/pojo/producer")
+ .then()
+ .statusCode(204);
+
+ RestAssured.get("/messaging/{queueName}", "pojoProduce")
+ .then()
+ .statusCode(200)
+ .body(is(message));
+ }
}
diff --git a/integration-tests/messaging/common/pom.xml b/integration-tests/messaging/common/pom.xml
index 78f3d14..1636836 100644
--- a/integration-tests/messaging/common/pom.xml
+++ b/integration-tests/messaging/common/pom.xml
@@ -32,6 +32,14 @@
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bean</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-direct</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-jta</artifactId>
</dependency>
<dependency>
@@ -71,6 +79,32 @@
<!-- 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-bean-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-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-jta-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
diff --git a/integration-tests/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingCommonResource.java b/integration-tests/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingCommonResource.java
index ecd9fff..d9f6e7f 100644
--- a/integration-tests/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingCommonResource.java
+++ b/integration-tests/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingCommonResource.java
@@ -69,6 +69,9 @@ public class MessagingCommonResource {
@Inject
ComponentScheme componentScheme;
+ @Inject
+ MessagingPojoConsumer pojoConsumer;
+
@Path("/{queueName}")
@GET
@Produces(MediaType.TEXT_PLAIN)
@@ -256,4 +259,30 @@ public class MessagingCommonResource {
}
return mock.getExchanges().stream().map(e -> e.getMessage().getBody(String.class)).collect(Collectors.toList());
}
+
+ @Path("/reply/to")
+ @Consumes(MediaType.TEXT_PLAIN)
+ @POST
+ public void replyTo(String message) throws InterruptedException {
+ MockEndpoint mockEndpointA = context.getEndpoint("mock:replyToStart", MockEndpoint.class);
+ MockEndpoint mockEndpointB = context.getEndpoint("mock:replyToEnd", MockEndpoint.class);
+ MockEndpoint mockEndpointC = context.getEndpoint("mock:replyToDone", MockEndpoint.class);
+
+ mockEndpointA.expectedBodiesReceived(message);
+ mockEndpointB.expectedBodiesReceived("Hello " + message);
+ mockEndpointC.expectedBodiesReceived(message);
+
+ producerTemplate.sendBody("direct:replyTo", message);
+
+ mockEndpointA.assertIsSatisfied(5000L);
+ mockEndpointB.assertIsSatisfied(5000L);
+ mockEndpointC.assertIsSatisfied(5000L);
+ }
+
+ @Path("/pojo/consumer")
+ @Produces(MediaType.TEXT_PLAIN)
+ @GET
+ public String pojoConsumer() {
+ return pojoConsumer.getMessage(5000);
+ }
}
diff --git a/integration-tests/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingCommonRoutes.java b/integration-tests/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingCommonRoutes.java
index 5b02d04..7dd29f4 100644
--- a/integration-tests/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingCommonRoutes.java
+++ b/integration-tests/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingCommonRoutes.java
@@ -89,6 +89,17 @@ public class MessagingCommonRoutes extends RouteBuilder {
.resequence(body()).batch().timeout(10000).allowDuplicates().reverse()
.to("mock:resequence");
+ from("direct:replyTo")
+ .toF("%s:queue:replyQueueA?replyTo=replyQueueB&preserveMessageQos=true", componentScheme)
+ .to("mock:replyToDone");
+
+ fromF("%s:queue:replyQueueA", componentScheme)
+ .to("mock:replyToStart")
+ .transform(body().prepend("Hello "));
+
+ fromF("%s:queue:replyQueueB?disableReplyTo=true", componentScheme)
+ .to("mock:replyToEnd");
+
}
private ErrorHandlerBuilder setUpJtaErrorHandler() {
diff --git a/integration-tests/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingPojoConsumer.java b/integration-tests/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingPojoConsumer.java
new file mode 100644
index 0000000..f26610b
--- /dev/null
+++ b/integration-tests/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingPojoConsumer.java
@@ -0,0 +1,58 @@
+/*
+ * 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.messaging.it;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.camel.Consume;
+import org.apache.camel.quarkus.component.messaging.it.util.scheme.ComponentScheme;
+
+@Singleton
+public class MessagingPojoConsumer {
+
+ private static BlockingQueue<String> messages = new LinkedBlockingQueue<>();
+
+ @Inject
+ ComponentScheme scheme;
+
+ public String getMessagingUri() {
+ return scheme + ":queue:pojoConsume";
+ }
+
+ @Consume(property = "messagingUri")
+ public void consumeMessage(String content) {
+ try {
+ messages.put("Hello " + content);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ public String getMessage(long timeout) {
+ try {
+ return messages.poll(timeout, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ return null;
+ }
+}
diff --git a/integration-tests/messaging/common/src/test/java/org/apache/camel/quarkus/component/messaging/it/AbstractMessagingTest.java b/integration-tests/messaging/common/src/test/java/org/apache/camel/quarkus/component/messaging/it/AbstractMessagingTest.java
index 1ce9a04..59f1d32 100644
--- a/integration-tests/messaging/common/src/test/java/org/apache/camel/quarkus/component/messaging/it/AbstractMessagingTest.java
+++ b/integration-tests/messaging/common/src/test/java/org/apache/camel/quarkus/component/messaging/it/AbstractMessagingTest.java
@@ -142,4 +142,31 @@ public abstract class AbstractMessagingTest {
Assertions.assertEquals(messages, actual);
}
+ @Test
+ public void testJmsReplyTo() {
+ String message = "JMS Reply To Message";
+ RestAssured.given()
+ .body(message)
+ .post("/messaging/reply/to")
+ .then()
+ .statusCode(204);
+ }
+
+ @Test
+ public void testJmsPojoConsumer() {
+ String message = "Camel Quarkus JMS POJO Consumer";
+
+ RestAssured.given()
+ .contentType(ContentType.TEXT)
+ .body(message)
+ .post("/messaging/{queueName}", "pojoConsume")
+ .then()
+ .statusCode(201);
+
+ RestAssured.given()
+ .get("/messaging/pojo/consumer")
+ .then()
+ .statusCode(200)
+ .body(is("Hello " + message));
+ }
}
diff --git a/integration-tests/messaging/jms/pom.xml b/integration-tests/messaging/jms/pom.xml
index 9136bd8..eec7c7f 100644
--- a/integration-tests/messaging/jms/pom.xml
+++ b/integration-tests/messaging/jms/pom.xml
@@ -32,6 +32,14 @@
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bean</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-direct</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-jms</artifactId>
</dependency>
<dependency>
@@ -65,6 +73,32 @@
<!-- 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-bean-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-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-jms-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
diff --git a/integration-tests/messaging/jms/src/main/java/org/apache/camel/quarkus/messaging/jms/JmsProducers.java b/integration-tests/messaging/jms/src/main/java/org/apache/camel/quarkus/messaging/jms/JmsProducers.java
index 4ca266f..b3ed6bf 100644
--- a/integration-tests/messaging/jms/src/main/java/org/apache/camel/quarkus/messaging/jms/JmsProducers.java
+++ b/integration-tests/messaging/jms/src/main/java/org/apache/camel/quarkus/messaging/jms/JmsProducers.java
@@ -16,7 +16,12 @@
*/
package org.apache.camel.quarkus.messaging.jms;
+import java.util.Set;
+
import javax.inject.Named;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
@@ -24,6 +29,10 @@ import javax.jms.TextMessage;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.jms.JmsConstants;
import org.apache.camel.component.jms.MessageListenerContainerFactory;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springframework.jms.support.converter.MessageConversionException;
@@ -83,4 +92,44 @@ public class JmsProducers {
}
};
}
+
+ @Named
+ public DestinationHeaderSetter destinationHeaderSetter() {
+ return new DestinationHeaderSetter();
+ }
+
+ @RegisterForReflection(fields = false)
+ static final class DestinationHeaderSetter {
+
+ public void setJmsDestinationHeader(Exchange exchange) {
+ org.apache.camel.Message message = exchange.getMessage();
+ String destinationHeaderType = message.getHeader("DestinationHeaderType", String.class);
+ String destinationName = message.getHeader("DestinationName", String.class);
+ if (destinationHeaderType.equals(String.class.getName())) {
+ message.setHeader(JmsConstants.JMS_DESTINATION_NAME, destinationName);
+ } else {
+ CamelContext camelContext = exchange.getContext();
+ Set<ConnectionFactory> factories = camelContext.getRegistry().findByType(ConnectionFactory.class);
+ ConnectionFactory connectionFactory = factories.iterator().next();
+
+ Connection connection = null;
+ try {
+ connection = connectionFactory.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Destination destination = session.createQueue(destinationName);
+ message.setHeader(JmsConstants.JMS_DESTINATION, destination);
+ } catch (JMSException e) {
+ throw new IllegalStateException("Failed to create JMS connection", e);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+ }
}
diff --git a/integration-tests/messaging/jms/src/main/java/org/apache/camel/quarkus/messaging/jms/JmsResource.java b/integration-tests/messaging/jms/src/main/java/org/apache/camel/quarkus/messaging/jms/JmsResource.java
index 244e68c..44cd909 100644
--- a/integration-tests/messaging/jms/src/main/java/org/apache/camel/quarkus/messaging/jms/JmsResource.java
+++ b/integration-tests/messaging/jms/src/main/java/org/apache/camel/quarkus/messaging/jms/JmsResource.java
@@ -16,14 +16,20 @@
*/
package org.apache.camel.quarkus.messaging.jms;
+import java.net.URI;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.inject.Inject;
+import javax.jms.Destination;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -128,4 +134,24 @@ public class JmsResource {
}
return Response.serverError().build();
}
+
+ @Path("/custom/destination/{destinationName}")
+ @POST
+ public Response produceMessageWithCustomDestination(
+ @QueryParam("isStringDestination") boolean isStringDestination,
+ @PathParam("destinationName") String destinationName,
+ String message) throws Exception {
+
+ Map<String, Object> headers = new HashMap<>();
+ if (isStringDestination) {
+ headers.put("DestinationHeaderType", String.class.getName());
+ } else {
+ headers.put("DestinationHeaderType", Destination.class.getName());
+ }
+ headers.put("DestinationName", destinationName);
+
+ producerTemplate.sendBodyAndHeaders("direct:computedDestination", message, headers);
+
+ return Response.created(new URI("https://camel.apache.org/")).build();
+ }
}
diff --git a/integration-tests/messaging/jms/src/main/java/org/apache/camel/quarkus/messaging/jms/JmsRoutes.java b/integration-tests/messaging/jms/src/main/java/org/apache/camel/quarkus/messaging/jms/JmsRoutes.java
index 7b42c72..7c2d2d2 100644
--- a/integration-tests/messaging/jms/src/main/java/org/apache/camel/quarkus/messaging/jms/JmsRoutes.java
+++ b/integration-tests/messaging/jms/src/main/java/org/apache/camel/quarkus/messaging/jms/JmsRoutes.java
@@ -36,5 +36,9 @@ public class JmsRoutes extends RouteBuilder {
fromF("%s:queue:transferException?transferException=true", componentScheme)
.throwException(new IllegalStateException("Forced exception"));
+
+ from("direct:computedDestination")
+ .bean("destinationHeaderSetter")
+ .toF("%s:queue:override", componentScheme);
}
}
diff --git a/integration-tests/messaging/jms/src/test/java/org/apache/camel/quarkus/messaging/jms/AbstractJmsMessagingTest.java b/integration-tests/messaging/jms/src/test/java/org/apache/camel/quarkus/messaging/jms/AbstractJmsMessagingTest.java
index 071e803..6b0c427 100644
--- a/integration-tests/messaging/jms/src/test/java/org/apache/camel/quarkus/messaging/jms/AbstractJmsMessagingTest.java
+++ b/integration-tests/messaging/jms/src/test/java/org/apache/camel/quarkus/messaging/jms/AbstractJmsMessagingTest.java
@@ -16,7 +16,10 @@
*/
package org.apache.camel.quarkus.messaging.jms;
+import java.util.UUID;
+
import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
import org.apache.camel.quarkus.component.messaging.it.AbstractMessagingTest;
import org.junit.jupiter.api.Test;
@@ -81,4 +84,42 @@ public class AbstractJmsMessagingTest extends AbstractMessagingTest {
assertTrue(result.startsWith("converter prefix"));
assertTrue(result.endsWith("converter suffix"));
}
+
+ @Test
+ public void testJmsCustomDestination() {
+ String message = UUID.randomUUID().toString();
+
+ // Send a message with java.lang.String destination header
+ String destinationA = "queue-" + UUID.randomUUID().toString().split("-")[0];
+ RestAssured.given()
+ .queryParam("isStringDestination", "true")
+ .body(message)
+ .post("/messaging/jms/custom/destination/{destinationName}", destinationA)
+ .then()
+ .statusCode(201);
+
+ // Send a message with javax.jms.Destination destination header
+ String destinationB = "queue-" + UUID.randomUUID().toString().split("-")[0];
+ RestAssured.given()
+ .queryParam("isStringDestination", "false")
+ .body(message)
+ .post("/messaging/jms/custom/destination/{destinationName}", destinationB)
+ .then()
+ .statusCode(201);
+
+ // Verify messages sent to destinations
+ RestAssured.given()
+ .contentType(ContentType.TEXT)
+ .get("/messaging/{destinationName}", destinationA)
+ .then()
+ .statusCode(200)
+ .body(is(message));
+
+ RestAssured.given()
+ .contentType(ContentType.TEXT)
+ .get("/messaging/{destinationName}", destinationB)
+ .then()
+ .statusCode(200)
+ .body(is(message));
+ }
}
diff --git a/integration-tests/messaging/sjms/pom.xml b/integration-tests/messaging/sjms/pom.xml
index 890de28..f3929fb 100644
--- a/integration-tests/messaging/sjms/pom.xml
+++ b/integration-tests/messaging/sjms/pom.xml
@@ -32,6 +32,14 @@
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bean</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-direct</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-sjms</artifactId>
</dependency>
<dependency>
@@ -65,6 +73,32 @@
<!-- 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-bean-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-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-sjms-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
diff --git a/integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsRoutes.java b/integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsProducers.java
similarity index 53%
copy from integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsRoutes.java
copy to integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsProducers.java
index d8b215b..71c5bc3 100644
--- a/integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsRoutes.java
+++ b/integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsProducers.java
@@ -16,24 +16,26 @@
*/
package org.apache.camel.quarkus.messaging.sjms;
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
+import javax.inject.Named;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.quarkus.component.messaging.it.util.scheme.ComponentScheme;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.sjms.SjmsConstants;
-@ApplicationScoped
-public class SjmsRoutes extends RouteBuilder {
+public class SjmsProducers {
- @Inject
- ComponentScheme componentScheme;
+ @Named
+ public DestinationHeaderSetter destinationHeaderSetter() {
+ return new DestinationHeaderSetter();
+ }
- @Override
- public void configure() throws Exception {
- fromF("%s:queue:selectorA", componentScheme)
- .toF("%s:queue:selectorB", componentScheme);
+ @RegisterForReflection(fields = false)
+ static final class DestinationHeaderSetter {
- fromF("%s:queue:selectorB?messageSelector=foo='bar'", componentScheme)
- .to("mock:selectorResult");
+ public void setJmsDestinationHeader(Exchange exchange) {
+ org.apache.camel.Message message = exchange.getMessage();
+ String destinationName = message.getHeader("DestinationName", String.class);
+ message.setHeader(SjmsConstants.JMS_DESTINATION_NAME, destinationName);
+ }
}
}
diff --git a/integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsResource.java b/integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsResource.java
index d77dd49..f5ece21 100644
--- a/integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsResource.java
+++ b/integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsResource.java
@@ -16,9 +16,14 @@
*/
package org.apache.camel.quarkus.messaging.sjms;
+import java.net.URI;
+
import javax.inject.Inject;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Response;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
@@ -49,4 +54,13 @@ public class SjmsResource {
mockEndpoint.assertIsSatisfied(5000L);
}
+
+ @Path("/custom/destination/{destinationName}")
+ @POST
+ public Response produceMessageWithCustomDestination(
+ @PathParam("destinationName") String destinationName,
+ String message) throws Exception {
+ producerTemplate.sendBodyAndHeader("direct:computedDestination", message, "DestinationName", destinationName);
+ return Response.created(new URI("https://camel.apache.org/")).build();
+ }
}
diff --git a/integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsRoutes.java b/integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsRoutes.java
index d8b215b..abeeda9 100644
--- a/integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsRoutes.java
+++ b/integration-tests/messaging/sjms/src/main/java/org/apache/camel/quarkus/messaging/sjms/SjmsRoutes.java
@@ -35,5 +35,9 @@ public class SjmsRoutes extends RouteBuilder {
fromF("%s:queue:selectorB?messageSelector=foo='bar'", componentScheme)
.to("mock:selectorResult");
+
+ from("direct:computedDestination")
+ .bean("destinationHeaderSetter")
+ .toF("%s:queue:override", componentScheme);
}
}
diff --git a/integration-tests/messaging/sjms/src/test/java/org/apache/camel/quarkus/messaging/sjms/AbstractSjmsMessagingTest.java b/integration-tests/messaging/sjms/src/test/java/org/apache/camel/quarkus/messaging/sjms/AbstractSjmsMessagingTest.java
index d12ae97..bde0e65 100644
--- a/integration-tests/messaging/sjms/src/test/java/org/apache/camel/quarkus/messaging/sjms/AbstractSjmsMessagingTest.java
+++ b/integration-tests/messaging/sjms/src/test/java/org/apache/camel/quarkus/messaging/sjms/AbstractSjmsMessagingTest.java
@@ -16,10 +16,15 @@
*/
package org.apache.camel.quarkus.messaging.sjms;
+import java.util.UUID;
+
import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
import org.apache.camel.quarkus.component.messaging.it.AbstractMessagingTest;
import org.junit.jupiter.api.Test;
+import static org.hamcrest.core.Is.is;
+
public class AbstractSjmsMessagingTest extends AbstractMessagingTest {
@Test
@@ -30,4 +35,25 @@ public class AbstractSjmsMessagingTest extends AbstractMessagingTest {
.then()
.statusCode(204);
}
+
+ @Test
+ public void testJmsCustomDestination() {
+ String message = UUID.randomUUID().toString();
+
+ // Send a message
+ String destination = "queue-" + UUID.randomUUID().toString().split("-")[0];
+ RestAssured.given()
+ .body(message)
+ .post("/messaging/sjms/custom/destination/{destinationName}", destination)
+ .then()
+ .statusCode(201);
+
+ // Verify message sent to destination
+ RestAssured.given()
+ .contentType(ContentType.TEXT)
+ .get("/messaging/{destinationName}", destination)
+ .then()
+ .statusCode(200)
+ .body(is(message));
+ }
}