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 e6d188f88c5 CAMEL-22047: camel-jbang - send/receive command to include exchange variables in reply/response e6d188f88c5 is described below commit e6d188f88c5d6564f2fd275d08f226e80879f619 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat May 3 09:28:33 2025 +0200 CAMEL-22047: camel-jbang - send/receive command to include exchange variables in reply/response --- .../camel/impl/console/ReceiveDevConsole.java | 2 +- .../apache/camel/impl/console/SendDevConsole.java | 7 ++++--- .../core/commands/action/CamelReceiveAction.java | 17 ++++++++++++++++- .../core/commands/action/CamelSendAction.java | 22 +++++++++++++++------- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java index 3f5652a68e7..81946c83419 100644 --- a/core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java +++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java @@ -262,7 +262,7 @@ public class ReceiveDevConsole extends AbstractDevConsole { private void addMessage(Exchange exchange) { JsonObject json - = MessageHelper.dumpAsJSonObject(exchange.getMessage(), false, false, true, true, true, true, bodyMaxChars); + = MessageHelper.dumpAsJSonObject(exchange.getMessage(), true, true, true, true, true, true, bodyMaxChars); json.put("uid", uuid.incrementAndGet()); json.put("endpointUri", exchange.getFromEndpoint().toString()); json.put("remoteEndpoint", exchange.getFromEndpoint().isRemote()); diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/SendDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/SendDevConsole.java index 3ae30b10c8e..2619258ec30 100644 --- a/core/camel-console/src/main/java/org/apache/camel/impl/console/SendDevConsole.java +++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/SendDevConsole.java @@ -171,10 +171,10 @@ public class SendDevConsole extends AbstractDevConsole { sb.append("\n\n"); } if (out != null && (poll || "InOut".equals(exchangePattern))) { - sb.append("\n Response Message:\n"); + sb.append("\n Response Message:\n\n"); int maxChars = Integer.parseInt((String) options.getOrDefault(BODY_MAX_CHARS, "" + bodyMaxChars)); String json - = MessageHelper.dumpAsJSon(out.getMessage(), false, false, true, 2, true, true, true, + = MessageHelper.dumpAsJSon(out.getMessage(), true, true, true, 2, true, true, true, maxChars, true); sb.append(json); sb.append("\n"); @@ -332,7 +332,8 @@ public class SendDevConsole extends AbstractDevConsole { private static boolean isCustomHeader(String key) { return !BODY.equals(key) && !BODY_MAX_CHARS.equals(key) && !POLL.equals(key) && !POLL_TIMEOUT.equals(key) - && !EXCHANGE_PATTERN.equals(key) && !ENDPOINT.equals(key); + && !EXCHANGE_PATTERN.equals(key) && !ENDPOINT.equals(key) + && !"CamelHttpPath".equals(key); // do not include ourself /q/dev/send } } diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveAction.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveAction.java index 3e1cb212840..7efcbaa9536 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveAction.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelReceiveAction.java @@ -130,6 +130,14 @@ public class CamelReceiveAction extends ActionBaseCommand { description = "Filter messages to only output matching text (ignore case).", arity = "0..*") String[] grep; + @CommandLine.Option(names = { "--show-exchange-properties" }, defaultValue = "false", + description = "Show exchange properties in received messages") + boolean showExchangeProperties; + + @CommandLine.Option(names = { "--show-exchange-variables" }, defaultValue = "false", + description = "Show exchange variables in received messages") + boolean showExchangeVariables; + @CommandLine.Option(names = { "--show-headers" }, defaultValue = "true", description = "Show message headers in received messages") boolean showHeaders = true; @@ -585,11 +593,18 @@ public class CamelReceiveAction extends ActionBaseCommand { row.message = jo.getMap("message"); row.message.remove("exchangeId"); row.message.remove("exchangePattern"); - row.message.remove("exchangeProperties"); if (onlyBody) { + row.message.remove("exchangeProperties"); + row.message.remove("exchangeVariables"); row.message.remove("headers"); row.message.remove("messageType"); } else { + if (!showExchangeProperties) { + row.message.remove("exchangeProperties"); + } + if (!showExchangeVariables) { + row.message.remove("exchangeVariables"); + } if (!showHeaders) { row.message.remove("headers"); } diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelSendAction.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelSendAction.java index a2573b91d87..4aacfebade5 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelSendAction.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelSendAction.java @@ -72,28 +72,32 @@ public class CamelSendAction extends ActionBaseCommand { long timeout = 20000; @CommandLine.Option(names = { "--show-exchange-properties" }, defaultValue = "false", - description = "Show exchange properties in traced messages") + description = "Show exchange properties from response message (InOut)") boolean showExchangeProperties; + @CommandLine.Option(names = { "--show-exchange-variables" }, defaultValue = "false", + description = "Show exchange variables from response message (InOut)") + boolean showExchangeVariables; + @CommandLine.Option(names = { "--show-headers" }, defaultValue = "true", - description = "Show message headers in traced messages") + description = "Show message headers from response message (InOut)") boolean showHeaders = true; @CommandLine.Option(names = { "--show-body" }, defaultValue = "true", - description = "Show message body in traced messages") + description = "Show message body from response message (InOut)") boolean showBody = true; @CommandLine.Option(names = { "--show-exception" }, defaultValue = "true", description = "Show exception and stacktrace for failed messages") boolean showException = true; - @CommandLine.Option(names = { "--logging-color" }, defaultValue = "true", description = "Use colored logging") - boolean loggingColor = true; - @CommandLine.Option(names = { "--pretty" }, - description = "Pretty print message body when using JSon or XML format") + description = "Pretty print response message body (InOut) when using JSon or XML format") boolean pretty; + @CommandLine.Option(names = { "--logging-color" }, defaultValue = "true", description = "Use colored logging") + boolean loggingColor = true; + private volatile long pid; private MessageTableHelper tableHelper; @@ -172,6 +176,9 @@ public class CamelSendAction extends ActionBaseCommand { if (!showExchangeProperties && message != null) { message.remove("exchangeProperties"); } + if (!showExchangeVariables && message != null) { + message.remove("exchangeVariables"); + } if (!showHeaders && message != null) { message.remove("headers"); } @@ -186,6 +193,7 @@ public class CamelSendAction extends ActionBaseCommand { tableHelper.setPretty(pretty); tableHelper.setLoggingColor(loggingColor); tableHelper.setShowExchangeProperties(showExchangeProperties); + tableHelper.setShowExchangeVariables(showExchangeVariables); String table = tableHelper.getDataAsTable(exchangeId, mep, jo, null, message, cause); printer().println(table); }