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;
}
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 "";
}
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");
}
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");
}
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");
}
Aggregations