You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2018/08/16 08:45:35 UTC
[camel] branch master updated: CAMEL-12520: FluentProducerTemplate
withExchange is only allowed for send method.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 5f328df CAMEL-12520: FluentProducerTemplate withExchange is only allowed for send method.
5f328df is described below
commit 5f328df79e74145124daff5b3a69638cb05937c1
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 16 10:45:20 2018 +0200
CAMEL-12520: FluentProducerTemplate withExchange is only allowed for send method.
---
.../org/apache/camel/FluentProducerTemplate.java | 4 ++++
.../builder/DefaultFluentProducerTemplate.java | 4 ++++
.../camel/builder/FluentProducerTemplateTest.java | 24 ++++++++++++++++++++++
3 files changed, 32 insertions(+)
diff --git a/camel-core/src/main/java/org/apache/camel/FluentProducerTemplate.java b/camel-core/src/main/java/org/apache/camel/FluentProducerTemplate.java
index 3a37890..87d4044 100644
--- a/camel-core/src/main/java/org/apache/camel/FluentProducerTemplate.java
+++ b/camel-core/src/main/java/org/apache/camel/FluentProducerTemplate.java
@@ -201,6 +201,8 @@ public interface FluentProducerTemplate extends Service {
/**
* Set the exchange to use for send.
*
+ * When using withExchange then you must use the send method (request is not supported).
+ *
* @param exchange the exchange
*/
FluentProducerTemplate withExchange(Exchange exchange);
@@ -209,6 +211,8 @@ public interface FluentProducerTemplate extends Service {
* Set the exchangeSupplier which will be invoke to get the exchange to be
* used for send.
*
+ * When using withExchange then you must use the send method (request is not supported).
+ *
* @param exchangeSupplier the supplier
*/
FluentProducerTemplate withExchange(Supplier<Exchange> exchangeSupplier);
diff --git a/camel-core/src/main/java/org/apache/camel/builder/DefaultFluentProducerTemplate.java b/camel-core/src/main/java/org/apache/camel/builder/DefaultFluentProducerTemplate.java
index b59af2f..ccfdda9 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/DefaultFluentProducerTemplate.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/DefaultFluentProducerTemplate.java
@@ -230,6 +230,10 @@ public class DefaultFluentProducerTemplate extends ServiceSupport implements Flu
@Override
@SuppressWarnings("unchecked")
public <T> T request(Class<T> type) throws CamelExecutionException {
+ if (exchangeSupplier.isPresent()) {
+ throw new IllegalArgumentException("withExchange not supported on FluentProducerTemplate.request method. Use send method instead.");
+ }
+
// Determine the target endpoint
final Endpoint target = target();
diff --git a/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java b/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
index 660e86d..570efd4 100644
--- a/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
+++ b/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
@@ -260,6 +260,30 @@ public class FluentProducerTemplateTest extends ContextTestSupport {
assertMockEndpointsSatisfied();
}
+ public void testWithExchange() throws Exception {
+ Exchange exchange = ExchangeBuilder.anExchange(context)
+ .withBody("Hello!")
+ .withPattern(ExchangePattern.InOut)
+ .build();
+
+ exchange = context.createFluentProducerTemplate()
+ .withExchange(exchange)
+ .to("direct:in")
+ .send();
+
+ assertEquals("Bye World", exchange.getMessage().getBody());
+
+ try {
+ String out = context.createFluentProducerTemplate()
+ .withExchange(exchange)
+ .to("direct:in")
+ .request(String.class);
+ fail("Should throw exception");
+ } catch (IllegalArgumentException e) {
+ assertEquals("withExchange not supported on FluentProducerTemplate.request method. Use send method instead.", e.getMessage());
+ }
+ }
+
public void testRequestBody() throws Exception {
// with endpoint as string uri
FluentProducerTemplate template = DefaultFluentProducerTemplate.on(context);