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

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


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

commit c07b7f912a92841b62ae4c146d55723faf0f2a28
Author: JinyuChen97 <[email protected]>
AuthorDate: Sat Jul 25 06:52:19 2026 +0100

    CAMEL-24257: Fix stub pattern matching for kamelets with #class component 
beans
    
    Fix regression where camel export fails with MongoTimeoutException for 
kamelets
    using #class: Component beans (e.g. mongodb-sink, cassandra-sink). The outer
    else { accept = true } branch added in CAMEL-22667 overrode accept=false 
back
    to true when stubPattern is "*", causing real components to be loaded and
    attempt connections instead of being replaced with StubComponent.
    
    Remove the outer else branch so accept remains as returned by accept(type):
    true for ACCEPTED_STUB_NAMES components, false for everything else.
    
    Closes #25097
    
    Co-Authored-By: Claude <[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