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 11ee0097a4f camel-console - output in html if using a browser
11ee0097a4f is described below

commit 11ee0097a4f56ae1749cc3c8bda1c7818a2ef2b2
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sat May 28 18:42:13 2022 +0200

    camel-console - output in html if using a browser
---
 .../org/apache/camel/main/VertxHttpServer.java     | 57 +++++++++++++++-------
 1 file changed, 39 insertions(+), 18 deletions(-)

diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
index 2b9db2b3554..a9be053cf6c 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
@@ -175,8 +175,17 @@ public final class VertxHttpServer {
         Handler<RoutingContext> handler = new Handler<RoutingContext>() {
             @Override
             public void handle(RoutingContext ctx) {
+                String acp = ctx.request().getHeader("Accept");
+                final boolean html = acp != null && acp.contains("html");
+
                 ctx.response().putHeader("content-type", "text/plain");
 
+                DevConsoleRegistry dcr = 
context.getExtension(DevConsoleRegistry.class);
+                if (dcr == null || !dcr.isEnabled()) {
+                    ctx.end("Developer Console is not enabled");
+                    return;
+                }
+
                 String path = StringHelper.after(ctx.request().path(), 
"/q/dev/");
                 String s = path;
                 if (s != null && s.contains("/")) {
@@ -184,23 +193,40 @@ public final class VertxHttpServer {
                 }
                 String id = s;
 
-                Map<String, Object> params = new HashMap<>();
-                ctx.queryParams().forEach(params::put);
-                params.put(Exchange.HTTP_PATH, path);
+                StringBuilder sb = new StringBuilder();
+
+                // index/home should list each console
+                if (id == null || id.isEmpty() || id.equals("index")) {
+                    dcr.stream().forEach(c -> {
+                        String link = c.getId();
+                        String eol = "\n";
+                        if (html) {
+                            link = "<a href=\"" + link + "\">" + c.getId() + 
"</a>";
+                            eol = "<br/>\n";
+                        }
+                        sb.append(link).append(": 
").append(c.getDescription()).append(eol);
+                        // special for top in processor mode
+                        if ("top".equals(c.getId())) {
+                            link = link.replace("top", "top/*");
+                            sb.append(link).append(": ").append("Display the 
top processors").append(eol);
+                        }
+                    });
+                    if (html) {
+                        ctx.response().putHeader("content-type", "text/html");
+                    }
+                    ctx.end(sb.toString());
+                } else {
+                    Map<String, Object> params = new HashMap<>();
+                    ctx.queryParams().forEach(params::put);
+                    params.put(Exchange.HTTP_PATH, path);
 
-                DevConsoleRegistry dcr = 
context.getExtension(DevConsoleRegistry.class);
-                if (dcr != null && dcr.isEnabled()) {
-                    StringBuilder sb = new StringBuilder();
                     // sort according to index by given id
                     dcr.stream().sorted((o1, o2) -> {
-                        if (id == null || id.isEmpty()) {
-                            return 0;
-                        }
                         int p1 = id.indexOf(o1.getId());
                         int p2 = id.indexOf(o2.getId());
                         return Integer.compare(p1, p2);
                     }).forEach(c -> {
-                        boolean include = id == null || id.isEmpty() || 
id.contains(c.getId());
+                        boolean include = "all".equals(id) || 
id.contains(c.getId());
                         if (include && 
c.supportMediaType(DevConsole.MediaType.TEXT)) {
                             String text = (String) 
c.call(DevConsole.MediaType.TEXT, params);
                             if (text != null) {
@@ -212,16 +238,11 @@ public final class VertxHttpServer {
                         }
                     });
                     if (sb.length() > 0) {
-                        ctx.end(sb.toString());
+                        String out = sb.toString();
+                        ctx.end(out);
                     } else {
-                        if (id != null) {
-                            ctx.end("Developer Console with id not found: " + 
id);
-                        } else {
-                            ctx.end("Developer Console is not enabled");
-                        }
+                        ctx.end("Developer Console not found: " + id);
                     }
-                } else {
-                    ctx.end("Developer Console is not enabled");
                 }
             }
         };

Reply via email to