use of org.apache.synapse.message.store.MessageStore in project wso2-synapse by wso2.
the class MessageStoreSerializationTest method testMessageStoreSerialization.
public void testMessageStoreSerialization() throws Exception {
String messageStoreConfiguration = "<syn:messageStore xmlns:syn=\"" + "http://ws.apache.org/ns/synapse\"" + " name=\"foo\" >" + "</syn:messageStore>";
OMElement messageStoreElement = createOMElement(messageStoreConfiguration);
MessageStore messageStore = MessageStoreFactory.createMessageStore(messageStoreElement, new Properties());
OMElement serializedElement = MessageStoreSerializer.serializeMessageStore(null, messageStore);
try {
assertTrue(compare(messageStoreElement, serializedElement));
} catch (Exception e) {
fail("Exception in test.");
}
}
use of org.apache.synapse.message.store.MessageStore in project wso2-synapse by wso2.
the class MessageStoreFactory method createMessageStore.
@SuppressWarnings({ "UnusedDeclaration" })
public static MessageStore createMessageStore(OMElement elem, Properties properties) {
OMAttribute clss = elem.getAttribute(CLASS_Q);
MessageStore messageStore;
if (clss != null) {
String clssName = clss.getAttributeValue();
// Make synapse configuration backward compatible
if (Constants.DEPRECATED_INMEMORY_CLASS.equals(clssName)) {
clssName = InMemoryStore.class.getName();
} else if (Constants.DEPRECATED_JMS_CLASS.equals(clssName)) {
clssName = JmsStore.class.getName();
}
try {
Class cls = Class.forName(clssName);
messageStore = (MessageStore) cls.newInstance();
} catch (Exception e) {
handleException("Error while instantiating the message store", e);
return null;
}
} else {
messageStore = new InMemoryStore();
}
OMAttribute nameAtt = elem.getAttribute(NAME_Q);
if (nameAtt != null) {
messageStore.setName(nameAtt.getAttributeValue());
} else {
handleException("Message Store name not specified");
}
OMElement descriptionElem = elem.getFirstChildWithName(DESCRIPTION_Q);
if (descriptionElem != null) {
messageStore.setDescription(descriptionElem.getText());
}
messageStore.setParameters(getParameters(elem));
log.info("Successfully added Message Store configuration of : [" + nameAtt.getAttributeValue() + "].");
return messageStore;
}
use of org.apache.synapse.message.store.MessageStore 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);
}
use of org.apache.synapse.message.store.MessageStore in project wso2-synapse by wso2.
the class MultiXMLConfigurationBuilder method createMessageStores.
private static void createMessageStores(SynapseConfiguration synapseConfig, String rootDirPath, Properties properties) {
File messageStoresDir = new File(rootDirPath, MESSAGE_STORE_DIR);
if (messageStoresDir.exists()) {
if (log.isDebugEnabled()) {
log.debug("Loading Message Stores from :" + messageStoresDir.getPath());
}
Iterator messageStores = FileUtils.iterateFiles(messageStoresDir, extensions, false);
while (messageStores.hasNext()) {
File file = (File) messageStores.next();
try {
OMElement document = getOMElement(file);
MessageStore messageStore = SynapseXMLConfigurationFactory.defineMessageStore(synapseConfig, document, properties);
if (messageStore != null) {
messageStore.setFileName(file.getName());
synapseConfig.getArtifactDeploymentStore().addArtifact(file.getAbsolutePath(), messageStore.getName());
}
} catch (Exception e) {
String msg = "Message store configuration cannot be built from : " + file.getName();
handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_MESSAGE_STORES, msg, e);
}
}
}
}
use of org.apache.synapse.message.store.MessageStore in project wso2-synapse by wso2.
the class FailoverForwardingService method setMessageConsumerAndProducer.
private boolean setMessageConsumerAndProducer() throws StoreForwardException {
final String messageStoreName = messageProcessor.getMessageStoreName();
MessageStore messageStore = synapseEnvironment.getSynapseConfiguration().getMessageStore(messageStoreName);
messageConsumer = messageStore.getConsumer();
if (messageProcessor.getParameters().get(FailoverForwardingProcessorConstants.TARGET_MESSAGE_STORE) != null) {
targetMessageStoreName = (String) messageProcessor.getParameters().get(FailoverForwardingProcessorConstants.TARGET_MESSAGE_STORE);
}
/*
* Make sure to set the same message consumer in the message processor
* since it is used by life-cycle management methods. Specially by the
* deactivate method to cleanup the connection before the deactivation.
*/
return messageProcessor.setMessageConsumer(messageConsumer);
}
Aggregations