You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/01/07 08:33:04 UTC
[camel] branch camel-3.0.x updated: Add support for toF to
FluentProducerTemplate
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch camel-3.0.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.0.x by this push:
new 6a2d734 Add support for toF to FluentProducerTemplate
6a2d734 is described below
commit 6a2d7342ccf225bcec36e7e56d1d5520bdc64374
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Jan 6 13:34:13 2020 +0100
Add support for toF to FluentProducerTemplate
---
.../org/apache/camel/FluentProducerTemplate.java | 20 ++++++++++++++++++--
.../camel/builder/FluentProducerTemplateTest.java | 17 +++++++++++++++++
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/core/camel-api/src/main/java/org/apache/camel/FluentProducerTemplate.java b/core/camel-api/src/main/java/org/apache/camel/FluentProducerTemplate.java
index e34da3b..af19126 100644
--- a/core/camel-api/src/main/java/org/apache/camel/FluentProducerTemplate.java
+++ b/core/camel-api/src/main/java/org/apache/camel/FluentProducerTemplate.java
@@ -19,6 +19,8 @@ package org.apache.camel;
import java.util.concurrent.Future;
import java.util.function.Supplier;
+import org.apache.camel.util.ObjectHelper;
+
/**
* Template for working with Camel and sending {@link Message} instances in an
* {@link Exchange} to an {@link Endpoint} using a <i>fluent</i> build style.
@@ -234,7 +236,7 @@ public interface FluentProducerTemplate extends Service {
* .request()}
* </pre>
*
- * @param processor
+ * @param processor
*/
FluentProducerTemplate withProcessor(Processor processor);
@@ -251,7 +253,21 @@ public interface FluentProducerTemplate extends Service {
*
* @param endpointUri the endpoint URI to send to
*/
- FluentProducerTemplate to(String endpointUri);
+ default FluentProducerTemplate to(String endpointUri) {
+ final CamelContext context = ObjectHelper.notNull(getCamelContext(), "camel context");
+
+ return to(context.getEndpoint(endpointUri));
+ }
+
+ /**
+ * Endpoint to send to
+ *
+ * @param uri the String formatted endpoint uri to send to
+ * @param args arguments for the string formatting of the uri
+ */
+ default FluentProducerTemplate toF(String uri, Object... args) {
+ return to(String.format(uri, args));
+ }
/**
* Endpoint to send to
diff --git a/core/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java b/core/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
index b5512a5..d4b3f7f 100644
--- a/core/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
@@ -85,6 +85,23 @@ public class FluentProducerTemplateTest extends ContextTestSupport {
}
@Test
+ public void testToF() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Bye World");
+
+ FluentProducerTemplate on = DefaultFluentProducerTemplate.on(context);
+ on.withBody("Hello World");
+ on.toF("direct:%s", "in");
+ Object result = on.request();
+
+ assertMockEndpointsSatisfied();
+
+ assertEquals("Bye World", result);
+
+ assertSame(context, template.getCamelContext());
+ }
+
+ @Test
public void testIn() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Bye World");