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 2021/05/14 07:09:32 UTC

[camel] branch main created (now b3972b2)

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

acosentino pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git.


      at b3972b2  Regen for commit 72a4c5a988cc7d331eb83bc91ee49a0e7ec13d70

This branch includes the following new commits:

     new d36f11d  Regen for commit 8b6af4ada9fd3c42a0e3f8e09d5a0c7bf852db51
     new 7fe950d  Kamelet local bean - Created local bean should memorize so when using the bean multiple times its the same local bean
     new b3972b2  Regen for commit 72a4c5a988cc7d331eb83bc91ee49a0e7ec13d70

The 3 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.


[camel] 02/03: Kamelet local bean - Created local bean should memorize so when using the bean multiple times its the same local bean

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

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7fe950d4d257e38abdae63c096e9003e2cedc229
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri May 14 08:45:48 2021 +0200

    Kamelet local bean - Created local bean should memorize so when using the bean multiple times its the same local bean
---
 .../java/org/apache/camel/impl/DefaultModel.java   | 19 ++++++---
 .../camel/builder/RouteTemplateLocalBeanTest.java  | 46 ++++++++++++++++++++++
 2 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
index 56196e7..b311748 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
@@ -66,6 +66,7 @@ import org.apache.camel.support.ScriptHelper;
 import org.apache.camel.support.service.ServiceHelper;
 import org.apache.camel.util.AntPathMatcher;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.function.Suppliers;
 
 public class DefaultModel implements Model {
 
@@ -366,7 +367,9 @@ public class DefaultModel implements Model {
                 final ScriptingLanguage slan = lan instanceof ScriptingLanguage ? (ScriptingLanguage) lan : null;
                 if (slan != null) {
                     // scripting language should be evaluated with route template context as binding
-                    routeTemplateContext.bind(b.getName(), clazz, () -> {
+                    // and memorize so the script is only evaluated once and the local bean is the same
+                    // if a route template refers to the local bean multiple times
+                    routeTemplateContext.bind(b.getName(), clazz, Suppliers.memorize(() -> {
                         Map<String, Object> bindings = new HashMap<>();
                         // use rtx as the short-hand name, as context would imply its CamelContext
                         bindings.put("rtc", routeTemplateContext);
@@ -375,10 +378,12 @@ public class DefaultModel implements Model {
                             setPropertiesOnTarget(camelContext, local, props);
                         }
                         return local;
-                    });
+                    }));
                 } else {
                     // exchange based languages needs a dummy exchange to be evaluated
-                    routeTemplateContext.bind(b.getName(), clazz, () -> {
+                    // and memorize so the script is only evaluated once and the local bean is the same
+                    // if a route template refers to the local bean multiple times
+                    routeTemplateContext.bind(b.getName(), clazz, Suppliers.memorize(() -> {
                         ExchangeFactory ef = camelContext.adapt(ExtendedCamelContext.class).getExchangeFactory();
                         Exchange dummy = ef.create(false);
                         try {
@@ -396,20 +401,22 @@ public class DefaultModel implements Model {
                         } finally {
                             ef.release(dummy);
                         }
-                    });
+                    }));
                 }
             } else if (b.getBeanClass() != null || b.getType() != null && b.getType().startsWith("#class:")) {
                 Class<?> clazz = b.getBeanClass() != null
                         ? b.getBeanClass() : camelContext.getClassResolver().resolveMandatoryClass(b.getType().substring(7));
                 // we only have the bean class so we use that to create a new bean via the injector
+                // and memorize so the bean is only created once and the local bean is the same
+                // if a route template refers to the local bean multiple times
                 routeTemplateContext.bind(b.getName(), clazz,
-                        () -> {
+                        Suppliers.memorize(() -> {
                             Object local = camelContext.getInjector().newInstance(clazz);
                             if (!props.isEmpty()) {
                                 setPropertiesOnTarget(camelContext, local, props);
                             }
                             return local;
-                        });
+                        }));
             } else if (b.getType() != null && b.getType().startsWith("#type:")) {
                 Class<?> clazz = camelContext.getClassResolver().resolveMandatoryClass(b.getType().substring(6));
                 Set<?> found = getCamelContext().getRegistry().findByType(clazz);
diff --git a/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateLocalBeanTest.java b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateLocalBeanTest.java
index 83337fb0..7228b50 100644
--- a/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateLocalBeanTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateLocalBeanTest.java
@@ -23,6 +23,7 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.RouteTemplateContext;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -650,6 +651,47 @@ public class RouteTemplateLocalBeanTest extends ContextTestSupport {
         context.stop();
     }
 
+    @Test
+    public void testLocalBeanMemorize() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                routeTemplate("myTemplate").templateParameter("foo").templateParameter("bar").templateParameter("hi")
+                        .templateBean("myBar").property("prefix", "{{hi}}").typeClass(BuilderThreeProcessor.class).end()
+                        .from("direct:{{foo}}")
+                        // use unique endpoints to force referring the to bean twice
+                        .to("bean:{{bar}}")
+                        .to("bean:{{bar}}?method=process")
+                        .to("mock:result");
+            }
+        });
+
+        context.start();
+
+        TemplatedRouteBuilder.builder(context, "myTemplate")
+                .parameter("foo", "one")
+                .parameter("bar", "myBar")
+                .parameter("hi", "Davs")
+                .routeId("myRoute")
+                .add();
+
+        assertEquals(1, context.getRoutes().size());
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("DavsBuilder3 DavsBuilder3 World");
+        mock.expectedHeaderReceived("counter", 2);
+
+        Object out = template.requestBody("direct:one", "World");
+        assertEquals("DavsBuilder3 DavsBuilder3 World", out);
+
+        assertMockEndpointsSatisfied();
+
+        // should not be a global bean
+        assertNull(context.getRegistry().lookupByName("myBar"));
+
+        context.stop();
+    }
+
     public static class BuilderTwoProcessor implements Processor {
 
         private String prefix = "";
@@ -670,6 +712,7 @@ public class RouteTemplateLocalBeanTest extends ContextTestSupport {
     public static class BuilderThreeProcessor implements Processor {
 
         private String prefix = "";
+        private int counter;
 
         public String getPrefix() {
             return prefix;
@@ -681,8 +724,11 @@ public class RouteTemplateLocalBeanTest extends ContextTestSupport {
 
         @Override
         public void process(Exchange exchange) throws Exception {
+            counter++;
             exchange.getMessage().setBody(prefix + "Builder3 " + exchange.getMessage().getBody());
+            exchange.getMessage().setHeader("counter", counter);
         }
+
     }
 
     public Processor createBuilderProcessor() {

[camel] 03/03: Regen for commit 72a4c5a988cc7d331eb83bc91ee49a0e7ec13d70

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

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit b3972b25753a786f03f8c8dd8785882b2568bbcf
Author: oscerd <os...@users.noreply.github.com>
AuthorDate: Fri May 14 06:56:16 2021 +0000

    Regen for commit 72a4c5a988cc7d331eb83bc91ee49a0e7ec13d70
    
    Signed-off-by: GitHub <no...@github.com>
---
 .../resources/org/apache/camel/catalog/schemas/camel-spring.xsd          | 1 +
 1 file changed, 1 insertion(+)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
index 785bd46..ec4d05f 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
@@ -14059,6 +14059,7 @@ to refer to an existing data format instance.
       <xs:extension base="tns:optionalIdentifiedDefinition">
         <xs:sequence>
           <xs:element minOccurs="0" ref="tns:securityDefinitions"/>
+          <xs:element minOccurs="0" ref="tns:securityRequirements"/>
           <xs:choice maxOccurs="unbounded" minOccurs="0">
             <xs:element ref="tns:verb"/>
             <xs:element ref="tns:delete"/>

[camel] 01/03: Regen for commit 8b6af4ada9fd3c42a0e3f8e09d5a0c7bf852db51

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

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d36f11d5cb67ecf91a578792e95766d769423c73
Author: davsclaus <da...@users.noreply.github.com>
AuthorDate: Fri May 14 06:25:13 2021 +0000

    Regen for commit 8b6af4ada9fd3c42a0e3f8e09d5a0c7bf852db51
    
    Signed-off-by: GitHub <no...@github.com>
---
 .../resources/org/apache/camel/catalog/models/templateBean.json  | 1 +
 .../resources/org/apache/camel/catalog/schemas/camel-spring.xsd  | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/templateBean.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/templateBean.json
index 9f2c566..991833d 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/templateBean.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/templateBean.json
@@ -13,6 +13,7 @@
   "properties": {
     "name": { "kind": "attribute", "displayName": "Name", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Bean name" },
     "type": { "kind": "attribute", "displayName": "Type", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What type to use for creating the bean. Can be one of: #class,#type,bean,groovy,joor,language,mvel,ognl. #class or #type then the bean is created via the fully qualified classname, such as #class:com.foo.MyBean The others are scripting languages that gives more power to create the bean with  [...]
+    "beanType": { "kind": "attribute", "displayName": "Bean Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To set the type (fully qualified class name) of the returned bean created by the script. Knowing the type of the bean can be needed when dependency injection by type is in use, or when looking in registry via class type." },
     "property": { "kind": "element", "displayName": "Property", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.PropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Optional properties to set on the created local bean" },
     "script": { "kind": "element", "displayName": "Script", "required": false, "type": "object", "javaType": "org.apache.camel.model.RouteTemplateScriptDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "The script to execute that creates the bean when using scripting languages. If the script use the prefix resource: such as resource:classpath:com\/foo\/myscript.groovy, resource:file:\/var\/myscript.groovy, then its loaded from the external resource." }
   }
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
index 959399b..785bd46 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
@@ -10337,6 +10337,15 @@ inlined code in the script section, such as using groovy.
         ]]></xs:documentation>
       </xs:annotation>
     </xs:attribute>
+    <xs:attribute name="beanType" type="xs:string">
+      <xs:annotation>
+        <xs:documentation xml:lang="en"><![CDATA[
+To set the type (fully qualified class name) of the returned bean created by the
+script. Knowing the type of the bean can be needed when dependency injection by
+type is in use, or when looking in registry via class type.
+        ]]></xs:documentation>
+      </xs:annotation>
+    </xs:attribute>
   </xs:complexType>
 
   <xs:simpleType name="routeTemplateScriptDefinition">