Search in sources :

Example 46 with Mediator

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

the class SpringMediator method mediate.

public boolean mediate(MessageContext synCtx) {
    if (synCtx.getEnvironment().isDebuggerEnabled()) {
        if (super.divertMediationRoute(synCtx)) {
            return true;
        }
    }
    SynapseLog synLog = getLog(synCtx);
    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Start : Spring mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synCtx.getEnvelope());
        }
    }
    Entry entry = synCtx.getConfiguration().getEntryDefinition(configKey);
    // if the configKey refers to a dynamic property
    if (entry != null && entry.isDynamic()) {
        if (!entry.isCached() || entry.isExpired()) {
            buildAppContext(synCtx, synLog);
        }
    // if the property is not a DynamicProperty, we will create an ApplicationContext only once
    } else {
        if (appContext == null) {
            buildAppContext(synCtx, synLog);
        }
    }
    if (appContext != null) {
        Object o = null;
        try {
            o = appContext.getBean(beanName);
            if (o != null && Mediator.class.isAssignableFrom(o.getClass())) {
                Mediator m = (Mediator) o;
                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Loaded mediator from bean : " + beanName + " executing...");
                }
                return m.mediate(synCtx);
            } else {
                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Unable to load mediator from bean : " + beanName);
                }
                handleException("Could not load bean named : " + beanName + " from the Spring configuration with key : " + configKey, synCtx);
            }
        } catch (Exception e) {
            if (o == null) {
                handleException("No bean named '" + beanName + "' is defined", synCtx);
            } else {
                handleException("Error in " + o.getClass().getName(), synCtx);
            }
        }
    } else {
        handleException("Cannot reference application context with key : " + configKey, synCtx);
    }
    synLog.traceOrDebug("End : Spring mediator");
    return true;
}
Also used : Entry(org.apache.synapse.config.Entry) SynapseLog(org.apache.synapse.SynapseLog) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator)

Example 47 with Mediator

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

the class ScriptMediatorFactoryTest method testRegPropMediatorFactory.

public void testRegPropMediatorFactory() throws Exception {
    Entry prop = new Entry();
    prop.setKey("MyMediator");
    prop.setValue(MY_MEDIATOR);
    Map<String, Entry> props = new HashMap<String, Entry>();
    props.put("MyMediator", prop);
    MessageContext mc = TestUtils.getTestContext("<foo/>", props);
    ScriptMediatorFactory mf = new ScriptMediatorFactory();
    Mediator mediator = mf.createMediator(REG_PROP_MEDIATOR_CONFIG, new Properties());
    assertTrue(mediator.mediate(mc));
}
Also used : Entry(org.apache.synapse.config.Entry) HashMap(java.util.HashMap) Mediator(org.apache.synapse.Mediator) MessageContext(org.apache.synapse.MessageContext) Properties(java.util.Properties)

Example 48 with Mediator

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

the class LoopBackMediatorFactory method createSpecificMediator.

@Override
protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
    Mediator loopBackMediator = new LoopBackMediator();
    processAuditStatus(loopBackMediator, elem);
    return loopBackMediator;
}
Also used : LoopBackMediator(org.apache.synapse.mediators.builtin.LoopBackMediator) LoopBackMediator(org.apache.synapse.mediators.builtin.LoopBackMediator) Mediator(org.apache.synapse.Mediator)

Example 49 with Mediator

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

the class Axis2MessageContext method getSequence.

public Mediator getSequence(String key) {
    Object o = localEntries.get(key);
    if (o != null && o instanceof Mediator) {
        return (Mediator) o;
    } else {
        Mediator m = getConfiguration().getSequence(key);
        if (m instanceof SequenceMediator) {
            SequenceMediator seqMediator = (SequenceMediator) m;
            synchronized (m) {
                if (!seqMediator.isInitialized()) {
                    seqMediator.init(synEnv);
                }
            }
        }
        localEntries.put(key, m);
        return m;
    }
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 50 with Mediator

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

the class Axis2MessageContext method getMainSequence.

public Mediator getMainSequence() {
    Object o = localEntries.get(SynapseConstants.MAIN_SEQUENCE_KEY);
    if (o != null && o instanceof Mediator) {
        return (Mediator) o;
    } else {
        Mediator main = getConfiguration().getMainSequence();
        localEntries.put(SynapseConstants.MAIN_SEQUENCE_KEY, main);
        return main;
    }
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

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