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 2026/09/09 08:18:17 UTC

(camel) branch main updated: camel-management: skip routes not registered in JMX in getManagedRoutes

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 c96dc301a8b1 camel-management: skip routes not registered in JMX in getManagedRoutes
c96dc301a8b1 is described below

commit c96dc301a8b13adfff18882d0c2cef01cd3af45a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Sep 9 09:20:59 2026 +0200

    camel-management: skip routes not registered in JMX in getManagedRoutes
    
    Routes created by Kamelets are not registered in JMX by default, so
    newProxyClient returned null for them and getManagedRoutes() handed out
    a list containing null entries. The processor-detail dev console then
    failed with a NullPointerException when asked for all routes. Also guard
    the console itself against null entries.
    
    Co-Authored-By: Claude Fable 5.1 <no...@anthropic.com>
    Signed-off-by: Claus Ibsen <cl...@gmail.com>
---
 .../impl/console/ProcessorDetailDevConsole.java    |  3 +
 .../camel/management/ManagedCamelContextImpl.java  |  5 +-
 .../ManagedCamelContextKameletRoutesTest.java      | 69 ++++++++++++++++++++++
 3 files changed, 76 insertions(+), 1 deletion(-)

diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/ProcessorDetailDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/ProcessorDetailDevConsole.java
index 04e6e9ea463f..4577ed631f8d 100644
--- a/core/camel-console/src/main/java/org/apache/camel/impl/console/ProcessorDetailDevConsole.java
+++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/ProcessorDetailDevConsole.java
@@ -136,6 +136,9 @@ public class ProcessorDetailDevConsole extends AbstractDevConsole {
             }
             List<RouteDetail> routes = new ArrayList<>();
             for (ManagedRouteMBean mr : managedRoutes) {
+                if (mr == null) {
+                    continue;
+                }
                 RouteDetail routeDetail = buildRouteDetail(mr);
                 if (routeDetail != null) {
                     routes.add(routeDetail);
diff --git a/core/camel-management/src/main/java/org/apache/camel/management/ManagedCamelContextImpl.java b/core/camel-management/src/main/java/org/apache/camel/management/ManagedCamelContextImpl.java
index c868c03a6fd3..4a1e17ae2aa0 100644
--- a/core/camel-management/src/main/java/org/apache/camel/management/ManagedCamelContextImpl.java
+++ b/core/camel-management/src/main/java/org/apache/camel/management/ManagedCamelContextImpl.java
@@ -163,7 +163,10 @@ public class ManagedCamelContextImpl implements ManagedCamelContext {
                     ObjectName on = getManagementStrategy().getManagementObjectNameStrategy().getObjectNameForRoute(route);
                     ManagedRouteMBean mr
                             = getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedRouteMBean.class);
-                    answer.add(mr);
+                    // routes may not be registered in JMX (such as routes created by Kamelets)
+                    if (mr != null) {
+                        answer.add(mr);
+                    }
                 } catch (MalformedObjectNameException e) {
                     throw RuntimeCamelException.wrapRuntimeCamelException(e);
                 }
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedCamelContextKameletRoutesTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedCamelContextKameletRoutesTest.java
new file mode 100644
index 000000000000..275f9d0cd790
--- /dev/null
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedCamelContextKameletRoutesTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.management;
+
+import java.util.List;
+
+import org.apache.camel.api.management.ManagedCamelContext;
+import org.apache.camel.api.management.mbean.ManagedRouteMBean;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Routes created by Kamelets are not registered in JMX by default, so they must not show up as null entries in the
+ * managed routes list.
+ */
+@DisabledOnOs(OS.AIX)
+public class ManagedCamelContextKameletRoutesTest extends ManagementTestSupport {
+
+    @Test
+    public void testKameletRoutesNotInManagedRoutes() {
+        ManagedCamelContext mcc = context.getCamelContextExtension().getContextPlugin(ManagedCamelContext.class);
+
+        assertNull(mcc.getManagedRoute("mysource-1"));
+
+        List<ManagedRouteMBean> routes = mcc.getManagedRoutes();
+        assertEquals(1, routes.size());
+        assertEquals("route1", routes.get(0).getRouteId());
+
+        routes = mcc.getManagedRoutesByGroup(null);
+        assertEquals(1, routes.size());
+        assertEquals("route1", routes.get(0).getRouteId());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                // simulates the route a Kamelet creates internally, feeding the user route
+                RouteDefinition kamelet = from("timer:tick?period=100000").routeId("mysource-1")
+                        .to("direct:mysource");
+                kamelet.setKamelet(true);
+
+                from("direct:mysource").routeId("route1")
+                        .to("mock:result");
+            }
+        };
+    }
+}