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 2024/02/22 09:11:45 UTC
(camel) branch camel-4.4.x updated: CAMEL-20445: camel-core - Add support for updating exchange variables in JMX debugger needed for tooling.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.4.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.4.x by this push:
new 0cd79233cf4 CAMEL-20445: camel-core - Add support for updating exchange variables in JMX debugger needed for tooling.
0cd79233cf4 is described below
commit 0cd79233cf42c411a349ce87999abd925be41427
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Feb 22 10:11:17 2024 +0100
CAMEL-20445: camel-core - Add support for updating exchange variables in JMX debugger needed for tooling.
---
.../java/org/apache/camel/spi/BacklogDebugger.java | 17 +++++++++
.../impl/debugger/DefaultBacklogDebugger.java | 40 ++++++++++++++++++++++
.../mbean/ManagedBacklogDebuggerMBean.java | 15 ++++++--
.../management/mbean/ManagedBacklogDebugger.java | 24 +++++++++++++
4 files changed, 93 insertions(+), 3 deletions(-)
diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/BacklogDebugger.java b/core/camel-api/src/main/java/org/apache/camel/spi/BacklogDebugger.java
index 19d1b601b18..5ce38acaeb5 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/BacklogDebugger.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/BacklogDebugger.java
@@ -229,6 +229,23 @@ public interface BacklogDebugger extends StatefulService {
*/
void removeExchangePropertyOnBreakpoint(String nodeId, String exchangePropertyName);
+ /**
+ * Updates/adds the variable (uses same type as old variableName value) on the suspended breakpoint at the given node id
+ */
+ void setExchangeVariableOnBreakpoint(String nodeId, String variableName, Object value)
+ throws NoTypeConversionAvailableException;
+
+ /**
+ * Updates/adds the variable (with a new type) on the suspended breakpoint at the given node id
+ */
+ void setExchangeVariableOnBreakpoint(String nodeId, String variableName, Object value, Class<?> type)
+ throws NoTypeConversionAvailableException;
+
+ /**
+ * Removes the variable on the suspended breakpoint at the given node id
+ */
+ void removeExchangeVariableOnBreakpoint(String nodeId, String variableName);
+
/**
* Fallback Timeout in seconds (300 seconds as default) when block the message processing in Camel. A timeout used
* for waiting for a message to arrive at a given breakpoint.
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogDebugger.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogDebugger.java
index 93f6e87d5e8..c53a16d3405 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogDebugger.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogDebugger.java
@@ -498,6 +498,46 @@ public final class DefaultBacklogDebugger extends ServiceSupport implements Back
}
}
+ @Override
+ public void setExchangeVariableOnBreakpoint(String nodeId, String variableName, Object value)
+ throws NoTypeConversionAvailableException {
+ SuspendedExchange se = suspendedBreakpoints.get(nodeId);
+ if (se != null) {
+ Class<?> oldType = se.getExchange().getMessage().getHeader(variableName) == null
+ ? null : se.getExchange().getMessage().getHeader(variableName).getClass();
+ setExchangeVariableOnBreakpoint(nodeId, variableName, value, oldType);
+ }
+ }
+
+ @Override
+ public void setExchangeVariableOnBreakpoint(String nodeId, String variableName, Object value, Class<?> type)
+ throws NoTypeConversionAvailableException {
+ SuspendedExchange se = suspendedBreakpoints.get(nodeId);
+ if (se != null) {
+ logger.log("Breakpoint at node " + nodeId + " is updating exchange variable on exchangeId: "
+ + se.getExchange().getExchangeId() + " with key: " + variableName + " and value: " + value);
+ if (type == null) {
+ se.getExchange().setVariable(variableName, value);
+ } else {
+ Object convertedValue
+ = se.getExchange().getContext().getTypeConverter().mandatoryConvertTo(type, se.getExchange(), value);
+ se.getExchange().setVariable(variableName, convertedValue);
+ }
+ refreshBacklogTracerEventMessage(nodeId, se);
+ }
+ }
+
+ @Override
+ public void removeExchangeVariableOnBreakpoint(String nodeId, String variableName) {
+ SuspendedExchange se = suspendedBreakpoints.get(nodeId);
+ if (se != null) {
+ logger.log("Breakpoint at node " + nodeId + " is removing variable on exchangeId: "
+ + se.getExchange().getExchangeId() + " with key: " + variableName);
+ se.getExchange().removeVariable(variableName);
+ refreshBacklogTracerEventMessage(nodeId, se);
+ }
+ }
+
@Override
public long getFallbackTimeout() {
return fallbackTimeout;
diff --git a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBacklogDebuggerMBean.java b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBacklogDebuggerMBean.java
index 783c6a5d2cd..ecdc3d24505 100644
--- a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBacklogDebuggerMBean.java
+++ b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBacklogDebuggerMBean.java
@@ -168,14 +168,23 @@ public interface ManagedBacklogDebuggerMBean {
@ManagedOperation(description = "Evaluates the expression at a given breakpoint node id and returns the result as String")
String evaluateExpressionAtBreakpoint(String nodeId, String language, String expression);
- @ManagedOperation(description = "Updates/adds the exchange property (uses same type as old exchange property value) on the suspended breakpoint at the given node id")
+ @ManagedOperation(description = "Updates/adds the exchange property (uses same type as old exchange property value) on the suspended breakpoint at the given node id")
void setExchangePropertyOnBreakpoint(String nodeId, String exchangePropertyName, Object value);
+ @ManagedOperation(description = "Updates/adds the exchange property (with a new type) on the suspended breakpoint at the given node id")
+ void setExchangePropertyOnBreakpoint(String nodeId, String exchangePropertyName, Object value, String type);
+
@ManagedOperation(description = "Removes the exchange property on the suspended breakpoint at the given node id")
void removeExchangePropertyOnBreakpoint(String nodeId, String exchangePropertyName);
- @ManagedOperation(description = "Updates/adds the exchange property (with a new type) on the suspended breakpoint at the given node id")
- void setExchangePropertyOnBreakpoint(String nodeId, String exchangePropertyName, Object value, String type);
+ @ManagedOperation(description = "Updates/adds the exchange variable (uses same type as old variableName value) on the suspended breakpoint at the given node id")
+ void setExchangeVariableOnBreakpoint(String nodeId, String variableName, Object value);
+
+ @ManagedOperation(description = "Updates/adds the exchange variable (with a new type) on the suspended breakpoint at the given node id")
+ void setExchangeVariableOnBreakpoint(String nodeId, String variableName, Object value, String type);
+
+ @ManagedOperation(description = "Removes the exchange variable on the suspended breakpoint at the given node id")
+ void removeExchangeVariableOnBreakpoint(String nodeId, String variableName);
@ManagedOperation(description = "Returns the message history at the given node id as XML")
String messageHistoryOnBreakpointAsXml(String nodeId);
diff --git a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedBacklogDebugger.java b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedBacklogDebugger.java
index edb5fc411db..09530f56edf 100644
--- a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedBacklogDebugger.java
+++ b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedBacklogDebugger.java
@@ -347,6 +347,30 @@ public class ManagedBacklogDebugger implements ManagedBacklogDebuggerMBean {
backlogDebugger.removeExchangePropertyOnBreakpoint(nodeId, exchangePropertyName);
}
+ @Override
+ public void setExchangeVariableOnBreakpoint(String nodeId, String variableName, Object value) {
+ try {
+ backlogDebugger.setExchangeVariableOnBreakpoint(nodeId, variableName, value);
+ } catch (NoTypeConversionAvailableException e) {
+ throw RuntimeCamelException.wrapRuntimeCamelException(e);
+ }
+ }
+
+ @Override
+ public void setExchangeVariableOnBreakpoint(String nodeId, String variableName, Object value, String type) {
+ try {
+ Class<?> classType = camelContext.getClassResolver().resolveMandatoryClass(type);
+ backlogDebugger.setExchangeVariableOnBreakpoint(nodeId, variableName, value, classType);
+ } catch (Exception e) {
+ throw RuntimeCamelException.wrapRuntimeCamelException(e);
+ }
+ }
+
+ @Override
+ public void removeExchangeVariableOnBreakpoint(String nodeId, String variableName) {
+ backlogDebugger.removeExchangeVariableOnBreakpoint(nodeId, variableName);
+ }
+
@Override
public Object evaluateExpressionAtBreakpoint(String nodeId, String language, String expression, String resultType) {
Exchange suspendedExchange;