use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class Axis2MessageContext method getDefaultConfiguration.
public Mediator getDefaultConfiguration(String key) {
Object o = localEntries.get(key);
if (o != null && o instanceof Mediator) {
return (Mediator) o;
} else {
Mediator m = getConfiguration().getDefaultConfiguration(key);
localEntries.put(key, m);
return m;
}
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class Axis2SynapseEnvironment method injectMessage.
public boolean injectMessage(final MessageContext synCtx) {
try {
if (log.isDebugEnabled()) {
log.debug("Injecting MessageContext");
}
if (synCtx.getEnvironment().isDebuggerEnabled()) {
SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
debugManager.acquireMediationFlowLock();
debugManager.advertiseMediationFlowStartPoint(synCtx);
}
// setting transport-in name as a message context property
TransportInDescription trpInDesc = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getTransportIn();
if (trpInDesc != null) {
synCtx.setProperty(SynapseConstants.TRANSPORT_IN_NAME, trpInDesc.getName());
}
synCtx.setEnvironment(this);
if (!invokeHandlers(synCtx)) {
return false;
}
Mediator mandatorySeq = synCtx.getConfiguration().getMandatorySequence();
// the mandatory sequence is optional and hence check for the existence before mediation
if (mandatorySeq != null) {
if (log.isDebugEnabled()) {
log.debug("Start mediating the message in the " + "pre-mediate state using the mandatory sequence");
}
if (!mandatorySeq.mediate(synCtx)) {
if (log.isDebugEnabled()) {
log.debug((synCtx.isResponse() ? "Response" : "Request") + " message for the " + (synCtx.getProperty(SynapseConstants.PROXY_SERVICE) != null ? "proxy service " + synCtx.getProperty(SynapseConstants.PROXY_SERVICE) : "message mediation") + " dropped in the " + "pre-mediation state by the mandatory sequence : \n" + synCtx);
}
return false;
}
}
String receivingSequence = (String) synCtx.getProperty(SynapseConstants.RECEIVING_SEQUENCE);
Boolean isContinuationCall = (Boolean) synCtx.getProperty(SynapseConstants.CONTINUATION_CALL);
// clear the message context properties related to endpoint in last service invocation
Set keySet = synCtx.getPropertyKeySet();
if (keySet != null) {
keySet.remove(SynapseConstants.RECEIVING_SEQUENCE);
keySet.remove(SynapseConstants.CONTINUATION_CALL);
}
if (isContinuationCall != null && isContinuationCall && !synCtx.getContinuationStateStack().isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("Response received for the Continuation Call service invocation");
}
return mediateFromContinuationStateStack(synCtx);
}
// if this is not a response to a proxy service
String proxyName = (String) synCtx.getProperty(SynapseConstants.PROXY_SERVICE);
if (proxyName == null || "".equals(proxyName)) {
// set default fault handler
synCtx.pushFaultHandler(new MediatorFaultHandler(synCtx.getFaultSequence()));
if (receivingSequence != null) {
if (log.isDebugEnabled()) {
log.debug("Using Sequence with name: " + receivingSequence + " for injected message");
}
Mediator seqMediator = synCtx.getSequence(receivingSequence);
if (seqMediator != null) {
return seqMediator.mediate(synCtx);
} else {
log.warn("Cannot find a Sequence with name: " + receivingSequence + " for injecting the response message");
return false;
}
} else {
boolean processed = restHandler.process(synCtx);
if (processed) {
return true;
}
if (log.isDebugEnabled()) {
log.debug("Using Main Sequence for injected message");
}
return synCtx.getMainSequence().mediate(synCtx);
}
}
ProxyService proxyService = synCtx.getConfiguration().getProxyService(proxyName);
if (proxyService != null) {
proxyService.registerFaultHandler(synCtx);
Mediator outSequence = getProxyOutSequence(synCtx, proxyService);
if (receivingSequence != null) {
if (log.isDebugEnabled()) {
log.debug("Using Sequence with name: " + receivingSequence + " for injected message");
}
Mediator seqMediator = synCtx.getSequence(receivingSequence);
if (seqMediator != null) {
seqMediator.mediate(synCtx);
} else {
log.warn("Cannot find a Sequence with name: " + receivingSequence + " for injecting the message");
return false;
}
} else if (outSequence != null) {
outSequence.mediate(synCtx);
} else {
if (log.isDebugEnabled()) {
log.debug(proxyService + " does not specifies an out-sequence - sending the response back");
}
Axis2Sender.sendBack(synCtx);
}
}
return true;
} finally {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
debugManager.advertiseMediationFlowTerminatePoint(synCtx);
debugManager.releaseMediationFlowLock();
}
}
}
use of org.apache.synapse.Mediator 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.Mediator in project wso2-synapse by wso2.
the class ConnectorDebugUtil method registerConnectorMediationFlowSkip.
/**
* Registers/Un-registers a skip, point where mediator disables from mediation flow
*
* @param synCfg Synapse configuration
* @param connectorMethod method name of the template
* @param connectorKey name of the Connector
* @param position array of integers that uniquely specifies a point in mediation route
* @param registerMode specify whether register or un register
*/
public static void registerConnectorMediationFlowSkip(SynapseConfiguration synCfg, String connectorKey, String connectorMethod, int[] position, boolean registerMode) {
ConnectorMediationFlowPoint skipPoint = new ConnectorMediationFlowPoint();
skipPoint.setSynapseMediationComponent(SynapseMediationComponent.CONNECTOR);
skipPoint.setKey(connectorKey);
skipPoint.setConnectorMediationComponentMethod(connectorMethod);
skipPoint.setMediatorPosition(position);
Mediator templateMediator = null;
String template_key = SynapseDebugManagerConstants.CONNECTOR_PACKAGE + "." + connectorKey + "." + connectorMethod;
templateMediator = synCfg.getSequenceTemplate(template_key);
if (templateMediator != null) {
Mediator current_mediator = null;
current_mediator = MediatorTreeTraverseUtil.getMediatorReference(synCfg, templateMediator, position);
if (current_mediator != null) {
skipPoint.setMediatorReference(current_mediator);
if (registerMode) {
if (!((AbstractMediator) current_mediator).isSkipEnabled()) {
((AbstractMediator) current_mediator).setSkipEnabled(true);
((AbstractMediator) current_mediator).registerMediationFlowPoint(skipPoint);
if (log.isDebugEnabled()) {
log.debug("Registered skip at mediator position " + logMediatorPosition(skipPoint) + " for Connector key " + skipPoint.getKey() + " method " + skipPoint.getConnectorMediationComponentMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed register skip. Already skip enabled at mediator position " + logMediatorPosition(skipPoint) + " for Connector key " + skipPoint.getKey() + " method " + skipPoint.getConnectorMediationComponentMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_SKIP_ENABLED).toString());
}
} else {
if (((AbstractMediator) current_mediator).isSkipEnabled()) {
((AbstractMediator) current_mediator).unregisterMediationFlowPoint();
((AbstractMediator) current_mediator).setSkipEnabled(false);
if (log.isDebugEnabled()) {
log.debug("Unregistered skip at mediator position " + logMediatorPosition(skipPoint) + " for Connector key " + skipPoint.getKey() + " method " + skipPoint.getConnectorMediationComponentMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister skip. Already skip disabled at mediator position " + logMediatorPosition(skipPoint) + " for Connector key " + skipPoint.getKey() + " method " + skipPoint.getConnectorMediationComponentMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_SKIP_DISABLED).toString());
}
}
} else {
if (registerMode) {
if (log.isDebugEnabled()) {
log.debug("Failed register skip. Non existing mediator position " + logMediatorPosition(skipPoint) + " for Connector key " + skipPoint.getKey() + " method " + skipPoint.getConnectorMediationComponentMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister skip. Non existing mediator position at " + logMediatorPosition(skipPoint) + " for Connector key " + skipPoint.getKey() + " method " + skipPoint.getConnectorMediationComponentMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
}
}
} else {
if (registerMode) {
if (log.isDebugEnabled()) {
log.debug("Failed register skip. Non existing template for Connector key " + skipPoint.getKey() + " method " + skipPoint.getConnectorMediationComponentMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_TEMPLATE).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister skip. Non existing template for Connector key " + skipPoint.getKey() + " method " + skipPoint.getConnectorMediationComponentMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_TEMPLATE).toString());
}
}
}
use of org.apache.synapse.Mediator in project wso2-synapse by wso2.
the class ConnectorDebugUtil method registerConnectorMediationFlowBreakPoint.
/**
* Registers/Un-registers a breakpoint, point where mediation flow get suspended
*
* @param synCfg Synapse configuration
* @param connectorMethod method name of the template
* @param connectorKey name of the Connector
* @param position array of integers that uniquely specifies a point in mediation route
* @param registerMode specify whether register or un register
*/
public static void registerConnectorMediationFlowBreakPoint(SynapseConfiguration synCfg, String connectorKey, String connectorMethod, int[] position, boolean registerMode) {
ConnectorMediationFlowPoint breakPoint = new ConnectorMediationFlowPoint();
breakPoint.setSynapseMediationComponent(SynapseMediationComponent.CONNECTOR);
breakPoint.setKey(connectorKey);
breakPoint.setConnectorMediationComponentMethod(connectorMethod);
breakPoint.setMediatorPosition(position);
Mediator templateMediator = null;
String template_key = SynapseDebugManagerConstants.CONNECTOR_PACKAGE + "." + connectorKey + "." + connectorMethod;
templateMediator = synCfg.getSequenceTemplate(template_key);
if (templateMediator != null) {
Mediator current_mediator = null;
current_mediator = MediatorTreeTraverseUtil.getMediatorReference(synCfg, templateMediator, 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.debug("Registered breakpoint at mediator position " + logMediatorPosition(breakPoint) + " for Connector key " + breakPoint.getKey() + " method " + breakPoint.getConnectorMediationComponentMethod());
}
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 Connector key " + breakPoint.getKey() + " method " + breakPoint.getConnectorMediationComponentMethod());
}
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 Connector key " + breakPoint.getKey() + " method " + breakPoint.getConnectorMediationComponentMethod());
}
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 Connector key " + breakPoint.getKey() + " method " + breakPoint.getConnectorMediationComponentMethod());
}
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 Connector key " + breakPoint.getKey() + " method " + breakPoint.getConnectorMediationComponentMethod());
}
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 Connector key " + breakPoint.getKey() + " method " + breakPoint.getConnectorMediationComponentMethod());
}
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 template for Connector key " + breakPoint.getKey() + " method " + breakPoint.getConnectorMediationComponentMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_TEMPLATE).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister breakpoint. Non existing template for Connector key " + breakPoint.getKey() + " method " + breakPoint.getConnectorMediationComponentMethod());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_TEMPLATE).toString());
}
}
}
Aggregations