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 2023/03/15 09:57:59 UTC

[camel] branch camel-3.18.x updated: CAMEL-19151: WireTap to support ignore invalid endpoint for static urls also

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

davsclaus pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.18.x by this push:
     new 83f8af3643a CAMEL-19151: WireTap to support ignore invalid endpoint for static urls also
83f8af3643a is described below

commit 83f8af3643a952da845768ddec2a2551aaab14a3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 15 10:57:00 2023 +0100

    CAMEL-19151: WireTap to support ignore invalid endpoint for static urls also
---
 .../org/apache/camel/catalog/models/toD.json       |  2 +-
 .../org/apache/camel/catalog/models/wireTap.json   |  2 +-
 .../resources/org/apache/camel/model/toD.json      |  2 +-
 .../resources/org/apache/camel/model/wireTap.json  |  2 +-
 .../apache/camel/model/ToDynamicDefinition.java    |  6 +--
 .../org/apache/camel/reifier/WireTapReifier.java   |  5 ++-
 .../WireTapIgnoreInvalidEndpointTest.java          | 47 ++++++++++++++++++++++
 7 files changed, 56 insertions(+), 10 deletions(-)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/toD.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/toD.json
index 0f6be91bcd0..73df24f67d1 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/toD.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/toD.json
@@ -15,7 +15,7 @@
     "uri": { "kind": "attribute", "displayName": "Uri", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The uri of the endpoint to send to. The uri can be dynamic computed using the org.apache.camel.language.simple.SimpleLanguage expression." },
     "pattern": { "kind": "attribute", "displayName": "Pattern", "label": "advanced", "required": false, "type": "enum", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut", "InOptionalOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the optional ExchangePattern used to invoke this endpoint" },
     "cacheSize": { "kind": "attribute", "displayName": "Cache Size", "label": "advanced", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the maximum size used by the org.apache.camel.spi.ProducerCache which is used to cache and reuse producers when using this recipient list, when uris are reused. Beware that when using dynamic endpoints then it affects how well the cache can be utilized [...]
-    "ignoreInvalidEndpoint": { "kind": "attribute", "displayName": "Ignore Invalid Endpoint", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "For dynamic endpoints then this option can be used to ignore invalid dynamic endpoints. This option is only in use if dynamic is enabled and the endpoint uri is also dynamic (using ${ } style)" },
+    "ignoreInvalidEndpoint": { "kind": "attribute", "displayName": "Ignore Invalid Endpoint", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to ignore invalid endpoint URIs and skip sending the message." },
     "allowOptimisedComponents": { "kind": "attribute", "displayName": "Allow Optimised Components", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to allow components to optimise toD if they are org.apache.camel.spi.SendDynamicAware ." },
     "autoStartComponents": { "kind": "attribute", "displayName": "Auto Start Components", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to auto startup components when toD is starting up." },
     "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" },
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/wireTap.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/wireTap.json
index df6667d2087..d9c0c6839d5 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/wireTap.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/wireTap.json
@@ -19,7 +19,7 @@
     "uri": { "kind": "attribute", "displayName": "Uri", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The uri of the endpoint to send to. The uri can be dynamic computed using the org.apache.camel.language.simple.SimpleLanguage expression." },
     "pattern": { "kind": "attribute", "displayName": "Pattern", "label": "advanced", "required": false, "type": "enum", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut", "InOptionalOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the optional ExchangePattern used to invoke this endpoint" },
     "cacheSize": { "kind": "attribute", "displayName": "Cache Size", "label": "advanced", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the maximum size used by the org.apache.camel.spi.ProducerCache which is used to cache and reuse producers when using this recipient list, when uris are reused. Beware that when using dynamic endpoints then it affects how well the cache can be utilized [...]
-    "ignoreInvalidEndpoint": { "kind": "attribute", "displayName": "Ignore Invalid Endpoint", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "For dynamic endpoints then this option can be used to ignore invalid dynamic endpoints. This option is only in use if dynamic is enabled and the endpoint uri is also dynamic (using ${ } style)" },
+    "ignoreInvalidEndpoint": { "kind": "attribute", "displayName": "Ignore Invalid Endpoint", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to ignore invalid endpoint URIs and skip sending the message." },
     "allowOptimisedComponents": { "kind": "attribute", "displayName": "Allow Optimised Components", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to allow components to optimise toD if they are org.apache.camel.spi.SendDynamicAware ." },
     "autoStartComponents": { "kind": "attribute", "displayName": "Auto Start Components", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to auto startup components when toD is starting up." },
     "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" },
diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/toD.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/toD.json
index 0f6be91bcd0..73df24f67d1 100644
--- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/toD.json
+++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/toD.json
@@ -15,7 +15,7 @@
     "uri": { "kind": "attribute", "displayName": "Uri", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The uri of the endpoint to send to. The uri can be dynamic computed using the org.apache.camel.language.simple.SimpleLanguage expression." },
     "pattern": { "kind": "attribute", "displayName": "Pattern", "label": "advanced", "required": false, "type": "enum", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut", "InOptionalOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the optional ExchangePattern used to invoke this endpoint" },
     "cacheSize": { "kind": "attribute", "displayName": "Cache Size", "label": "advanced", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the maximum size used by the org.apache.camel.spi.ProducerCache which is used to cache and reuse producers when using this recipient list, when uris are reused. Beware that when using dynamic endpoints then it affects how well the cache can be utilized [...]
-    "ignoreInvalidEndpoint": { "kind": "attribute", "displayName": "Ignore Invalid Endpoint", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "For dynamic endpoints then this option can be used to ignore invalid dynamic endpoints. This option is only in use if dynamic is enabled and the endpoint uri is also dynamic (using ${ } style)" },
+    "ignoreInvalidEndpoint": { "kind": "attribute", "displayName": "Ignore Invalid Endpoint", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to ignore invalid endpoint URIs and skip sending the message." },
     "allowOptimisedComponents": { "kind": "attribute", "displayName": "Allow Optimised Components", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to allow components to optimise toD if they are org.apache.camel.spi.SendDynamicAware ." },
     "autoStartComponents": { "kind": "attribute", "displayName": "Auto Start Components", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to auto startup components when toD is starting up." },
     "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" },
diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/wireTap.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/wireTap.json
index df6667d2087..d9c0c6839d5 100644
--- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/wireTap.json
+++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/wireTap.json
@@ -19,7 +19,7 @@
     "uri": { "kind": "attribute", "displayName": "Uri", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The uri of the endpoint to send to. The uri can be dynamic computed using the org.apache.camel.language.simple.SimpleLanguage expression." },
     "pattern": { "kind": "attribute", "displayName": "Pattern", "label": "advanced", "required": false, "type": "enum", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut", "InOptionalOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the optional ExchangePattern used to invoke this endpoint" },
     "cacheSize": { "kind": "attribute", "displayName": "Cache Size", "label": "advanced", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the maximum size used by the org.apache.camel.spi.ProducerCache which is used to cache and reuse producers when using this recipient list, when uris are reused. Beware that when using dynamic endpoints then it affects how well the cache can be utilized [...]
-    "ignoreInvalidEndpoint": { "kind": "attribute", "displayName": "Ignore Invalid Endpoint", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "For dynamic endpoints then this option can be used to ignore invalid dynamic endpoints. This option is only in use if dynamic is enabled and the endpoint uri is also dynamic (using ${ } style)" },
+    "ignoreInvalidEndpoint": { "kind": "attribute", "displayName": "Ignore Invalid Endpoint", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to ignore invalid endpoint URIs and skip sending the message." },
     "allowOptimisedComponents": { "kind": "attribute", "displayName": "Allow Optimised Components", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to allow components to optimise toD if they are org.apache.camel.spi.SendDynamicAware ." },
     "autoStartComponents": { "kind": "attribute", "displayName": "Auto Start Components", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to auto startup components when toD is starting up." },
     "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" },
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ToDynamicDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ToDynamicDefinition.java
index e1bc777c781..962fedafea1 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ToDynamicDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ToDynamicDefinition.java
@@ -164,16 +164,14 @@ public class ToDynamicDefinition extends NoOutputDefinition<ToDynamicDefinition>
     }
 
     /**
-     * For dynamic endpoints then this option can be used to ignore invalid dynamic endpoints. This option is only in use
-     * if dynamic is enabled and the endpoint uri is also dynamic (using ${ } style)
+     * Whether to ignore invalid endpoint URIs and skip sending the message.
      */
     public ToDynamicDefinition ignoreInvalidEndpoint(boolean ignoreInvalidEndpoint) {
         return ignoreInvalidEndpoint(Boolean.toString(ignoreInvalidEndpoint));
     }
 
     /**
-     * For dynamic endpoints then this option can be used to ignore invalid dynamic endpoints. This option is only in use
-     * if dynamic is enabled and the endpoint uri is also dynamic (using ${ } style)
+     * Whether to ignore invalid endpoint URIs and skip sending the message.
      */
     public ToDynamicDefinition ignoreInvalidEndpoint(String ignoreInvalidEndpoint) {
         setIgnoreInvalidEndpoint(ignoreInvalidEndpoint);
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java
index 79f2577d5a6..e550807a641 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java
@@ -71,8 +71,9 @@ public class WireTapReifier extends ToDynamicReifier<WireTapDefinition<?>> {
         SendProcessor sendProcessor = null;
         boolean simple = LanguageSupport.hasSimpleFunction(uri);
         boolean dynamic = parseBoolean(definition.getDynamicUri(), true);
-        if (dynamic && simple) {
-            // dynamic so we need the dynamic send processor
+        boolean invalid = parseBoolean(definition.getIgnoreInvalidEndpoint(), false);
+        if (dynamic && simple || invalid) {
+            // dynamic or ignore-invalid so we need the dynamic send processor
             dynamicSendProcessor = (SendDynamicProcessor) super.createProcessor();
         } else {
             // static so we can use a plain send processor
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/WireTapIgnoreInvalidEndpointTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/WireTapIgnoreInvalidEndpointTest.java
new file mode 100644
index 00000000000..7daf78b2f01
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/WireTapIgnoreInvalidEndpointTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Wire tap unit test
+ */
+public class WireTapIgnoreInvalidEndpointTest extends ContextTestSupport {
+
+    @Test
+    public void testIgnoreInvalid() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start")
+                        .wireTap("xxx:invalid").ignoreInvalidEndpoint()
+                        .to("mock:result");
+            }
+        };
+    }
+}