You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/12/17 08:08:29 UTC

[camel] branch master updated: CAMEL-14300: Java 8 Supplier overloadings break all DSLs (remove methods)

This is an automated email from the ASF dual-hosted git repository.

lburgazzoli 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 6310cb7  CAMEL-14300: Java 8 Supplier overloadings break all DSLs (remove methods)
6310cb7 is described below

commit 6310cb785a4b925b22a655fb710b7f0652b7dbd8
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Dec 16 23:33:06 2019 +0100

    CAMEL-14300: Java 8 Supplier overloadings break all DSLs (remove methods)
---
 .../org/apache/camel/builder/ExpressionClause.java | 15 -------
 .../apache/camel/model/MulticastDefinition.java    | 17 --------
 .../apache/camel/model/ProcessorDefinition.java    | 37 -----------------
 .../camel/model/RecipientListDefinition.java       | 17 --------
 .../org/apache/camel/model/SplitDefinition.java    | 17 --------
 .../org/apache/camel/model/WireTapDefinition.java  | 34 ---------------
 .../builder/ExpressionClauseSupplierTest.java      | 48 ----------------------
 .../camel/model/ProcessDefinitionSetBodyTest.java  | 13 +++---
 .../camel/processor/SplitterOnPrepareTest.java     |  2 +-
 .../modules/ROOT/pages/camel-3x-upgrade-guide.adoc | 16 ++++++++
 10 files changed, 22 insertions(+), 194 deletions(-)

diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/builder/ExpressionClause.java b/core/camel-core-engine/src/main/java/org/apache/camel/builder/ExpressionClause.java
index beac72e..ff2f968 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/builder/ExpressionClause.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/builder/ExpressionClause.java
@@ -19,7 +19,6 @@ package org.apache.camel.builder;
 import java.util.Map;
 import java.util.function.BiFunction;
 import java.util.function.Function;
-import java.util.function.Supplier;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
@@ -129,20 +128,6 @@ public class ExpressionClause<T> implements Expression, Predicate {
     }
 
     /**
-     * A functional expression of an inbound message body
-     *
-     * @deprecated see https://issues.apache.org/jira/browse/CAMEL-14300
-     */
-    @Deprecated
-    public T body(final Supplier<Object> supplier) {
-        return delegate.expression(new ExpressionAdapter() {
-            public Object evaluate(Exchange exchange) {
-                return supplier.get();
-            }
-        });
-    }
-
-    /**
      * A functional expression of an inbound message body and headers
      */
     public T body(final BiFunction<Object, Map<String, Object>, Object> function) {
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/model/MulticastDefinition.java b/core/camel-core-engine/src/main/java/org/apache/camel/model/MulticastDefinition.java
index 036d346..79d9233 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/model/MulticastDefinition.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/model/MulticastDefinition.java
@@ -311,23 +311,6 @@ public class MulticastDefinition extends OutputDefinition<MulticastDefinition> i
      * deep-clone messages that should be send, or any custom logic needed
      * before the exchange is send.
      *
-     * @param onPrepare the processor
-     * @return the builder
-     *
-     * @deprecated see https://issues.apache.org/jira/browse/CAMEL-14300
-     */
-    @Deprecated
-    public MulticastDefinition onPrepare(Supplier<Processor> onPrepare) {
-        setOnPrepare(onPrepare.get());
-        return this;
-    }
-
-    /**
-     * Uses the {@link Processor} when preparing the
-     * {@link org.apache.camel.Exchange} to be send. This can be used to
-     * deep-clone messages that should be send, or any custom logic needed
-     * before the exchange is send.
-     *
      * @param onPrepareRef reference to the processor to lookup in the
      *            {@link org.apache.camel.spi.Registry}
      * @return the builder
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-engine/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 84afc50..5535384 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -2408,21 +2408,6 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
 
     /**
      * <a href="http://camel.apache.org/message-translator.html">Message
-     * Translator EIP:</a> Adds the custom processor to this destination which
-     * could be a final destination, or could be a transformation in a pipeline
-     *
-     * @param processor the custom {@link Processor}
-     * @return the builder
-     *
-     * @deprecated see https://issues.apache.org/jira/browse/CAMEL-14300
-     */
-    @Deprecated
-    public Type process(Supplier<Processor> processor) {
-        return process(processor.get());
-    }
-
-    /**
-     * <a href="http://camel.apache.org/message-translator.html">Message
      * Translator EIP:</a> Adds the custom processor reference to this
      * destination which could be a final destination, or could be a
      * transformation in a pipeline
@@ -2666,28 +2651,6 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
      * Translator EIP:</a> Adds a processor which sets the body on the IN
      * message
      *
-     * @param supplier the supplier that provides a value to the IN message body
-     * @return the builder
-     *
-     * @deprecated see https://issues.apache.org/jira/browse/CAMEL-14300
-     */
-    @Deprecated
-    public <Result> Type setBody(Supplier<Result> supplier) {
-        SetBodyDefinition answer = new SetBodyDefinition(new ExpressionAdapter() {
-            @Override
-            public Result evaluate(Exchange exchange) {
-                return supplier.get();
-            }
-        });
-        addOutput(answer);
-        return asType();
-    }
-
-    /**
-     * <a href="http://camel.apache.org/message-translator.html">Message
-     * Translator EIP:</a> Adds a processor which sets the body on the IN
-     * message
-     *
      * @param function the function that provides a value to the IN message body
      * @return the builder
      */
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/model/RecipientListDefinition.java b/core/camel-core-engine/src/main/java/org/apache/camel/model/RecipientListDefinition.java
index ed31bd0..098e6a0 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/model/RecipientListDefinition.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/model/RecipientListDefinition.java
@@ -323,23 +323,6 @@ public class RecipientListDefinition<Type extends ProcessorDefinition<Type>> ext
     }
 
     /**
-     * Uses the {@link Processor} when preparing the
-     * {@link org.apache.camel.Exchange} to be used send. This can be used to
-     * deep-clone messages that should be send, or any custom logic needed
-     * before the exchange is send.
-     *
-     * @param onPrepare the processor
-     * @return the builder
-     *
-     * @deprecated see https://issues.apache.org/jira/browse/CAMEL-14300
-     */
-    @Deprecated
-    public RecipientListDefinition<Type> onPrepare(Supplier<Processor> onPrepare) {
-        setOnPrepare(onPrepare.get());
-        return this;
-    }
-
-    /**
      * Sets the {@link Processor} when preparing the
      * {@link org.apache.camel.Exchange} to be used send using a fluent buidler.
      */
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/model/SplitDefinition.java b/core/camel-core-engine/src/main/java/org/apache/camel/model/SplitDefinition.java
index b8a95f3..a9cb69c 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/model/SplitDefinition.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/model/SplitDefinition.java
@@ -302,23 +302,6 @@ public class SplitDefinition extends OutputExpressionNode implements ExecutorSer
      * deep-clone messages that should be send, or any custom logic needed
      * before the exchange is send.
      *
-     * @param onPrepare the processor
-     * @return the builder
-     *
-     * @deprecated see https://issues.apache.org/jira/browse/CAMEL-14300
-     */
-    @Deprecated
-    public SplitDefinition onPrepare(Supplier<Processor> onPrepare) {
-        setOnPrepare(onPrepare.get());
-        return this;
-    }
-
-    /**
-     * Uses the {@link Processor} when preparing the
-     * {@link org.apache.camel.Exchange} to be send. This can be used to
-     * deep-clone messages that should be send, or any custom logic needed
-     * before the exchange is send.
-     *
      * @param onPrepareRef reference to the processor to lookup in the
      *            {@link org.apache.camel.spi.Registry}
      * @return the builder
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/model/WireTapDefinition.java b/core/camel-core-engine/src/main/java/org/apache/camel/model/WireTapDefinition.java
index 6cce273..fff5e7b 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/model/WireTapDefinition.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/model/WireTapDefinition.java
@@ -19,7 +19,6 @@ package org.apache.camel.model;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
-import java.util.function.Supplier;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -209,22 +208,6 @@ public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends T
     }
 
     /**
-     * Sends a <i>new</i> Exchange, instead of tapping an existing, using
-     * {@link ExchangePattern#InOnly}
-     *
-     * @param processor processor preparing the new exchange to send
-     * @return the builder
-     * @see #newExchangeHeader(String, org.apache.camel.Expression)
-     *
-     * @deprecated see https://issues.apache.org/jira/browse/CAMEL-14300
-     */
-    @Deprecated
-    public WireTapDefinition<Type> newExchange(Supplier<Processor> processor) {
-        setNewExchangeProcessor(processor.get());
-        return this;
-    }
-
-    /**
      * Sets a header on the <i>new</i> Exchange, instead of tapping an existing,
      * using {@link ExchangePattern#InOnly}.
      * <p/>
@@ -261,23 +244,6 @@ public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends T
      * deep-clone messages that should be send, or any custom logic needed
      * before the exchange is send.
      *
-     * @param onPrepare the processor
-     * @return the builder
-     *
-     * @deprecated see https://issues.apache.org/jira/browse/CAMEL-14300
-     */
-    @Deprecated
-    public WireTapDefinition<Type> onPrepare(Supplier<Processor> onPrepare) {
-        setOnPrepare(onPrepare.get());
-        return this;
-    }
-
-    /**
-     * Uses the {@link Processor} when preparing the
-     * {@link org.apache.camel.Exchange} to be send. This can be used to
-     * deep-clone messages that should be send, or any custom logic needed
-     * before the exchange is send.
-     *
      * @param onPrepareRef reference to the processor to lookup in the
      *            {@link org.apache.camel.spi.Registry}
      * @return the builder
diff --git a/core/camel-core/src/test/java/org/apache/camel/builder/ExpressionClauseSupplierTest.java b/core/camel-core/src/test/java/org/apache/camel/builder/ExpressionClauseSupplierTest.java
deleted file mode 100644
index b923d22..0000000
--- a/core/camel-core/src/test/java/org/apache/camel/builder/ExpressionClauseSupplierTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.builder;
-
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.junit.Test;
-
-public class ExpressionClauseSupplierTest extends ContextTestSupport {
-
-    private static final String BODY_SUPPLIER_MSG = "I am the body supplier!";
-
-    @Test
-    public void testBodySupplier() throws Exception {
-        MockEndpoint functionMock1 = getMockEndpoint("mock:output1");
-        functionMock1.expectedMessageCount(1);
-        functionMock1.expectedBodyReceived().constant(BODY_SUPPLIER_MSG);
-
-        template.sendBody("direct:supplier1", "are you there?");
-
-        assertMockEndpointsSatisfied();
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("direct:supplier1").transform().body(() -> BODY_SUPPLIER_MSG).to("mock:output1");
-            }
-        };
-    }
-
-}
diff --git a/core/camel-core/src/test/java/org/apache/camel/model/ProcessDefinitionSetBodyTest.java b/core/camel-core/src/test/java/org/apache/camel/model/ProcessDefinitionSetBodyTest.java
index b42774f..c750858 100644
--- a/core/camel-core/src/test/java/org/apache/camel/model/ProcessDefinitionSetBodyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/model/ProcessDefinitionSetBodyTest.java
@@ -28,13 +28,9 @@ public class ProcessDefinitionSetBodyTest extends ContextTestSupport {
 
     @Test
     public void testProcessDefinitionSetBody() throws InterruptedException {
-
-        MockEndpoint functionMock1 = getMockEndpoint("mock:supplierOutput");
-        functionMock1.expectedMessageCount(1);
-        functionMock1.expectedBodyReceived().constant(SUPPLIER_MESSAGE);
-        MockEndpoint functionMock2 = getMockEndpoint("mock:functionOutput");
-        functionMock2.expectedMessageCount(1);
-        functionMock2.expectedBodyReceived().constant(FUNCTION_MESSAGE);
+        MockEndpoint mock = getMockEndpoint("mock:functionOutput");
+        mock.expectedMessageCount(1);
+        mock.expectedBodyReceived().constant(FUNCTION_MESSAGE);
 
         template.sendBody("direct:start", "are you there?");
 
@@ -46,7 +42,8 @@ public class ProcessDefinitionSetBodyTest extends ContextTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start").setBody(() -> SUPPLIER_MESSAGE).to("mock:supplierOutput").setBody(exchange -> FUNCTION_MESSAGE).to("mock:functionOutput").to("mock:output");
+                from("direct:start")
+                    .setBody(exchange -> FUNCTION_MESSAGE).to("mock:functionOutput").to("mock:output");
             }
         };
     }
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/SplitterOnPrepareTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/SplitterOnPrepareTest.java
index 10d363c..cca3643 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/SplitterOnPrepareTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/SplitterOnPrepareTest.java
@@ -48,7 +48,7 @@ public class SplitterOnPrepareTest extends ContextTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start").split(body()).onPrepare(FixNamePrepare::new).to("direct:a");
+                from("direct:start").split(body()).onPrepare(new FixNamePrepare()).to("direct:a");
 
                 from("direct:a").process(new ProcessorA()).to("mock:a");
             }
diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc
index fd24dd3..be9d6c9 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc
@@ -46,3 +46,19 @@ nsq:myTopic?servers=myserver:4161
 
 This change is motivated by allowing to configure servers on component level,
 and also for Spring Boot auto-configuration etc.
+
+
+=== Java DSL
+
+The Java DSL has been revisited and the following methods have been removed:
+
+* ExpressionClause::body(Supplier<Object>)
+* MulticastDefinition::onPrepare(Supplier<Processor>)
+* ProcessorDefinition::process(Supplier<Processor>)
+* ProcessorDefinition::setBody(Supplier<Result>)
+* RecipientListDefinition::onPrepare(Supplier<Processor>)
+* SplitDefinition::onPrepare(Supplier<Processor>)
+* WireTapDefinition::newExchange(Supplier<Processor>)
+* WireTapDefinition::onPrepare(Supplier<Processor>)
+
+This change is motivated by the need to remove method ambiguity for untyped languages such as Groovy and JavaScript, for more info see https://issues.apache.org/jira/browse/CAMEL-14300