Search in sources :

Example 1 with SynapseEventSource

use of org.apache.synapse.eventing.SynapseEventSource in project wso2-synapse by wso2.

the class EventSourceDeployer method deploySynapseArtifact.

@Override
public String deploySynapseArtifact(OMElement artifactConfig, String fileName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("EventSource Deployment from file : " + fileName + " : Started");
    }
    try {
        SynapseEventSource es = EventSourceFactory.createEventSource(artifactConfig, properties);
        if (es != null) {
            es.setFileName((new File(fileName)).getName());
            if (log.isDebugEnabled()) {
                log.debug("EventSource named '" + es.getName() + "' has been built from the file " + fileName);
            }
            es.buildService(getSynapseConfiguration().getAxisConfiguration());
            if (log.isDebugEnabled()) {
                log.debug("Initialized the EventSource : " + es.getName());
            }
            getSynapseConfiguration().addEventSource(es.getName(), es);
            if (log.isDebugEnabled()) {
                log.debug("EventSource Deployment from file : " + fileName + " : Completed");
            }
            log.info("EventSource named '" + es.getName() + "' has been deployed from file : " + fileName);
            return es.getName();
        } else {
            handleSynapseArtifactDeploymentError("EventSource Deployment Failed. The " + "artifact described in the file " + fileName + " is not an EventSource");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("EventSource Deployment from the file : " + fileName + " : Failed.", e);
    }
    return null;
}
Also used : SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) File(java.io.File) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 2 with SynapseEventSource

use of org.apache.synapse.eventing.SynapseEventSource in project wso2-synapse by wso2.

the class EventSourceFactoryTest method testCreateEventSource3.

/**
 * Test to CreateEventSource and asserting EventSource is created.
 *
 * @throws XMLStreamException - XMLStreamException
 */
@Test
public void testCreateEventSource3() throws XMLStreamException {
    String inputXML = "      <eventSource name=\"SampleEventSource\" xmlns=\"http://ws.apache.org/ns/synapse\">\n" + "            <subscriptionManager class=\"org.apache.synapse.eventing.managers." + "DefaultInMemorySubscriptionManager\">\n" + "                <property name=\"topicHeaderName\" value=\"Topic\"/>\n" + "                <property name=\"topicHeaderNS\" value=\"http://apache.org/aip\"/>\n" + "            </subscriptionManager>\n" + "            <subscription id=\"mySubscription\">\n" + "                 <filter source =\"synapse/event/test\" dialect=\"http://synapse.apache." + "org/eventing/dialect/topicFilter\"/>\n" + "                 <endpoint><address uri=\"http://localhost:9000/services/" + "SimpleStockQuoteService\"/></endpoint>\n" + "            </subscription>\n" + "            <subscription id=\"mySubscription2\">\n" + "                 <filter source =\"synapse/event/test\" dialect=\"http://synapse.apache.org/" + "eventing/dialect/topicFilter\"/>\n" + "                 <endpoint><address uri=\"http://localhost:9000/services/" + "SimpleStockQuoteService\"/></endpoint>\n" + "                 <expires>2020-06-27T21:07:00.000-08:00</expires>\n" + "            </subscription>\n" + "      </eventSource>\n";
    OMElement element = AXIOMUtil.stringToOM(inputXML);
    SynapseEventSource eventSource = EventSourceFactory.createEventSource(element, null);
    Assert.assertNotNull("SynapseEventSource is not created", eventSource);
}
Also used : SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) OMElement(org.apache.axiom.om.OMElement) Test(org.junit.Test)

Example 3 with SynapseEventSource

use of org.apache.synapse.eventing.SynapseEventSource 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);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) StartUpController(org.apache.synapse.startup.quartz.StartUpController) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) ProxyService(org.apache.synapse.core.axis2.ProxyService) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) Startup(org.apache.synapse.Startup)

Example 4 with SynapseEventSource

use of org.apache.synapse.eventing.SynapseEventSource in project wso2-synapse by wso2.

the class MultiXMLConfigurationBuilder method createEventSources.

private static void createEventSources(SynapseConfiguration synapseConfig, String rootDirPath, Properties properties) {
    File eventsDir = new File(rootDirPath, EVENTS_DIR);
    if (eventsDir.exists()) {
        if (log.isDebugEnabled()) {
            log.debug("Loading event sources from : " + eventsDir.getPath());
        }
        Iterator events = FileUtils.iterateFiles(eventsDir, extensions, false);
        while (events.hasNext()) {
            File file = (File) events.next();
            try {
                OMElement document = getOMElement(file);
                SynapseEventSource eventSource = SynapseXMLConfigurationFactory.defineEventSource(synapseConfig, document, properties);
                if (eventSource != null) {
                    eventSource.setFileName(file.getName());
                    synapseConfig.getArtifactDeploymentStore().addArtifact(file.getAbsolutePath(), eventSource.getName());
                }
            } catch (Exception e) {
                String msg = "Event source configuration cannot be built from : " + file.getName();
                handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_EVENT_SOURCE, msg, e);
            }
        }
    }
}
Also used : SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException)

Example 5 with SynapseEventSource

use of org.apache.synapse.eventing.SynapseEventSource 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);
}
Also used : MessageStore(org.apache.synapse.message.store.MessageStore) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) OMElement(org.apache.axiom.om.OMElement) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) Template(org.apache.synapse.endpoints.Template) SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) Entry(org.apache.synapse.config.Entry) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TemplateSerializer(org.apache.synapse.config.xml.endpoints.TemplateSerializer) AbstractStartup(org.apache.synapse.startup.AbstractStartup) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) OMFactory(org.apache.axiom.om.OMFactory) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) ProxyService(org.apache.synapse.core.axis2.ProxyService) Collection(java.util.Collection) API(org.apache.synapse.rest.API) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Startup(org.apache.synapse.Startup) AbstractStartup(org.apache.synapse.startup.AbstractStartup)

Aggregations

SynapseEventSource (org.apache.synapse.eventing.SynapseEventSource)15 OMElement (org.apache.axiom.om.OMElement)8 Test (org.junit.Test)5 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 ProxyService (org.apache.synapse.core.axis2.ProxyService)3 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)3 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)3 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)3 SubscriptionManager (org.wso2.eventing.SubscriptionManager)3 File (java.io.File)2 Iterator (java.util.Iterator)2 Startup (org.apache.synapse.Startup)2 PriorityExecutor (org.apache.synapse.commons.executors.PriorityExecutor)2 Entry (org.apache.synapse.config.Entry)2 Endpoint (org.apache.synapse.endpoints.Endpoint)2 Template (org.apache.synapse.endpoints.Template)2 DefaultInMemorySubscriptionManager (org.apache.synapse.eventing.managers.DefaultInMemorySubscriptionManager)2 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Date (java.util.Date)1