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/08/23 15:37:37 UTC

[camel] branch camel-4.0.x updated (0104d370795 -> 42ff9febcab)

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

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


    from 0104d370795 CAMEL-19777: Fix usage of FQQN with toD (#11178)
     new 9289b3af6e7 Fixes (#11189)
     new f30849ac25f Delete test that cant compile
     new a8d3d48e925 CAMEL-19785: camel-yaml-dsl - Order of beans should not matter
     new 42ff9febcab Regen

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../http/HttpProducerWithSpecialCharsBodyTest.java | 104 ---------------------
 .../camel/main/MainDurationEventNotifier.java      |   3 +-
 .../camel/support/PropertyBindingSupport.java      |   4 +
 .../java/org/apache/camel/util/SensitiveUtils.java |   2 +-
 .../dsl/yaml/deserializers/BeansDeserializer.java  |  65 +++++++++----
 5 files changed, 54 insertions(+), 124 deletions(-)
 delete mode 100644 components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerWithSpecialCharsBodyTest.java


[camel] 01/04: Fixes (#11189)

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9289b3af6e77663c1b6f5d9e288f06b1dbdfdf31
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Aug 23 17:17:08 2023 +0200

    Fixes (#11189)
    
    * CAMEL-19784: camel-core - PropertyBindingSupport - mandatory reference should fail if cannot resolve bean
    
    * Regen
    
    * CAMEL-19785: camel-yaml-dsl - Order of beans should not matter
---
 .../camel/support/PropertyBindingSupport.java      |  4 ++
 .../dsl/yaml/deserializers/BeansDeserializer.java  | 71 ++++++++++++++++------
 2 files changed, 56 insertions(+), 19 deletions(-)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 1b2f7ee6d84..67d0a8179f4 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -542,6 +542,10 @@ public final class PropertyBindingSupport {
                 // resolve property placeholders
                 str = camelContext.resolvePropertyPlaceholders(str.toString());
             }
+            if (str == null && reference && mandatory && !optional) {
+                // we could not resolve the reference and this is mandatory
+                throw new PropertyBindingException(target, key, value);
+            }
             value = str;
         } catch (Exception e) {
             // report the exception using the long key and parent target
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/BeansDeserializer.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/BeansDeserializer.java
index e4bb570b140..7425de959f4 100644
--- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/BeansDeserializer.java
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/BeansDeserializer.java
@@ -17,13 +17,12 @@
 package org.apache.camel.dsl.yaml.deserializers;
 
 import java.util.ArrayList;
-import java.util.List;
 
-import org.apache.camel.CamelContext;
 import org.apache.camel.dsl.yaml.common.YamlDeserializationContext;
 import org.apache.camel.dsl.yaml.common.YamlDeserializerResolver;
 import org.apache.camel.dsl.yaml.common.YamlDeserializerSupport;
 import org.apache.camel.dsl.yaml.common.YamlSupport;
+import org.apache.camel.model.Model;
 import org.apache.camel.model.app.RegistryBeanDefinition;
 import org.apache.camel.spi.CamelContextCustomizer;
 import org.apache.camel.spi.annotations.YamlIn;
@@ -46,8 +45,8 @@ import org.snakeyaml.engine.v2.nodes.SequenceNode;
 public class BeansDeserializer extends YamlDeserializerSupport implements ConstructNode {
     @Override
     public Object construct(Node node) {
+        final BeansCustomizer answer = new BeansCustomizer();
         final SequenceNode sn = asSequenceNode(node);
-        final List<CamelContextCustomizer> customizers = new ArrayList<>();
         final YamlDeserializationContext dc = getDeserializationContext(node);
 
         for (Node item : sn.getValue()) {
@@ -61,24 +60,10 @@ public class BeansDeserializer extends YamlDeserializerSupport implements Constr
                 bean.setType("#class:" + bean.getType());
             }
 
-            customizers.add(new CamelContextCustomizer() {
-                @Override
-                public void configure(CamelContext camelContext) {
-                    try {
-                        // to support hot reloading of beans then we need to unbind old existing first
-                        String name = bean.getName();
-                        camelContext.getRegistry().unbind(name);
-                        camelContext.getRegistry().bind(
-                                name,
-                                newInstance(bean, camelContext));
-                    } catch (Exception e) {
-                        throw new RuntimeException(e);
-                    }
-                }
-            });
+            answer.addBean(bean);
         }
 
-        return YamlSupport.customizer(customizers);
+        return answer;
     }
 
     public Object newInstance(RegistryBeanDefinition bean, CamelContext context) throws Exception {
@@ -91,4 +76,52 @@ public class BeansDeserializer extends YamlDeserializerSupport implements Constr
         return target;
     }
 
+    protected void registerBean(
+            CamelContext camelContext,
+            List<RegistryBeanDefinition> delayedRegistrations,
+            RegistryBeanDefinition def, boolean delayIfFailed) {
+        try {
+            // to support hot reloading of beans then we need to unbind old existing first
+            String name = def.getName();
+            Object bean = newInstance(def, camelContext);
+            camelContext.getRegistry().unbind(name);
+            camelContext.getRegistry().bind(name, bean);
+
+            // register bean in model
+            Model model = camelContext.getCamelContextExtension().getContextPlugin(Model.class);
+            model.addRegistryBean(def);
+
+        } catch (Exception e) {
+            if (delayIfFailed) {
+                delayedRegistrations.add(def);
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    private class BeansCustomizer implements CamelContextCustomizer {
+
+        private final List<RegistryBeanDefinition> delayedRegistrations = new ArrayList<>();
+        private final List<RegistryBeanDefinition> beans = new ArrayList<>();
+
+        public void addBean(RegistryBeanDefinition bean) {
+            beans.add(bean);
+        }
+
+        @Override
+        public void configure(CamelContext camelContext) {
+            // first-pass of creating beans
+            for (RegistryBeanDefinition bean : beans) {
+                registerBean(camelContext, delayedRegistrations, bean, true);
+            }
+            beans.clear();
+            // second-pass of creating beans should fail if not possible
+            for (RegistryBeanDefinition bean : delayedRegistrations) {
+                registerBean(camelContext, delayedRegistrations, bean, false);
+            }
+            delayedRegistrations.clear();
+        }
+    }
+
 }


[camel] 04/04: Regen

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 42ff9febcabae5c963fd6cbe7cbe78420b254758
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Aug 23 17:35:35 2023 +0200

    Regen
---
 .../src/main/java/org/apache/camel/main/MainDurationEventNotifier.java | 3 ++-
 .../camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java b/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
index daecdbffeea..7b6c6e52b31 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
@@ -96,7 +96,8 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
 
         boolean complete = false;
         if (maxMessages > 0) {
-             complete = event.getType() == CamelEvent.Type.ExchangeCompleted || event.getType() == CamelEvent.Type.ExchangeFailed;
+            complete = event.getType() == CamelEvent.Type.ExchangeCompleted
+                    || event.getType() == CamelEvent.Type.ExchangeFailed;
 
             if (complete) {
                 boolean result = doneMessages.incrementAndGet() >= maxMessages;
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java b/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java
index 0288b00652c..c5485bb4aaa 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java
@@ -180,7 +180,7 @@ public final class SensitiveUtils {
                                                     + "|\\Qverificationcode\\E"
                                                     + "|\\Qwebhookverifytoken\\E"
                                                     + "|\\Qzookeeperpassword\\E"
-                                                    // SENSITIVE-PATTERN: END
+    // SENSITIVE-PATTERN: END
     ;
 
     private SensitiveUtils() {


[camel] 03/04: CAMEL-19785: camel-yaml-dsl - Order of beans should not matter

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a8d3d48e925650f405b36f9b3f06b652cfc65726
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Aug 23 17:28:49 2023 +0200

    CAMEL-19785: camel-yaml-dsl - Order of beans should not matter
---
 .../apache/camel/dsl/yaml/deserializers/BeansDeserializer.java    | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/BeansDeserializer.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/BeansDeserializer.java
index 7425de959f4..c7537de2451 100644
--- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/BeansDeserializer.java
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/BeansDeserializer.java
@@ -17,12 +17,12 @@
 package org.apache.camel.dsl.yaml.deserializers;
 
 import java.util.ArrayList;
+import java.util.List;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.dsl.yaml.common.YamlDeserializationContext;
 import org.apache.camel.dsl.yaml.common.YamlDeserializerResolver;
 import org.apache.camel.dsl.yaml.common.YamlDeserializerSupport;
-import org.apache.camel.dsl.yaml.common.YamlSupport;
-import org.apache.camel.model.Model;
 import org.apache.camel.model.app.RegistryBeanDefinition;
 import org.apache.camel.spi.CamelContextCustomizer;
 import org.apache.camel.spi.annotations.YamlIn;
@@ -87,10 +87,6 @@ public class BeansDeserializer extends YamlDeserializerSupport implements Constr
             camelContext.getRegistry().unbind(name);
             camelContext.getRegistry().bind(name, bean);
 
-            // register bean in model
-            Model model = camelContext.getCamelContextExtension().getContextPlugin(Model.class);
-            model.addRegistryBean(def);
-
         } catch (Exception e) {
             if (delayIfFailed) {
                 delayedRegistrations.add(def);


[camel] 02/04: Delete test that cant compile

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f30849ac25fdd3337962fc6c010b7267984938f1
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Aug 23 17:23:23 2023 +0200

    Delete test that cant compile
---
 .../http/HttpProducerWithSpecialCharsBodyTest.java | 104 ---------------------
 1 file changed, 104 deletions(-)

diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerWithSpecialCharsBodyTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerWithSpecialCharsBodyTest.java
deleted file mode 100644
index b651f7ff1a0..00000000000
--- a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerWithSpecialCharsBodyTest.java
+++ /dev/null
@@ -1,104 +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.component.http;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.camel.CamelExchangeException;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.hc.core5.http.HttpEntity;
-import org.apache.hc.core5.http.io.entity.StringEntity;
-import org.junit.jupiter.api.Test;
-
-import static org.apache.camel.Exchange.CHARSET_NAME;
-import static org.apache.hc.core5.http.ContentType.APPLICATION_JSON;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class HttpProducerWithSpecialCharsBodyTest {
-
-    private static final String TEST_MESSAGE_WITH_SPECIAL_CHARACTERS
-            = """
-                    {
-                        "description": "Example with special characters",
-                        "BasicLatin": "\u0021 \u0023 \u0024 \u0025 \u0026 \u0027 \u0028 \u0029 \u002A \u002B \u002C \u002D \u002E \u002F \u003A \u003B \u003C \u003D \u003E \u003F",
-                        "Latin1": "\u00A1 \u00BF \u00A9 \u00AE \u00F1 \u00F6 \u00FC",
-                        "Greek": "\u0391 \u03B2 \u03B3 \u0394 \u03A9",
-                        "Cyrillic": "\u0410 \u0431 \u0432 \u0413 \u0434",
-                        "Hebrew": "\u05D0 \u05D1 \u05D2 \u05D3 \u05D4",
-                        "Arabic": "\u0627 \u0628 \u062A \u062B \u062C",
-                        "Devanagari": "\u0905 \u0906 \u0907 \u0908 \u0909",
-                        "CJK Unified Ideographs" : "\u4E00 \u4E8C \u4E09 \u56DB \u4E94",
-                        "Emoticons": "\uD83D\uDE00 \uD83D\uDE0E \uD83D\uDE0A \uD83C\uDF0D"
-                    }
-                    """;
-
-    private static final String APPLICATION_JSON_UTF8
-            = APPLICATION_JSON.getMimeType() + "; charset=" + StandardCharsets.UTF_8.name();
-
-    @Test
-    void createRequestEntityJsonUtf8ThroughContentType() throws CamelExchangeException, IOException {
-        HttpEndpoint httpEndpoint = mock(HttpEndpoint.class);
-        HttpProducer httpProducer = new HttpProducer(httpEndpoint);
-
-        Message message = mock(Message.class);
-        when(message.getBody()).thenReturn(TEST_MESSAGE_WITH_SPECIAL_CHARACTERS);
-        when(message.getHeader(Exchange.CONTENT_TYPE, String.class)).thenReturn(APPLICATION_JSON_UTF8);
-
-        Exchange exchange = mock(Exchange.class);
-        when(exchange.getIn()).thenReturn(message);
-
-        HttpEntity requestEntity = httpProducer.createRequestEntity(exchange);
-
-        assertTrue(requestEntity instanceof StringEntity);
-        StringEntity entity = (StringEntity) requestEntity;
-        assertEquals(APPLICATION_JSON_UTF8, entity.getContentType(), "Content type should be given content type and charset");
-        assertEquals(StandardCharsets.UTF_8.name(), entity.getContentEncoding(), "Content encoding should be given charset");
-        assertEquals(TEST_MESSAGE_WITH_SPECIAL_CHARACTERS,
-                new String(entity.getContent().readAllBytes(), StandardCharsets.UTF_8),
-                "Reading entity content with intended charset should result in the original (readable) message");
-    }
-
-    @Test
-    void createRequestEntityJsonUtf8ThroughCharset() throws CamelExchangeException, IOException {
-        HttpEndpoint httpEndpoint = mock(HttpEndpoint.class);
-        HttpProducer httpProducer = new HttpProducer(httpEndpoint);
-
-        Message message = mock(Message.class);
-        when(message.getBody()).thenReturn(TEST_MESSAGE_WITH_SPECIAL_CHARACTERS);
-        when(message.getHeader(Exchange.CONTENT_TYPE, String.class)).thenReturn(APPLICATION_JSON.getMimeType());
-        when(message.getHeader(CHARSET_NAME, String.class)).thenReturn(StandardCharsets.UTF_8.name());
-
-        Exchange exchange = mock(Exchange.class);
-        when(exchange.getIn()).thenReturn(message);
-
-        HttpEntity requestEntity = httpProducer.createRequestEntity(exchange);
-
-        assertTrue(requestEntity instanceof StringEntity);
-        StringEntity entity = (StringEntity) requestEntity;
-        assertEquals(APPLICATION_JSON_UTF8, entity.getContentType(), "Content type should be given content type and charset");
-        assertEquals(StandardCharsets.UTF_8.name(), entity.getContentEncoding(), "Content encoding should be given charset");
-        assertEquals(TEST_MESSAGE_WITH_SPECIAL_CHARACTERS,
-                new String(entity.getContent().readAllBytes(), StandardCharsets.UTF_8),
-                "Reading entity content with intended charset should result in the original (readable) message");
-    }
-
-}