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

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


The following commit(s) were added to refs/heads/camel-4.18.x by this push:
     new c6329eceef80 CAMEL-24257: Fix stub pattern matching for kamelets with 
#class component beans
c6329eceef80 is described below

commit c6329eceef8014f439fc5435b03011d855248705
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Jul 25 09:44:01 2026 +0200

    CAMEL-24257: Fix stub pattern matching for kamelets with #class component 
beans
    
    Backport of #25097 — fix regression where camel export fails with
    MongoTimeoutException for kamelets using #class: Component beans.
    The outer else { accept = true } branch added in CAMEL-22667 overrode
    accept=false, causing real components to be loaded instead of stubbed.
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 .../camel/main/download/KameletMainInjector.java   |  2 -
 .../main/download/KameletMainInjectorTest.java     | 68 ++++++++++++++++++++++
 2 files changed, 68 insertions(+), 2 deletions(-)

diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/KameletMainInjector.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/KameletMainInjector.java
index 94277558399a..3c7165deab3d 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/KameletMainInjector.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/KameletMainInjector.java
@@ -100,8 +100,6 @@ public class KameletMainInjector implements Injector {
                 } else {
                     accept = true;
                 }
-            } else {
-                accept = true;
             }
         }
         return accept;
diff --git 
a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/KameletMainInjectorTest.java
 
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/KameletMainInjectorTest.java
new file mode 100644
index 000000000000..770c9915e69f
--- /dev/null
+++ 
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/KameletMainInjectorTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.main.download;
+
+import org.apache.camel.component.direct.DirectComponent;
+import org.apache.camel.component.stub.StubComponent;
+import org.apache.camel.component.timer.TimerComponent;
+import org.apache.camel.impl.engine.SimpleCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+
+class KameletMainInjectorTest {
+
+    @Test
+    void testWildcardStubsNonWhitelistedComponent() {
+        // TimerComponent is NOT in ACCEPTED_STUB_NAMES, stubPattern="*" (used 
by camel export), it should be replaced with StubComponent.
+        KameletMainInjector injector = new KameletMainInjector(
+                new SimpleCamelContext().getInjector(), "*", true);
+
+        Object result = injector.newInstance(TimerComponent.class);
+        assertInstanceOf(StubComponent.class, result);
+    }
+
+    @Test
+    void testComponentWildcardStubsNonWhitelistedComponent() {
+        // stubPattern="component:*" (used by --stub=all) should also stub 
non-whitelisted components.
+        KameletMainInjector injector = new KameletMainInjector(
+                new SimpleCamelContext().getInjector(), "component:*", true);
+
+        Object result = injector.newInstance(TimerComponent.class);
+        assertInstanceOf(StubComponent.class, result);
+    }
+
+    @Test
+    void testWildcardAllowsWhitelistedComponent() {
+        // DirectComponent is in ACCEPTED_STUB_NAMES, so it should not be 
stubbed.
+        KameletMainInjector injector = new KameletMainInjector(
+                new SimpleCamelContext().getInjector(), "*", true);
+
+        Object result = injector.newInstance(DirectComponent.class);
+        assertInstanceOf(DirectComponent.class, result);
+    }
+
+    @Test
+    void testNonComponentClassIsNotStubbed() {
+        // Non-Component classes should pass through unchanged.
+        KameletMainInjector injector = new KameletMainInjector(
+                new SimpleCamelContext().getInjector(), "*", true);
+
+        Object result = injector.newInstance(String.class);
+        assertInstanceOf(String.class, result);
+    }
+}

Reply via email to