Search in sources :

Example 86 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class SequenceDebugUtil method registerSequenceMediationFlowSkip.

/**
 * Registers/Un-registers a breakpoint, point where mediation flow get suspended
 *
 * @param synCfg Synapse configuration
 * @param seqType Synapse sequence type
 * @param seqKey name of the Sequence
 * @param position array of integers that uniquely specifies a point in mediation route
 * @param registerMode specify whether register or un register
 */
public static void registerSequenceMediationFlowSkip(SynapseConfiguration synCfg, String seqType, String seqKey, int[] position, boolean registerMode) {
    SynapseSequenceType synapseSequenceType = SynapseSequenceType.valueOf(seqType.toUpperCase());
    SequenceMediationFlowPoint skipPoint = new SequenceMediationFlowPoint();
    skipPoint.setSynapseMediationComponent(SynapseMediationComponent.SEQUENCE);
    skipPoint.setKey(seqKey);
    skipPoint.setMediatorPosition(position);
    skipPoint.setSynapseSequenceType(synapseSequenceType);
    skipPoint.setSequenceBaseType(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE);
    Mediator seqMediator = null;
    if (synapseSequenceType.equals(SynapseSequenceType.NAMED)) {
        seqMediator = synCfg.getSequence(seqKey);
    }
    if (seqMediator != null) {
        Mediator current_mediator = null;
        current_mediator = MediatorTreeTraverseUtil.getMediatorReference(synCfg, seqMediator, 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 Sequence " + skipPoint.getKey());
                    }
                    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 Sequence " + skipPoint.getKey());
                    }
                    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 Sequence " + skipPoint.getKey());
                    }
                    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 Sequence " + skipPoint.getKey());
                    }
                    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 at " + logMediatorPosition(skipPoint) + " for Sequence " + skipPoint.getKey());
                }
                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 Sequence " + skipPoint.getKey());
                }
                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 sequence for key " + skipPoint.getKey());
            }
            debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Failed unregister skip. Non existing sequence for key " + skipPoint.getKey());
            }
            debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
        }
    }
}
Also used : SequenceMediationFlowPoint(org.apache.synapse.debug.constructs.SequenceMediationFlowPoint) SynapseSequenceType(org.apache.synapse.debug.constructs.SynapseSequenceType) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator)

Example 87 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class TemplateDebugUtil method registerTemplateMediationFlowSkip.

/**
 * Registers/Un-registers a skip, point where mediator disables from mediation flow
 *
 * @param synCfg Synapse configuration
 * @param templateKey name of the Template
 * @param position array of integers that uniquely specifies a point in mediation route
 * @param registerMode specify whether register or un register
 */
public static void registerTemplateMediationFlowSkip(SynapseConfiguration synCfg, String templateKey, int[] position, boolean registerMode) {
    SynapseMediationFlowPoint skipPoint = new SynapseMediationFlowPoint();
    skipPoint.setSynapseMediationComponent(SynapseMediationComponent.TEMPLATE);
    skipPoint.setKey(templateKey);
    skipPoint.setMediatorPosition(position);
    Mediator templateMediator = null;
    templateMediator = synCfg.getSequenceTemplate(templateKey);
    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 Template key " + skipPoint.getKey());
                    }
                    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 Template key " + skipPoint.getKey());
                    }
                    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 Template key " + skipPoint.getKey());
                    }
                    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 Template key " + skipPoint.getKey());
                    }
                    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 at " + logMediatorPosition(skipPoint) + " for Template key " + skipPoint.getKey());
                }
                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 Template key " + skipPoint.getKey());
                }
                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 key " + skipPoint.getKey());
            }
            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 key " + skipPoint.getKey());
            }
            debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_TEMPLATE).toString());
        }
    }
}
Also used : SynapseMediationFlowPoint(org.apache.synapse.debug.constructs.SynapseMediationFlowPoint) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator)

Example 88 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class TemplateDebugUtil method registerTemplateMediationFlowBreakPoint.

/**
 * Registers/Un-registers a breakpoint, point where mediation flow gets suspended
 *
 * @param synCfg Synapse configuration
 * @param templateKey name of the Template
 * @param position array of integers that uniquely specifies a point in mediation route
 * @param registerMode specify whether register or un register
 */
public static void registerTemplateMediationFlowBreakPoint(SynapseConfiguration synCfg, String templateKey, int[] position, boolean registerMode) {
    SynapseMediationFlowPoint breakPoint = new SynapseMediationFlowPoint();
    breakPoint.setSynapseMediationComponent(SynapseMediationComponent.TEMPLATE);
    breakPoint.setKey(templateKey);
    breakPoint.setMediatorPosition(position);
    Mediator templateMediator = null;
    templateMediator = synCfg.getSequenceTemplate(templateKey);
    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 Template key " + breakPoint.getKey());
                    }
                    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 Template key " + breakPoint.getKey());
                    }
                    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 Template key " + breakPoint.getKey());
                    }
                    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 Template key " + breakPoint.getKey());
                    }
                    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 Template key " + breakPoint.getKey());
                }
                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 Template key " + breakPoint.getKey());
                }
                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 key " + breakPoint.getKey());
            }
            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 key " + breakPoint.getKey());
            }
            debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_TEMPLATE).toString());
        }
    }
}
Also used : SynapseMediationFlowPoint(org.apache.synapse.debug.constructs.SynapseMediationFlowPoint) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) AbstractMediator(org.apache.synapse.mediators.AbstractMediator)

Example 89 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class SequenceDeployer method deploySynapseArtifact.

@Override
public String deploySynapseArtifact(OMElement artifactConfig, String fileName, Properties properties) {
    CustomLogSetter.getInstance().setLogAppender(customLogContent);
    if (log.isDebugEnabled()) {
        log.debug("Sequence Deployment from file : " + fileName + " : Started");
    }
    try {
        MediatorFactoryFinder.getInstance().setSynapseLibraryMap(getSynapseConfiguration().getSynapseLibraries());
        Mediator m = MediatorFactoryFinder.getInstance().getMediator(artifactConfig, properties);
        if (m instanceof SequenceMediator) {
            SequenceMediator seq = (SequenceMediator) m;
            seq.setArtifactContainerName(customLogContent);
            seq.setFileName((new File(fileName)).getName());
            if (log.isDebugEnabled()) {
                log.debug("Sequence named '" + seq.getName() + "' has been built from the file " + fileName);
            }
            seq.init(getSynapseEnvironment());
            if (log.isDebugEnabled()) {
                log.debug("Initialized the sequence : " + seq.getName());
            }
            getSynapseConfiguration().addSequence(seq.getName(), seq);
            if (log.isDebugEnabled()) {
                log.debug("Sequence Deployment from file : " + fileName + " : Completed");
            }
            log.info("Sequence named '" + seq.getName() + "' has been deployed from file : " + fileName);
            return seq.getName();
        } else {
            handleSynapseArtifactDeploymentError("Sequence Deployment Failed. " + "The artifact described in the file " + fileName + " is not a Sequence");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Sequence Deployment from the file : " + fileName + " : Failed.", e);
    }
    return null;
}
Also used : Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) File(java.io.File) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 90 with Mediator

use of org.apache.synapse.Mediator in project wso2-synapse by wso2.

the class TemplateDeployer method deploySynapseArtifact.

@Override
public String deploySynapseArtifact(OMElement artifactConfig, String fileName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Template Deployment from file : " + fileName + " : Started");
    }
    try {
        OMElement element = artifactConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "endpoint"));
        if (element != null) {
            org.apache.synapse.config.xml.endpoints.TemplateFactory templateFactory = new org.apache.synapse.config.xml.endpoints.TemplateFactory();
            Template tm = templateFactory.createEndpointTemplate(artifactConfig, properties);
            tm.setFileName(new File(fileName).getName());
            /**
             * Set the artifact container name of the Template
             */
            tm.setArtifactContainerName(customLogContent);
            if (log.isDebugEnabled()) {
                log.debug("Endpoint Template named '" + tm.getName() + "' has been built from the file " + fileName);
            }
            getSynapseConfiguration().addEndpointTemplate(tm.getName(), tm);
            if (log.isDebugEnabled()) {
                log.debug("Template Deployment from file : " + fileName + " : Completed");
            }
            log.info("Endpoint Template named '" + tm.getName() + "' has been deployed from file : " + fileName);
            return tm.getName();
        } else {
            element = artifactConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sequence"));
            if (element != null) {
                Mediator mediator = MediatorFactoryFinder.getInstance().getMediator(artifactConfig, properties);
                if (mediator instanceof TemplateMediator) {
                    TemplateMediator tm = (TemplateMediator) mediator;
                    /**
                     * Set the artifact container name of the Template
                     */
                    tm.setArtifactContainerName(customLogContent);
                    tm.setFileName((new File(fileName)).getName());
                    if (log.isDebugEnabled()) {
                        log.debug("Sequence Template named '" + tm.getName() + "' has been built from the file " + fileName);
                    }
                    tm.init(getSynapseEnvironment());
                    if (log.isDebugEnabled()) {
                        log.debug("Initialized the Template : " + tm.getName());
                    }
                    getSynapseConfiguration().addSequenceTemplate(tm.getName(), tm);
                    if (log.isDebugEnabled()) {
                        log.debug("Template Deployment from file : " + fileName + " : Completed");
                    }
                    log.info("Template named '" + tm.getName() + "' has been deployed from file : " + fileName);
                    return tm.getName();
                }
            }
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Template Deployment from the file : " + fileName + " : Failed.", e);
    }
    return null;
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) SynapseException(org.apache.synapse.SynapseException) DeploymentException(org.apache.axis2.deployment.DeploymentException) Template(org.apache.synapse.endpoints.Template) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) Mediator(org.apache.synapse.Mediator) File(java.io.File)

Aggregations

Mediator (org.apache.synapse.Mediator)108 Properties (java.util.Properties)30 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)24 OMElement (org.apache.axiom.om.OMElement)22 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)22 MessageContext (org.apache.synapse.MessageContext)16 SynapseLog (org.apache.synapse.SynapseLog)16 FlowContinuableMediator (org.apache.synapse.mediators.FlowContinuableMediator)13 SynapseException (org.apache.synapse.SynapseException)12 TestMessageContext (org.apache.synapse.TestMessageContext)12 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)12 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)12 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)12 Test (org.junit.Test)10 AbstractListMediator (org.apache.synapse.mediators.AbstractListMediator)9 SynapseSequenceType (org.apache.synapse.debug.constructs.SynapseSequenceType)8 SequenceMediationFlowPoint (org.apache.synapse.debug.constructs.SequenceMediationFlowPoint)6 ForEachMediatorFactory (org.apache.synapse.config.xml.ForEachMediatorFactory)5 MediatorFactory (org.apache.synapse.config.xml.MediatorFactory)5 MediatorFaultHandler (org.apache.synapse.mediators.MediatorFaultHandler)5