Skip to content

Commit

Permalink
Merge pull request #2256 from SanojPunchihewa/debugger
Browse files Browse the repository at this point in the history
Update mediation debugger to add, retrieve and remove variables
  • Loading branch information
SanojPunchihewa authored Dec 9, 2024
2 parents 4d739fb + 88d1a6b commit 9a94a60
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -748,4 +748,15 @@ public void setVariable(String key, Object value) {
public Set getVariableKeySet() {
return variables.keySet();
}

/**
* Get a read-only view of all the variables currently set on this
* message context
*
* @return an unmodifiable map of variables
*/
public Map<String, Object> getVariables() {

return Collections.unmodifiableMap(variables);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ public void processDebugCommand(String debug_line) throws IOException {
JSONObject property_arguments = parsed_debug_line
.getJSONObject(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY);
this.addMediationFlowPointProperty(propertyContext, property_arguments, false);
} else if (skipOrBreakPointOrProperty.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLE)) {
JSONObject variable_arguments = parsed_debug_line
.getJSONObject(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLE);
this.addMediationFlowPointVariable(variable_arguments, false);
} else {
String mediation_component = parsed_debug_line
.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT);
Expand All @@ -342,6 +346,10 @@ public void processDebugCommand(String debug_line) throws IOException {
property_arguments = parsed_debug_line
.getJSONObject(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY);
}
if (propertyOrProperties.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLE)) {
property_arguments = parsed_debug_line
.getJSONObject(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLE);
}
this.acquireMediationFlowPointProperties(propertyOrProperties, propertyContext, property_arguments);
} else if (command.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_RESUME)) {
this.debugResume();
Expand All @@ -354,6 +362,10 @@ public void processDebugCommand(String debug_line) throws IOException {
JSONObject property_arguments = parsed_debug_line
.getJSONObject(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY);
this.addMediationFlowPointProperty(propertyContext, property_arguments, true);
} else if (skipOrBreakPointOrProperty.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLE)) {
JSONObject variable_arguments = parsed_debug_line
.getJSONObject(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLE);
this.addMediationFlowPointVariable(variable_arguments, true);
} else {
String mediation_component = parsed_debug_line
.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT);
Expand Down Expand Up @@ -962,6 +974,25 @@ public void acquireMediationFlowPointProperties(String propertyOrProperties,
debugInterface.getPortListenWriter().flush();
log.debug("wirelog sent to devstudio - " + wireLog.toString());
}
} else if (propertyOrProperties.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLES)) {
JSONObject data_synapse = new JSONObject(((Axis2MessageContext) synCtx).getVariables());
JSONObject data_synapse_variables = new JSONObject();
data_synapse_variables.put(SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_VARIABLES, data_synapse);
debugInterface.getPortListenWriter().println(data_synapse_variables);
debugInterface.getPortListenWriter().flush();
} else if (propertyOrProperties.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLE)) {
JSONObject data_synapse = new JSONObject(((Axis2MessageContext) synCtx).getVariables());
Object result = null;
if (data_synapse.has(property_arguments
.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLE_NAME))) {
result = data_synapse.get(property_arguments
.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLE_NAME));
}
JSONObject json_result = new JSONObject();
json_result.put(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLE_NAME),
result);
debugInterface.getPortListenWriter().println(json_result);
debugInterface.getPortListenWriter().flush();
}
} catch (JSONException ex) {
log.error("Failed to acquire property in the scope: " + propertyContext, ex);
Expand Down Expand Up @@ -1333,4 +1364,33 @@ public void update(Observable o, Object arg) {
}
}
}

/**
* This method is used to add or remove a variable in the mediation flow point.
*
* @param variableArguments
* @param isActionSet
*/
private void addMediationFlowPointVariable(JSONObject variableArguments, boolean isActionSet) {

try {
String variableName = variableArguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLE_NAME);
if (isActionSet) {
String variableValue = variableArguments
.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_VARIABLE_VALUE);
synCtx.setVariable(variableName, variableValue);
} else {
Set variableKeySet = synCtx.getVariableKeySet();
if (variableKeySet != null) {
variableKeySet.remove(variableName);
}
}
} catch (JSONException e) {
log.error("Failed to set or remove variable.", e);
this.advertiseCommandResponse(createDebugCommandResponse(false,
SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_UNABLE_TO_ALTER_VARIABLE)
.toString());
}
this.advertiseCommandResponse(createDebugCommandResponse(true, null).toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public class SynapseDebugCommandConstants {
public static final String DEBUG_COMMAND_PROPERTY_NAME = "property-name";
public static final String DEBUG_COMMAND_PROPERTY_VALUE = "property-value";
public static final String DEBUG_COMMAND_PROPERTIES = "properties";
public static final String DEBUG_COMMAND_VARIABLES = "variables";
public static final String DEBUG_COMMAND_VARIABLE = "variable";
public static final String DEBUG_COMMAND_VARIABLE_NAME = "variable-name";
public static final String DEBUG_COMMAND_VARIABLE_VALUE = "variable-value";
public static final String DEBUG_COMMAND_PROPERTY_CONTEXT = "context";
public static final String DEBUG_COMMAND_PROPERTY_CONTEXT_ALL = "all";
public static final String DEBUG_COMMAND_PROPERTY_CONTEXT_AXIS2 = "axis2";
Expand All @@ -61,6 +65,7 @@ public class SynapseDebugCommandConstants {
public static final String DEBUG_COMMAND_RESPONSE_PROPERTY_CONTEXT_AXIS2CLIENT = "axis2Client-properties";
public static final String DEBUG_COMMAND_RESPONSE_PROPERTY_CONTEXT_AXIS2TRANSPORT = "axis2Transport-properties";
public static final String DEBUG_COMMAND_RESPONSE_PROPERTY_CONTEXT_AXIS2OPERATION = "axis2Operation-properties";
public static final String DEBUG_COMMAND_RESPONSE_VARIABLES = "message-variables";
public static final String DEBUG_COMMAND_EXIT = "exit";
public static final String DEBUG_COMMAND_RESUME = "resume";
public static final String DEBUG_COMMAND_STEP = "step";
Expand All @@ -77,6 +82,8 @@ public class SynapseDebugCommandConstants {
public static final String DEBUG_COMMAND_RESPONSE_UNABLE_TO_REGISTER_FLOW_POINT = "unable to register mediation flow point";
public static final String DEBUG_COMMAND_RESPONSE_UNABLE_TO_ACQUIRE_MESSAGE_CONTEXT_PROPERTIES = "unable to acquire message context properties";
public static final String DEBUG_COMMAND_RESPONSE_UNABLE_TO_ALTER_MESSAGE_CONTEXT_PROPERTY = "unable to alter message context property";
public static final String DEBUG_COMMAND_RESPONSE_UNABLE_TO_ACQUIRE_VARIABLES = "unable to acquire message variables";
public static final String DEBUG_COMMAND_RESPONSE_UNABLE_TO_ALTER_VARIABLE = "unable to alter message variable";
public static final String DEBUG_COMMAND_RESPONSE_API_RESOURCE_NOT_FOUND = "api resource not found";
public static final String DEBUG_COMMAND_RESPONSE_API_NOT_FOUND = "api not found";
public static final String DEBUG_COMMAND_RESPONSE_PROXY_NOT_FOUND = "proxy not found";
Expand Down

0 comments on commit 9a94a60

Please sign in to comment.