use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class SynapseObserverTest method testSimpleObserver.
public void testSimpleObserver() {
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.setAxisConfiguration(new AxisConfiguration());
synapseConfig.registerObserver(observer);
Endpoint epr = new AddressEndpoint();
epr.setName("endpoint1");
synapseConfig.addEndpoint(epr.getName(), epr);
assertItemAdded(epr.getName(), ENDPOINT);
synapseConfig.removeEndpoint(epr.getName());
assertItemRemoved(epr.getName(), ENDPOINT);
SequenceMediator seq = new SequenceMediator();
seq.setName("sequence1");
synapseConfig.addSequence(seq.getName(), seq);
assertItemAdded(seq.getName(), SEQUENCE);
synapseConfig.removeSequence(seq.getName());
assertItemRemoved(seq.getName(), SEQUENCE);
TemplateMediator template = new TemplateMediator();
template.setName("template1");
synapseConfig.addSequenceTemplate(template.getName(), template);
assertItemAdded(template.getName(), SEQUENCE_TEMPLATE);
synapseConfig.removeSequenceTemplate(template.getName());
assertItemRemoved(template.getName(), SEQUENCE_TEMPLATE);
Entry entry = new Entry();
entry.setKey("entry1");
synapseConfig.addEntry(entry.getKey(), entry);
assertItemAdded(entry.getKey(), ENTRY);
synapseConfig.removeEntry(entry.getKey());
assertItemRemoved(entry.getKey(), ENTRY);
ProxyService proxy = new ProxyService("proxy1");
synapseConfig.addProxyService(proxy.getName(), proxy);
assertItemAdded(proxy.getName(), PROXY);
synapseConfig.removeProxyService(proxy.getName());
assertItemRemoved(proxy.getName(), PROXY);
Startup startup = new StartUpController();
startup.setName("startup1");
synapseConfig.addStartup(startup);
assertItemAdded(startup.getName(), STARTUP);
synapseConfig.removeStartup(startup.getName());
assertItemRemoved(startup.getName(), STARTUP);
SynapseEventSource eventSrc = new SynapseEventSource("eventSrc1");
synapseConfig.addEventSource(eventSrc.getName(), eventSrc);
assertItemAdded(eventSrc.getName(), EVENT_SRC);
synapseConfig.removeEventSource(eventSrc.getName());
assertItemRemoved(eventSrc.getName(), EVENT_SRC);
PriorityExecutor exec = new PriorityExecutor();
exec.setName("exec1");
synapseConfig.addPriorityExecutor(exec.getName(), exec);
assertItemAdded(exec.getName(), EXECUTOR);
synapseConfig.removeExecutor(exec.getName());
assertItemRemoved(exec.getName(), EXECUTOR);
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class TestMessageContext 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.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class SynapseConfigUtils method setDefaultFaultSequence.
/**
* Return the fault sequence if one is not defined. This implementation defaults to
* a simple sequence :
* <log level="full">
* <property name="MESSAGE" value="Executing default "fault" sequence"/>
* <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
* <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
* </log>
* <drop/>
*
* @param config the configuration to be updated
*/
public static void setDefaultFaultSequence(SynapseConfiguration config) {
SequenceMediator fault = new SequenceMediator();
fault.setName(org.apache.synapse.SynapseConstants.FAULT_SEQUENCE_KEY);
LogMediator log = new LogMediator();
log.setLogLevel(LogMediator.FULL);
MediatorProperty mp = new MediatorProperty();
mp.setName("MESSAGE");
mp.setValue("Executing default \"fault\" sequence");
log.addProperty(mp);
mp = new MediatorProperty();
mp.setName("ERROR_CODE");
try {
mp.setExpression(new SynapseXPath("get-property('ERROR_CODE')"));
} catch (JaxenException ignore) {
}
log.addProperty(mp);
mp = new MediatorProperty();
mp.setName("ERROR_MESSAGE");
try {
mp.setExpression(new SynapseXPath("get-property('ERROR_MESSAGE')"));
} catch (JaxenException ignore) {
}
log.addProperty(mp);
fault.addChild(log);
fault.addChild(new DropMediator());
// set aspect configuration
AspectConfiguration configuration = new AspectConfiguration(fault.getName());
fault.configure(configuration);
config.addSequence(org.apache.synapse.SynapseConstants.FAULT_SEQUENCE_KEY, fault);
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class SynapseConfigurationBuilder method getDefaultConfiguration.
/**
* Return the default Synapse Configuration
* @return the default configuration to be used
*/
public static SynapseConfiguration getDefaultConfiguration() {
// programatically create an empty configuration which just log and drop the messages
SynapseConfiguration config = SynapseConfigUtils.newConfiguration();
SequenceMediator mainMediator = new SequenceMediator();
InMediator inMediator = new InMediator();
inMediator.addChild(new LogMediator());
mainMediator.addChild(inMediator);
OutMediator outMediator = new OutMediator();
outMediator.addChild(new SendMediator());
mainMediator.addChild(outMediator);
mainMediator.setName(SynapseConstants.MAIN_SEQUENCE_KEY);
config.addSequence(SynapseConstants.MAIN_SEQUENCE_KEY, mainMediator);
SequenceMediator faultMediator = new SequenceMediator();
LogMediator fault = new LogMediator();
fault.setLogLevel(LogMediator.FULL);
faultMediator.addChild(fault);
faultMediator.setName(SynapseConstants.FAULT_SEQUENCE_KEY);
config.addSequence(SynapseConstants.FAULT_SEQUENCE_KEY, faultMediator);
config.setDescription("The default configuration of the ESB, that is created " + "programatically at the startup");
return config;
}
use of org.apache.synapse.mediators.base.SequenceMediator in project wso2-synapse by wso2.
the class MultiXMLConfigurationSerializer method serializeSynapseXML.
/**
* Serialize only the elements defined in the top level synapse.xml file back to the
* synapse.xml file. This method ignores the elements defined in files other than the
* synapse.xml. Can be used in situations where only the synapse.xml file should be
* updated at runtime.
*
* @param synapseConfig Current Synapse configuration
* @throws Exception on file I/O error
*/
public void serializeSynapseXML(SynapseConfiguration synapseConfig) throws Exception {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMElement definitions = fac.createOMElement("definitions", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
if (synapseConfig.getRegistry() != null && !Boolean.valueOf(synapseConfig.getProperty(MultiXMLConfigurationBuilder.SEPARATE_REGISTRY_DEFINITION))) {
RegistrySerializer.serializeRegistry(definitions, synapseConfig.getRegistry());
}
if (synapseConfig.getTaskManager() != null && !Boolean.valueOf(synapseConfig.getProperty(MultiXMLConfigurationBuilder.SEPARATE_TASK_MANAGER_DEFINITION))) {
TaskManagerSerializer.serializetaskManager(definitions, synapseConfig.getTaskManager());
}
Collection<ProxyService> proxyServices = synapseConfig.getProxyServices();
Collection<SynapseEventSource> eventSources = synapseConfig.getEventSources();
Collection<Startup> tasks = synapseConfig.getStartups();
Collection localEntries = synapseConfig.getLocalRegistry().values();
Collection<PriorityExecutor> executors = synapseConfig.getPriorityExecutors().values();
Collection<MessageStore> messageStores = synapseConfig.getMessageStores().values();
Collection<MessageProcessor> messageProcessors = synapseConfig.getMessageProcessors().values();
Collection<API> apiCollection = synapseConfig.getAPIs();
Collection<SynapseImport> synapseImportsCollection = synapseConfig.getSynapseImports().values();
Collection<InboundEndpoint> inboundEndpoints = synapseConfig.getInboundEndpoints();
Collection<String> comments = synapseConfig.getCommentedTextList();
for (ProxyService service : proxyServices) {
if (service.getFileName() == null) {
ProxyServiceSerializer.serializeProxy(definitions, service);
}
}
for (SynapseEventSource source : eventSources) {
if (source.getFileName() == null) {
EventSourceSerializer.serializeEventSource(definitions, source);
}
}
for (Startup task : tasks) {
if (task instanceof AbstractStartup && task.getFileName() == null) {
StartupFinder.getInstance().serializeStartup(definitions, task);
}
}
for (Object o : localEntries) {
if (o instanceof TemplateMediator) {
TemplateMediator template = (TemplateMediator) o;
if (template.getFileName() == null) {
MediatorSerializerFinder.getInstance().getSerializer(template).serializeMediator(definitions, template);
}
} else if (o instanceof SequenceMediator) {
SequenceMediator seq = (SequenceMediator) o;
if (seq.getFileName() == null) {
MediatorSerializerFinder.getInstance().getSerializer(seq).serializeMediator(definitions, seq);
}
} else if (o instanceof Template) {
Template templEndpoint = (Template) o;
if (templEndpoint.getFileName() == null) {
new TemplateSerializer().serializeEndpointTemplate(templEndpoint, definitions);
}
} else if (o instanceof AbstractEndpoint) {
AbstractEndpoint endpoint = (AbstractEndpoint) o;
if (endpoint.getFileName() == null) {
OMElement endpointElem = EndpointSerializer.getElementFromEndpoint(endpoint);
definitions.addChild(endpointElem);
}
} else if (o instanceof Entry) {
Entry entry = (Entry) o;
if (entry.getFileName() == null) {
if ((SynapseConstants.SERVER_HOST.equals(entry.getKey()) || SynapseConstants.SERVER_IP.equals(entry.getKey())) || entry.getType() == Entry.REMOTE_ENTRY) {
continue;
}
EntrySerializer.serializeEntry(entry, definitions);
}
}
}
for (PriorityExecutor executor : executors) {
PriorityExecutorSerializer.serialize(definitions, executor, SynapseConstants.SYNAPSE_NAMESPACE);
}
for (MessageStore messageStore : messageStores) {
if (messageStore.getFileName() == null) {
MessageStoreSerializer.serializeMessageStore(definitions, messageStore);
}
}
for (MessageProcessor messageProcessor : messageProcessors) {
if (messageProcessor.getFileName() == null) {
MessageProcessorSerializer.serializeMessageProcessor(definitions, messageProcessor);
}
}
for (API api : apiCollection) {
if (api.getFileName() == null) {
APISerializer.serializeAPI(definitions, api);
}
}
for (SynapseImport synapseImport : synapseImportsCollection) {
if (synapseImport.getFileName() == null) {
SynapseImportSerializer.serializeImport(definitions, synapseImport);
}
}
for (InboundEndpoint inboundEndpoint : inboundEndpoints) {
if (inboundEndpoint.getFileName() == null) {
InboundEndpointSerializer.serializeInboundEndpoint(definitions, inboundEndpoint);
}
}
serializeComments(comments, definitions);
serializeSynapseXML(definitions);
}
Aggregations