Search in sources :

Example 96 with Attribute

use of org.wso2.siddhi.query.api.definition.Attribute in project wso2-synapse by wso2.

the class EventSourceFactory method createEventSource.

@SuppressWarnings({ "UnusedDeclaration" })
public static SynapseEventSource createEventSource(OMElement elem, Properties properties) {
    SynapseEventSource eventSource = null;
    OMAttribute name = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
    if (name == null) {
        handleException("The 'name' attribute is required for a event source de");
    } else {
        eventSource = new SynapseEventSource(name.getAttributeValue());
    }
    OMElement subscriptionManagerElem = elem.getFirstChildWithName(SUBSCRIPTION_MANAGER_QNAME);
    if (eventSource != null && subscriptionManagerElem != null) {
        OMAttribute clazz = subscriptionManagerElem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "class"));
        if (clazz != null) {
            String className = clazz.getAttributeValue();
            try {
                Class subscriptionManagerClass = Class.forName(className);
                SubscriptionManager manager = (SubscriptionManager) subscriptionManagerClass.newInstance();
                Iterator itr = subscriptionManagerElem.getChildrenWithName(PROPERTIES_QNAME);
                while (itr.hasNext()) {
                    OMElement propElem = (OMElement) itr.next();
                    String propName = propElem.getAttribute(new QName("name")).getAttributeValue();
                    String propValue = propElem.getAttribute(new QName("value")).getAttributeValue();
                    if (propName != null && !"".equals(propName.trim()) && propValue != null && !"".equals(propValue.trim())) {
                        propName = propName.trim();
                        propValue = propValue.trim();
                        PasswordManager passwordManager = PasswordManager.getInstance();
                        String key = eventSource.getName() + "." + propName;
                        if (passwordManager.isInitialized() && passwordManager.isTokenProtected(key)) {
                            eventSource.putConfigurationProperty(propName, propValue);
                            propValue = passwordManager.resolve(propValue);
                        }
                        manager.addProperty(propName, propValue);
                    }
                }
                eventSource.setSubscriptionManager(manager);
                eventSource.getSubscriptionManager().init();
            } catch (ClassNotFoundException e) {
                handleException("SubscriptionManager class not found", e);
            } catch (IllegalAccessException e) {
                handleException("Unable to access the SubscriptionManager object", e);
            } catch (InstantiationException e) {
                handleException("Unable to instantiate the SubscriptionManager object", e);
            }
        } else {
            handleException("SynapseSubscription manager class is a required attribute");
        }
    } else {
        handleException("SynapseSubscription Manager has not been specified for the event source");
    }
    try {
        createStaticSubscriptions(elem, eventSource);
    } catch (EventException e) {
        handleException("Static subscription creation failure", e);
    }
    return eventSource;
}
Also used : SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) EventException(org.wso2.eventing.exceptions.EventException) QName(javax.xml.namespace.QName) PasswordManager(org.wso2.securevault.PasswordManager) OMElement(org.apache.axiom.om.OMElement) SubscriptionManager(org.wso2.eventing.SubscriptionManager) Iterator(java.util.Iterator) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 97 with Attribute

use of org.wso2.siddhi.query.api.definition.Attribute in project ballerina by ballerina-lang.

the class Generator method annotFieldAnnotation.

/**
 * Get description annotation of the annotation attribute.
 * @param annotationNode parent node.
 * @param annotAttribute annotation attribute.
 * @return description of the annotation attribute.
 */
private static String annotFieldAnnotation(BLangAnnotation annotationNode, BLangAnnotAttribute annotAttribute) {
    List<? extends AnnotationAttachmentNode> annotationAttachments = getAnnotationAttachments(annotationNode);
    for (AnnotationAttachmentNode annotation : annotationAttachments) {
        if ("Field".equals(annotation.getAnnotationName().getValue())) {
            BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
            BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
            String value = bLangLiteral.toString();
            if (value.startsWith(annotAttribute.getName().getValue())) {
                String[] valueParts = value.split(":");
                return valueParts.length == 2 ? valueParts[1] : valueParts[0];
            }
        }
    }
    return "";
}
Also used : BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 98 with Attribute

use of org.wso2.siddhi.query.api.definition.Attribute in project ballerina by ballerina-lang.

the class HTTPSessionEssentialMethodsTest method testGetAttributeFunction.

@Test(description = "Test for Get Attribute Function")
public void testGetAttributeFunction() {
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample/test4", "GET");
    HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
    Assert.assertNotNull(response);
    String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
    ;
    Assert.assertNotNull(responseMsgPayload);
    Assert.assertEquals(responseMsgPayload, "attribute not available");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 99 with Attribute

use of org.wso2.siddhi.query.api.definition.Attribute in project ballerina by ballerina-lang.

the class HTTPSessionEssentialMethodsTest method testSessionForStructAttribute.

@Test(description = "Test for struct attribute")
public void testSessionForStructAttribute() {
    List<Header> headers = new ArrayList<Header>();
    headers.add(new Header(HttpHeaderNames.CONTENT_TYPE.toString(), TEXT_PLAIN));
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample2/myStruct", "POST", headers, "wso2");
    HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
    Assert.assertNotNull(response);
    String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertNotNull(responseMsgPayload);
    Assert.assertEquals(responseMsgPayload, "wso2");
    String cookie = response.getHeader(RESPONSE_COOKIE_HEADER);
    String sessionId = CookieUtils.getCookie(cookie).value;
    cMsg = MessageUtils.generateHTTPMessage("/sample2/myStruct", "POST", headers, "chamil");
    cMsg.setHeader(COOKIE_HEADER, SESSION_ID + sessionId);
    response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
    Assert.assertNotNull(response);
    responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertNotNull(responseMsgPayload);
    Assert.assertEquals(responseMsgPayload, "wso2");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) Header(org.wso2.carbon.messaging.Header) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) ArrayList(java.util.ArrayList) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 100 with Attribute

use of org.wso2.siddhi.query.api.definition.Attribute in project ballerina by ballerina-lang.

the class ServiceTest method testConstantValueAsAnnAttributeVal.

@Test(description = "Test using constant as annotation attribute value")
public void testConstantValueAsAnnAttributeVal() {
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/constantPath", "GET");
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, requestMsg);
    Assert.assertNotNull(responseMsg);
    String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(responseMsg).getInputStream());
    StringDataSource stringDataSource = new StringDataSource(responseMsgPayload);
    Assert.assertNotNull(stringDataSource);
    Assert.assertEquals(stringDataSource.getValue(), "constant path test");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) StringDataSource(org.ballerinalang.runtime.message.StringDataSource) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)126 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)103 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)89 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)89 Event (org.wso2.siddhi.core.event.Event)85 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)83 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)83 Query (org.wso2.siddhi.query.api.execution.query.Query)83 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)73 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)44 Attribute (org.wso2.siddhi.query.api.definition.Attribute)40 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)38 ArrayList (java.util.ArrayList)37 Attribute (org.wso2.charon3.core.attributes.Attribute)36 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)36 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)34 HashMap (java.util.HashMap)32 CharonException (org.wso2.charon3.core.exceptions.CharonException)29 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)22 Map (java.util.Map)21