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;
}
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));
}
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;
}
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;
}
}
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;
}
}
Aggregations