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 9eaab087ec1 CAMEL-19299: camel-console - Add bean registry console 9eaab087ec1 is described below commit 9eaab087ec124ab4466a9b64e468e55e76b1a88e Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sun May 7 11:59:57 2023 +0200 CAMEL-19299: camel-console - Add bean registry console --- .../services/org/apache/camel/dev-console/bean | 2 + .../apache/camel/impl/console/BeanDevConsole.java | 62 ++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/bean b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/bean new file mode 100644 index 00000000000..0108ad92105 --- /dev/null +++ b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/bean @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.impl.console.BeanDevConsole diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/BeanDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/BeanDevConsole.java new file mode 100644 index 00000000000..f94dd336421 --- /dev/null +++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/BeanDevConsole.java @@ -0,0 +1,62 @@ +/* + * 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.impl.console; + +import java.util.Map; +import java.util.stream.Stream; + +import org.apache.camel.spi.annotations.DevConsole; +import org.apache.camel.support.console.AbstractDevConsole; +import org.apache.camel.util.json.JsonObject; + +@DevConsole("bean") +public class BeanDevConsole extends AbstractDevConsole { + + public BeanDevConsole() { + super("camel", "bean", "Bean", "Displays Java beans from the registry"); + } + + @Override + protected String doCallText(Map<String, Object> options) { + StringBuilder sb = new StringBuilder(); + + Map<String, Object> beans = getCamelContext().getRegistry().findByTypeWithName(Object.class); + Stream<String> keys = beans.keySet().stream().sorted(String::compareToIgnoreCase); + keys.forEach(k -> { + String v = beans.getOrDefault(k, "<null>").getClass().getName(); + sb.append(String.format(" %s (class: %s)%n", k, v)); + }); + + return sb.toString(); + } + + @Override + protected JsonObject doCallJson(Map<String, Object> options) { + JsonObject root = new JsonObject(); + + JsonObject jo = new JsonObject(); + root.put("beans", jo); + Map<String, Object> beans = getCamelContext().getRegistry().findByTypeWithName(Object.class); + Stream<String> keys = beans.keySet().stream().sorted(String::compareToIgnoreCase); + keys.forEach(k -> { + String v = beans.getOrDefault(k, "null").getClass().getName(); + beans.put(k, v); + }); + + return root; + } +}