use of org.wso2.siddhi.core.stream.input.source.Source in project siddhi by wso2.
the class SiddhiCompiler method parseStreamDefinition.
public static StreamDefinition parseStreamDefinition(String source) {
ANTLRInputStream input = new ANTLRInputStream(source);
SiddhiQLLexer lexer = new SiddhiQLLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SiddhiQLParser parser = new SiddhiQLParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(SiddhiErrorListener.INSTANCE);
ParseTree tree = parser.definition_stream_final();
SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
return (StreamDefinition) eval.visit(tree);
}
use of org.wso2.siddhi.core.stream.input.source.Source in project wso2-synapse by wso2.
the class EventSourceFactory method createStaticSubscriptions.
/**
* Generate the static subscriptions
*
* @param elem containing the static subscription configurations
* @param synapseEventSource event source to which the static subscriptions belong to
* @throws EventException in-case of a failure in creating static subscriptions
*/
private static void createStaticSubscriptions(OMElement elem, SynapseEventSource synapseEventSource) throws EventException {
for (Iterator iterator = elem.getChildrenWithName(SUBSCRIPTION_QNAME); iterator.hasNext(); ) {
SynapseSubscription synapseSubscription = new SynapseSubscription();
OMElement elmSubscription = (OMElement) iterator.next();
synapseSubscription.setId(elmSubscription.getAttribute(ID_QNAME).getAttributeValue());
// process the filter
OMElement elmFilter = elmSubscription.getFirstChildWithName(FILTER_QNAME);
OMAttribute dialectAttr = elmFilter.getAttribute(FILTER_DIALECT_QNAME);
if (dialectAttr != null && dialectAttr.getAttributeValue() != null) {
OMAttribute sourceAttr = elmFilter.getAttribute(FILTER_SOURCE_QNAME);
if (sourceAttr != null) {
synapseSubscription.setFilterDialect(dialectAttr.getAttributeValue());
synapseSubscription.setFilterValue(sourceAttr.getAttributeValue());
} else {
handleException("Error in creating static subscription. Filter source not defined");
}
} else {
handleException("Error in creating static subscription. Filter dialect not defined");
}
OMElement elmEndpoint = elmSubscription.getFirstChildWithName(ENDPOINT_QNAME);
if (elmEndpoint != null) {
OMElement elmAddress = elmEndpoint.getFirstChildWithName(ADDRESS_QNAME);
if (elmAddress != null) {
OMAttribute uriAttr = elmAddress.getAttribute(EP_URI_QNAME);
if (uriAttr != null) {
synapseSubscription.setEndpointUrl(uriAttr.getAttributeValue());
synapseSubscription.setAddressUrl(uriAttr.getAttributeValue());
} else {
handleException("Error in creating static subscription. URI not defined");
}
} else {
handleException("Error in creating static subscription. Address not defined");
}
} else {
handleException("Error in creating static subscription. Endpoint not defined");
}
OMElement elmExpires = elmSubscription.getFirstChildWithName(EXPIRES_QNAME);
if (elmExpires != null) {
try {
if (elmExpires.getText().startsWith("P")) {
synapseSubscription.setExpires(ConverterUtil.convertToDuration(elmExpires.getText()).getAsCalendar());
} else {
synapseSubscription.setExpires(ConverterUtil.convertToDateTime(elmExpires.getText()));
}
} catch (Exception e) {
handleException("Error in creating static subscription. invalid date format", e);
}
} else {
synapseSubscription.setExpires(null);
}
synapseSubscription.setStaticEntry(true);
synapseEventSource.getSubscriptionManager().subscribe(synapseSubscription);
}
}
use of org.wso2.siddhi.core.stream.input.source.Source in project wso2-synapse by wso2.
the class EventSourceSerializer method serializeEventSource.
public static OMElement serializeEventSource(OMElement elem, SynapseEventSource eventSource) {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace nullNS = fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");
OMElement evenSourceElem = fac.createOMElement("eventSource", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
if (eventSource.getName() != null) {
evenSourceElem.addAttribute(fac.createOMAttribute("name", nullNS, eventSource.getName()));
}
if (eventSource.getSubscriptionManager() != null) {
OMElement subManagerElem = fac.createOMElement("subscriptionManager", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
subManagerElem.addAttribute(fac.createOMAttribute("class", nullNS, eventSource.getSubscriptionManager().getClass().getName()));
Collection<String> names = (Collection<String>) eventSource.getSubscriptionManager().getPropertyNames();
for (String name : names) {
String value;
if (eventSource.isContainsConfigurationProperty(name)) {
value = eventSource.getConfigurationProperty(name);
} else {
value = eventSource.getSubscriptionManager().getPropertyValue(name);
}
OMElement propElem = fac.createOMElement("property", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
propElem.addAttribute(fac.createOMAttribute("name", nullNS, name));
propElem.addAttribute(fac.createOMAttribute("value", nullNS, value));
subManagerElem.addChild(propElem);
}
evenSourceElem.addChild(subManagerElem);
// Adding static subscriptions
List<Subscription> staticSubscriptionList = eventSource.getSubscriptionManager().getStaticSubscriptions();
for (Iterator<Subscription> iterator = staticSubscriptionList.iterator(); iterator.hasNext(); ) {
Subscription staticSubscription = iterator.next();
OMElement staticSubElem = fac.createOMElement("subscription", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
staticSubElem.addAttribute(fac.createOMAttribute("id", nullNS, staticSubscription.getId()));
OMElement filterElem = fac.createOMElement("filter", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
filterElem.addAttribute(fac.createOMAttribute("source", nullNS, (String) staticSubscription.getFilterValue()));
filterElem.addAttribute(fac.createOMAttribute("dialect", nullNS, (String) staticSubscription.getFilterDialect()));
staticSubElem.addChild(filterElem);
OMElement endpointElem = fac.createOMElement("endpoint", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
OMElement addressElem = fac.createOMElement("address", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
addressElem.addAttribute(fac.createOMAttribute("uri", nullNS, staticSubscription.getEndpointUrl()));
endpointElem.addChild(addressElem);
staticSubElem.addChild(endpointElem);
if (staticSubscription.getExpires() != null) {
OMElement expiresElem = fac.createOMElement("expires", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
fac.createOMText(expiresElem, ConverterUtil.convertToString(staticSubscription.getExpires()));
staticSubElem.addChild(expiresElem);
}
evenSourceElem.addChild(staticSubElem);
}
}
if (elem != null) {
elem.addChild(evenSourceElem);
}
return evenSourceElem;
}
use of org.wso2.siddhi.core.stream.input.source.Source 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);
}
use of org.wso2.siddhi.core.stream.input.source.Source in project wso2-dss-connectors by wso2-attic.
the class MongoDBDataSource method init.
@Override
public void init(Map<String, String> params) throws DataServiceFault {
String serversParam = params.get(MongoDBDSConstants.SERVERS);
if (DBUtils.isEmptyString(serversParam)) {
throw new DataServiceFault("The data source param '" + MongoDBDSConstants.SERVERS + "' is required");
}
String[] servers = serversParam.split(",");
String database = params.get(MongoDBDSConstants.DATABASE);
if (DBUtils.isEmptyString(database)) {
throw new DataServiceFault("The data source param '" + MongoDBDSConstants.DATABASE + "' is required");
}
try {
this.mongo = new Mongo(this.createServerAddresses(servers), this.extractMongoOptions(params));
String writeConcern = params.get(MongoDBDSConstants.WRITE_CONCERN);
if (!DBUtils.isEmptyString(writeConcern)) {
this.getMongo().setWriteConcern(WriteConcern.valueOf(writeConcern));
}
String readPref = params.get(MongoDBDSConstants.READ_PREFERENCE);
if (!DBUtils.isEmptyString(readPref)) {
this.getMongo().setReadPreference(ReadPreference.valueOf(readPref));
}
this.jongo = new Jongo(this.getMongo().getDB(database));
} catch (Exception e) {
throw new DataServiceFault(e);
}
}
Aggregations