use of org.apache.synapse.mediators.AbstractMediator in project wso2-synapse by wso2.
the class APIDebugUtil method registerAPISequenceMediationFlowBreakPoint.
/**
* Registers/Un-registers a breakpoint, point where mediation flow get suspended
*
* @param synCfg Synapse configuration
* @param mapping either resource url-mapping or uri-template
* @param method resource http method
* @param sequenceType Synapse sequence type
* @param apiKey name of the API
* @param position array of integers that uniquely specifies a point in mediation route
* @param registerMode specify whether register or un register
*/
public static void registerAPISequenceMediationFlowBreakPoint(SynapseConfiguration synCfg, String mapping, String method, String sequenceType, String apiKey, int[] position, boolean registerMode) {
SynapseSequenceType synapseSequenceType = SynapseSequenceType.valueOf(sequenceType.toUpperCase());
APIMediationFlowPoint breakPoint = new APIMediationFlowPoint();
breakPoint.setSynapseMediationComponent(SynapseMediationComponent.SEQUENCE);
breakPoint.setKey(apiKey);
breakPoint.setMediatorPosition(position);
breakPoint.setSynapseSequenceType(synapseSequenceType);
breakPoint.setSequenceBaseType(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_API);
breakPoint.setResourceMapping(mapping);
breakPoint.setResourceHTTPMethod(method);
Mediator seqMediator = null;
Resource api_resource = null;
API api = synCfg.getAPI(apiKey);
if (api == null) {
if (log.isDebugEnabled()) {
log.debug("Non existing API for the key " + breakPoint.getKey());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_API_NOT_FOUND).toString());
return;
}
Resource[] resource_array = api.getResources();
for (int counter = 0; counter < resource_array.length; counter++) {
if (resource_array[counter].getDispatcherHelper() != null && mapping != null) {
if (mapping.equals(resource_array[counter].getDispatcherHelper().getString())) {
for (String m1 : resource_array[counter].getMethods()) {
if (m1.equals(method)) {
api_resource = resource_array[counter];
break;
}
}
if (api_resource != null) {
break;
}
}
} else if (resource_array[counter].getDispatcherHelper() == null && mapping == null) {
for (String m1 : resource_array[counter].getMethods()) {
if (m1.equals(method)) {
api_resource = resource_array[counter];
break;
}
}
if (api_resource != null) {
break;
}
}
}
if (api_resource != null) {
if (synapseSequenceType.equals(SynapseSequenceType.API_INSEQ)) {
seqMediator = api_resource.getInSequence();
} else if (synapseSequenceType.equals(SynapseSequenceType.API_OUTSEQ)) {
seqMediator = api_resource.getOutSequence();
} else if (synapseSequenceType.equals(SynapseSequenceType.API_FAULTSEQ)) {
seqMediator = api_resource.getFaultSequence();
}
} else {
if (log.isDebugEnabled()) {
log.debug("Resource not found for the API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_API_RESOURCE_NOT_FOUND).toString());
return;
}
if (seqMediator != null) {
Mediator current_mediator = null;
current_mediator = MediatorTreeTraverseUtil.getMediatorReference(synCfg, seqMediator, position);
if (current_mediator != null) {
breakPoint.setMediatorReference(current_mediator);
if (registerMode) {
if (!((AbstractMediator) current_mediator).isBreakPoint()) {
((AbstractMediator) current_mediator).setBreakPoint(true);
((AbstractMediator) current_mediator).registerMediationFlowPoint(breakPoint);
if (log.isDebugEnabled()) {
log.info("Registered breakpoint at mediator position " + logMediatorPosition(breakPoint) + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod() + " sequence type " + breakPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed register breakpoint. Already breakpoint enabled at mediator position " + logMediatorPosition(breakPoint) + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod() + " sequence type " + breakPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_BREAKPOINT_ENABLED).toString());
}
} else {
if (((AbstractMediator) current_mediator).isBreakPoint()) {
((AbstractMediator) current_mediator).unregisterMediationFlowPoint();
((AbstractMediator) current_mediator).setBreakPoint(false);
if (log.isDebugEnabled()) {
log.debug("Unregistered breakpoint at mediator position " + logMediatorPosition(breakPoint) + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod() + " sequence type " + breakPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister breakpoint. Already breakpoint disabled at mediator position " + logMediatorPosition(breakPoint) + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod() + " sequence type " + breakPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_BREAKPOINT_DISABLED).toString());
}
}
} else {
if (registerMode) {
if (log.isDebugEnabled()) {
log.debug("Failed register breakpoint. Non existing mediator position at " + logMediatorPosition(breakPoint) + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod() + " sequence type " + breakPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister breakpoint. Non existing mediator position at " + logMediatorPosition(breakPoint) + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod() + " sequence type " + breakPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
}
}
} else {
if (registerMode) {
if (log.isDebugEnabled()) {
log.debug("Failed register breakpoint. Non existing sequence " + breakPoint.getSynapseSequenceType().toString() + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister breakpoint. Non existing sequence " + breakPoint.getSynapseSequenceType().toString() + " for API key " + breakPoint.getKey() + " resource mapping " + breakPoint.getResourceMapping() + " resource HTTP method " + breakPoint.getResourceHTTPMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
}
}
}
use of org.apache.synapse.mediators.AbstractMediator in project wso2-synapse by wso2.
the class DebugManagerTest method testDebugManagerProcessCommandClearSkipProxyInSequence.
public void testDebugManagerProcessCommandClearSkipProxyInSequence() throws Exception {
ProxyService ps = new ProxyService("test_proxy_7");
TestMediator in1 = new TestMediator();
TestMediator in2 = new TestMediator();
TestMediator in3 = new TestMediator();
SequenceMediator inSeq = new SequenceMediator();
inSeq.addChild(in1);
inSeq.addChild(in2);
inSeq.addChild(in3);
TestMediator out1 = new TestMediator();
TestMediator out2 = new TestMediator();
TestMediator out3 = new TestMediator();
SequenceMediator outSeq = new SequenceMediator();
outSeq.addChild(out1);
outSeq.addChild(out2);
outSeq.addChild(out3);
ps.setTargetInLineInSequence(inSeq);
ps.setTargetInLineOutSequence(inSeq);
synConfig.addProxyService(ps.getName(), ps);
String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_7\",\"sequence-type\":\"proxy_inseq\"," + "\"mediator-position\":\"0\"}}}";
dm.processDebugCommand(debug_command);
debug_command = "{\"command\":\"clear\",\"command-argument\":\"skip\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_7\",\"sequence-type\":\"proxy_inseq\"," + "\"mediator-position\":\"0\"}}}";
dm.processDebugCommand(debug_command);
assertTrue(!((AbstractMediator) ps.getTargetInLineInSequence().getChild(0)).isSkipEnabled());
}
use of org.apache.synapse.mediators.AbstractMediator in project wso2-synapse by wso2.
the class DebugManagerTest method testDebugManagerProcessCommandClearSkipTemplate.
public void testDebugManagerProcessCommandClearSkipTemplate() throws Exception {
TestMediator t1 = new TestMediator();
TestMediator t2 = new TestMediator();
TestMediator t3 = new TestMediator();
TemplateMediator temp = new TemplateMediator();
temp.addChild(t1);
temp.addChild(t2);
temp.addChild(t3);
temp.setName("test_sequence_template_4");
synConfig.addSequenceTemplate(temp.getName(), temp);
String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\"," + "\"mediation-component\":\"template\",\"template\":{\"template-key\":\"test_sequence_template_4\"," + "\"mediator-position\": \"0\"}}";
dm.processDebugCommand(debug_command);
debug_command = "{\"command\":\"clear\",\"command-argument\":\"skip\",\"mediation-component\":\"template\"," + "\"template\":{\"template-key\":\"test_sequence_template_4\",\"mediator-position\": \"0\"}}";
dm.processDebugCommand(debug_command);
assertTrue(!((AbstractMediator) temp.getChild(0)).isSkipEnabled());
}
use of org.apache.synapse.mediators.AbstractMediator in project wso2-synapse by wso2.
the class DebugManagerTest method testDebugManagerProcessCommandClearBreakPointSequence.
public void testDebugManagerProcessCommandClearBreakPointSequence() throws Exception {
TestMediator t1 = new TestMediator();
TestMediator t2 = new TestMediator();
TestMediator t3 = new TestMediator();
SequenceMediator seq = new SequenceMediator();
seq.addChild(t1);
seq.addChild(t2);
seq.addChild(t3);
synConfig.addSequence("test_sequence_2", seq);
String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\"," + "\"mediation-component\":\"sequence\",\"sequence\":{\"sequence-key\":\"test_sequence_2\"," + "\"sequence-type\": \"named\",\"mediator-position\": \"0\"}}";
dm.processDebugCommand(debug_command);
debug_command = "{\"command\":\"clear\",\"command-argument\":\"breakpoint\"," + "\"mediation-component\":\"sequence\",\"sequence\":{\"sequence-key\":\"test_sequence_2\"," + "\"sequence-type\": \"named\",\"mediator-position\": \"0\"}}";
dm.processDebugCommand(debug_command);
assertTrue(!((AbstractMediator) seq.getChild(0)).isBreakPoint());
}
use of org.apache.synapse.mediators.AbstractMediator in project wso2-synapse by wso2.
the class DebugManagerTest method testDebugManagerProcessCommandClearSkipSequence.
public void testDebugManagerProcessCommandClearSkipSequence() throws Exception {
TestMediator t1 = new TestMediator();
TestMediator t2 = new TestMediator();
TestMediator t3 = new TestMediator();
SequenceMediator seq = new SequenceMediator();
seq.addChild(t1);
seq.addChild(t2);
seq.addChild(t3);
synConfig.addSequence("test_sequence_4", seq);
String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\"," + "\"mediation-component\":\"sequence\",\"sequence\":{\"sequence-key\":\"test_sequence_4\"," + "\"sequence-type\": \"named\",\"mediator-position\": \"0\"}}";
dm.processDebugCommand(debug_command);
debug_command = "{\"command\":\"clear\",\"command-argument\":\"skip\"," + "\"mediation-component\":\"sequence\",\"sequence\":{\"sequence-key\":\"test_sequence_4\"," + "\"sequence-type\": \"named\",\"mediator-position\": \"0\"}}";
dm.processDebugCommand(debug_command);
assertTrue(!((AbstractMediator) seq.getChild(0)).isSkipEnabled());
}
Aggregations