Search in sources :

Example 11 with SynapseEventSource

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

the class EventSourceDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("EventSource Update 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);
            }
            getSynapseConfiguration().removeEventSource(existingArtifactName);
            if (!existingArtifactName.equals(es.getName())) {
                log.info("EventSource named " + existingArtifactName + " has been Undeployed");
            }
            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 " + (existingArtifactName.equals(es.getName()) ? "update" : "deployment") + " from file : " + fileName + " : Completed");
            }
            log.info("EventSource named '" + es.getName() + "' has been " + (existingArtifactName.equals(es.getName()) ? "update" : "deployed") + " from file : " + fileName);
            return es.getName();
        } else {
            handleSynapseArtifactDeploymentError("EventSource Update Failed. The artifact " + "described in the file " + fileName + " is not a EventSource");
        }
    } catch (DeploymentException e) {
        handleSynapseArtifactDeploymentError("EventSource Update from the file : " + fileName + " : Failed.", e);
    } catch (AxisFault e) {
        handleSynapseArtifactDeploymentError("Error while initializing the event source", e);
    }
    return null;
}
Also used : AxisFault(org.apache.axis2.AxisFault) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 12 with SynapseEventSource

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

the class EventSourceSerializerTest method testSerializeEvent3.

/**
 * Test serializeEventSource with subscriptionManager and assert OMElement returned is not null.
 *
 * @throws XMLStreamException - XMLStreamException
 */
@Test
public void testSerializeEvent3() throws XMLStreamException {
    SynapseEventSource synapseEventSource = new SynapseEventSource("Test");
    SubscriptionManager subscriptionManager = new DefaultInMemorySubscriptionManager();
    synapseEventSource.setSubscriptionManager(subscriptionManager);
    OMElement omElement = EventSourceSerializer.serializeEventSource(null, synapseEventSource);
    Assert.assertNotNull("OMElement cannot be null.", omElement);
}
Also used : SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) OMElement(org.apache.axiom.om.OMElement) DefaultInMemorySubscriptionManager(org.apache.synapse.eventing.managers.DefaultInMemorySubscriptionManager) SubscriptionManager(org.wso2.eventing.SubscriptionManager) DefaultInMemorySubscriptionManager(org.apache.synapse.eventing.managers.DefaultInMemorySubscriptionManager) Test(org.junit.Test)

Example 13 with SynapseEventSource

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

the class EventSourceSerializerTest method testSerializeEvent4.

/**
 * Test SerialEvent and assert OMElement returned is not null.
 *
 * @throws XMLStreamException - XMLStreamException
 * @throws EventException     - EventException
 */
@Test
public void testSerializeEvent4() throws XMLStreamException, EventException {
    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 synapseEventSource = new SynapseEventSource("Test");
    SubscriptionManager subscriptionManager = new DefaultInMemorySubscriptionManager();
    subscriptionManager.addProperty("Name", "Test");
    SynapseSubscription synapseSubscription = new SynapseSubscription();
    synapseSubscription.setStaticEntry(true);
    Date date = new Date(System.currentTimeMillis() + 3600000);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    synapseSubscription.setExpires(cal);
    subscriptionManager.subscribe(synapseSubscription);
    synapseEventSource.setSubscriptionManager(subscriptionManager);
    OMElement omElement = EventSourceSerializer.serializeEventSource(element, synapseEventSource);
    Assert.assertNotNull("OMElement cannot be null.", omElement);
}
Also used : SynapseSubscription(org.apache.synapse.eventing.SynapseSubscription) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) Calendar(java.util.Calendar) OMElement(org.apache.axiom.om.OMElement) DefaultInMemorySubscriptionManager(org.apache.synapse.eventing.managers.DefaultInMemorySubscriptionManager) SubscriptionManager(org.wso2.eventing.SubscriptionManager) DefaultInMemorySubscriptionManager(org.apache.synapse.eventing.managers.DefaultInMemorySubscriptionManager) Date(java.util.Date) Test(org.junit.Test)

Example 14 with SynapseEventSource

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

the class EventSourceSerializerTest method testSerializeEvent2.

/**
 * Test serializeEventSource and assert OMElement returned is not null.
 *
 * @throws XMLStreamException - XMLStreamException
 */
@Test
public void testSerializeEvent2() throws XMLStreamException {
    SynapseEventSource synapseEventSource = new SynapseEventSource("Test");
    OMElement omElement = EventSourceSerializer.serializeEventSource(null, synapseEventSource);
    Assert.assertNotNull("OMElement cannot be null.", omElement);
}
Also used : SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) OMElement(org.apache.axiom.om.OMElement) Test(org.junit.Test)

Example 15 with SynapseEventSource

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

the class EventPublisherMediatorTest method testMediate.

/**
 * Testing eventPublisherMediator with mocked event source.
 */
@Test
public void testMediate() {
    final String EventSourceName = "testEventStore";
    SynapseEnvironment synapseEnvironment = Mockito.mock(SynapseEnvironment.class);
    MessageContext messageContext = new TestMessageContext();
    messageContext.setEnvironment(synapseEnvironment);
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    SynapseEventSource synapseEventSource = Mockito.mock(SynapseEventSource.class);
    Mockito.doNothing().when(synapseEventSource).dispatchEvents(Mockito.any(MessageContext.class));
    Map<String, SynapseEventSource> eventStoreMap = new HashMap<>();
    eventStoreMap.put(EventSourceName, synapseEventSource);
    synapseConfiguration.setEventSources(eventStoreMap);
    messageContext.setConfiguration(synapseConfiguration);
    eventPublisherMediator.setEventSourceName(EventSourceName);
    Assert.assertTrue("mediation successful", eventPublisherMediator.mediate(messageContext));
}
Also used : TestMessageContext(org.apache.synapse.TestMessageContext) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) HashMap(java.util.HashMap) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

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