Skip to content

Commit

Permalink
FUSETOOLS2-2299: Display variables values during debugging for Exchan…
Browse files Browse the repository at this point in the history
…ge scope

Signed-off-by: Dominik Jelinek <[email protected]>
  • Loading branch information
djelinek committed Mar 18, 2024
1 parent a343f85 commit 09d6901
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ public boolean attach(Map<String, Object> args, IDebugProtocolClient client) {
// Ignore, we might be connected to pre 4.2 Camel version
System.out.println(ex);
}
try {
backlogDebugger.setIncludeExchangeVariables(true);
} catch(Exception ex) {
// Ignore, we might be connected to pre 4.4 Camel version
System.out.println(ex);
}
backlogDebugger.enableDebugger();
routesDOMDocument = retrieveRoutesWithSourceLineNumber(jmxAddress);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.github.cameltooling.dap.internal.model.CamelStackFrame;
import com.github.cameltooling.dap.internal.model.variables.message.MessageBodyCamelVariable;
import com.github.cameltooling.dap.internal.model.variables.message.MessageExchangePropertiesVariable;
import com.github.cameltooling.dap.internal.model.variables.message.MessageExchangeVariablesVariable;
import com.github.cameltooling.dap.internal.model.variables.message.MessageHeadersVariable;
import com.github.cameltooling.dap.internal.types.EventMessage;
import com.github.cameltooling.dap.internal.types.UnmarshallerEventMessage;
Expand All @@ -39,6 +40,7 @@ public class CamelMessageScope extends CamelScope {
private MessageBodyCamelVariable messageBody;
private MessageHeadersVariable headersVariable;
private MessageExchangePropertiesVariable exchangePropertiesVariable;
private MessageExchangeVariablesVariable exchangeVariablesVariable;

public CamelMessageScope(CamelStackFrame stackframe) {
super(NAME, stackframe.getName(), IdUtils.getPositiveIntFromHashCode((stackframe.getId()+"@Message@" + stackframe.getName()).hashCode()));
Expand All @@ -59,6 +61,8 @@ public Set<Variable> createVariables(int variablesReference, ManagedBacklogDebug
variables.add(headersVariable);
exchangePropertiesVariable = new MessageExchangePropertiesVariable(variablesReference, eventMessage.getMessage().getExchangeProperties(), getBreakpointId());
variables.add(getExchangePropertiesVariable());
exchangeVariablesVariable = new MessageExchangeVariablesVariable(variablesReference, eventMessage.getMessage().getExchangeVariables());
variables.add(getExchangeVariablesVariable());
}
} else {
if (headersVariable != null && variablesReference == headersVariable.getVariablesReference()) {
Expand All @@ -67,6 +71,9 @@ public Set<Variable> createVariables(int variablesReference, ManagedBacklogDebug
if (getExchangePropertiesVariable() != null && variablesReference == getExchangePropertiesVariable().getVariablesReference()) {
variables.addAll(getExchangePropertiesVariable().createVariables());
}
if (getExchangeVariablesVariable() != null && variablesReference == getExchangeVariablesVariable().getVariablesReference()) {
variables.addAll(getExchangeVariablesVariable().createVariables());
}
}
return variables;
}
Expand Down Expand Up @@ -103,4 +110,8 @@ public MessageExchangePropertiesVariable getExchangePropertiesVariable() {
return exchangePropertiesVariable;
}

public MessageExchangeVariablesVariable getExchangeVariablesVariable() {
return exchangeVariablesVariable;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.github.cameltooling.dap.internal.model.variables.message;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.lsp4j.debug.Variable;

import com.github.cameltooling.dap.internal.IdUtils;
import com.github.cameltooling.dap.internal.types.ExchangeVariable;

public class MessageExchangeVariablesVariable extends Variable {

private final List<ExchangeVariable> exchangeVariables;

public MessageExchangeVariablesVariable(int parentVariablesReference, List<ExchangeVariable> exchangeVariables) {
this.exchangeVariables = exchangeVariables;
setName("Variables");
setValue("");
int headerVarRefId = IdUtils.getPositiveIntFromHashCode((parentVariablesReference+"@ExchangeVariables@").hashCode());
setVariablesReference(headerVarRefId);
}

public Collection<Variable> createVariables() {
Collection<Variable> variables = new ArrayList<>();
if (exchangeVariables != null) {
for (ExchangeVariable exchangeVariable : exchangeVariables) {
variables.add(createVariable(exchangeVariable.getKey(), exchangeVariable.getValue()));
}
}
return variables;
}

private Variable createVariable(String key, String value) {
Variable variable = new Variable();
variable.setName(key);
variable.setValue(value);
return variable ;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.cameltooling.dap.internal.types;

import java.io.Serializable;

import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlValue;

@XmlRootElement(name = "exchangeVariable")
public class ExchangeVariable implements Serializable {

private static final long serialVersionUID = 4693511937508953820L;

private String type;
private String key;
private String value;

@XmlAttribute(name = "type")
public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

@XmlAttribute(name = "key")
public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

@XmlValue
public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Message implements Serializable {
private List<Header> headers;
private String body;
private List<ExchangeProperty> exchangeProperties;
private List<ExchangeVariable> exchangeVariables;

@XmlAttribute(name = "exchangeId")
public String getExchangeId() {
Expand Down Expand Up @@ -70,4 +71,13 @@ public List<ExchangeProperty> getExchangeProperties() {
public void setExchangeProperties(List<ExchangeProperty> exchangeProperties) {
this.exchangeProperties = exchangeProperties;
}

@XmlElementWrapper(name = "exchangeVariables")
@XmlElement(name = "exchangeVariable")
public List<ExchangeVariable> getExchangeVariables() {
return exchangeVariables;
}
public void setExchangeVariables(List<ExchangeVariable> exchangeVariables) {
this.exchangeVariables = exchangeVariables;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class UnmarshallerEventMessage {

public EventMessage getUnmarshalledEventMessage(String xmlDump) {
try {
JAXBContext context = JAXBContext.newInstance(EventMessage.class, Message.class, Header.class, ExchangeProperty.class);
JAXBContext context = JAXBContext.newInstance(EventMessage.class, Message.class, Header.class, ExchangeProperty.class, ExchangeVariable.class);
Unmarshaller um = context.createUnmarshaller();
return (EventMessage)um.unmarshal(new StringReader(xmlDump));
} catch (JAXBException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
//@SetSystemProperty(key = "camel.debug.enabled", value = "true")
public abstract class BaseTest {

protected static final int DEFAULT_VARIABLES_NUMBER = 16;
protected static final int DEFAULT_VARIABLES_NUMBER = 17;
protected CamelDebugAdapterServer server;
protected DummyCamelDebugClient clientProxy;
protected CamelContext context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void testBasicFlow() throws Exception {
await().untilAsserted(() -> assertThat(stackAndData.getScopes()).hasSize(5));
await("handling of stop event response is finished")
.atMost(Duration.ofSeconds(60))
.untilAsserted(() -> assertThat(stackAndData.getVariables()).hasSize(21));
.untilAsserted(() -> assertThat(stackAndData.getVariables()).hasSize(24));
ManagedBacklogDebuggerMBean debugger = server.getConnectionManager().getBacklogDebugger();
List<Variable> variables = stackAndData.getVariables();
assertThat(variables)
Expand All @@ -115,7 +115,9 @@ void testBasicFlow() throws Exception {
createVariable("header1", "value of header 1"),
createVariable("header2", "value of header 2"),
createVariable("property1", "value of property 1"),
createVariable("property2", "value of property 2"));
createVariable("property2", "value of property 2"),
createVariable("var1", "value of variable 1"),
createVariable("var2", "value of variable 2"));

assertThat(variables.stream().map(var -> var.getValue()))
.as("All variables must have a non-null values due to limitation in VS Code implementation, see https://github.com/microsoft/vscode/issues/141544")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public void configure() throws Exception {
.setHeader("header2", constant("value of header 2"))
.setProperty("property1", constant("value of property 1"))
.setProperty("property2", constant("value of property 2"))
.setVariable("var1", constant("value of variable 1"))
.setVariable("var2", constant("value of variable 2"))
.log("Log from test").id(logEndpointId); // XXX-breakpoint-XXX
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ void testGetUnmarshalledEventMessage() {
<header key="header1" type="java.lang.String">value of header 1</header>
<header key="header2" type="java.lang.String">value of header 2</header>
</headers>
<exchangeVariables>
<exchangeVariable key="var1" type="java.lang.String">value of variable 1</exchangeVariable>
<exchangeVariable key="var2" type="java.lang.String">value of variable 2</exchangeVariable>
</exchangeVariables>
<body type="java.lang.String">a body for test</body>
</message>
</backlogTracerEventMessage>
Expand All @@ -60,6 +64,7 @@ void testGetUnmarshalledEventMessage() {
assertThat(message.getUid()).isEqualTo(1);
assertThat(message.getMessage().getHeaders()).hasSize(2);
assertThat(message.getMessage().getExchangeProperties()).hasSize(3);
assertThat(message.getMessage().getExchangeVariables()).hasSize(2);
assertThat(message.getMessage().getBody()).isEqualTo("a body for test");
}

Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/basic-withroutes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<setProperty name="property2">
<constant>value of property 2</constant>
</setProperty>
<setVariable name="var1">
<constant>value of variable 1</constant>
</setVariable>
<setVariable name="var2">
<constant>value of variable 2</constant>
</setVariable>
<log message="Log From Test" id="testBasicFlow-log-id" /> <!-- XXX-breakpoint-XXX -->
</route>
</routes>
6 changes: 6 additions & 0 deletions src/test/resources/basic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@
<setProperty name="property2">
<constant>value of property 2</constant>
</setProperty>
<setVariable name="var1">
<constant>value of variable 1</constant>
</setVariable>
<setVariable name="var2">
<constant>value of variable 2</constant>
</setVariable>
<log message="Log From Test" id="testBasicFlow-log-id" /> <!-- XXX-breakpoint-XXX -->
</route>
8 changes: 8 additions & 0 deletions src/test/resources/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
name: property2
expression:
constant: value of property 2
- setVariable:
name: var1
expression:
constant: value of variable 1
- setVariable:
name: var2
expression:
constant: value of variable 2
- to: # XXX-breakpoint-XXX
uri: log:Log From Test
id: testBasicFlow-log-id

0 comments on commit 09d6901

Please sign in to comment.