简体   繁体   English

从wso2event解析WSO2 SP Siddhi xml

[英]WSO2 SP Siddhi xml parsing from wso2event

I have input stream as wso2event on wso2 SP, and it contain timestamp and payload. 我在wso2 SP上将输入流作为wso2event,并且包含时间戳和有效负载。 Payload is in xml format. 有效载荷为xml格式。 How can I parse this payload to variables? 如何将此有效载荷解析为变量? I see this doc https://wso2-extensions.github.io/siddhi-map-xml/api/4.0.11/ but i don't know, how get incoming wso2event to sourcemapper and then pars it to variables? 我看到了这个文档https://wso2-extensions.github.io/siddhi-map-xml/api/4.0.11/,但我不知道如何将传入的wso2event传递到sourcemapper,然后将其解析为变量?

siddhi-map-* extensions are used to map input/output event attributes at the source/sink level. siddhi-map- *扩展用于在源/接收器级别映射输入/输出事件属性。

Since this xml payload is an attribute of another stream, you can use siddhi-execution-map extension to create a map from that xml. 由于此xml有效负载是另一个流的属性,因此可以使用siddhi-execution-map扩展从该xml创建映射。

Then you can handle the xml payload as a hashmap within the siddhi app. 然后,您可以在siddhi应用程序中将XML有效内容作为哈希图处理。

Please refer to the documentation[1] for more details on this. 请参考文档[1]以获得更多详细信息。

[1] https://wso2-extensions.github.io/siddhi-execution-map/ [1] https://wso2-extensions.github.io/siddhi-execution-map/

Ok, I realized, that there is bug in https://wso2-extensions.github.io/siddhi-execution-map/api/latest/ createFromXML function. 好的,我意识到, https: //wso2-extensions.github.io/siddhi-execution-map/api/latest/ createFromXML函数中存在错误。 This function correctly parse xml file over each element, but there is badly defined HashMap, because function is called recursively and every cycle is created new map and override data in old map. 此函数可正确解析每个元素上的xml文件,但是定义不正确的HashMap,因为该函数是递归调用的,每个循环都将创建新的映射并覆盖旧映射中的数据。 So at the end, there is map with only one key. 因此,最后只有一键的地图。

private Object getMapFromXML(OMElement parentElement) throws XMLStreamException {
    Map<Object, Object> topLevelMap = new HashMap<Object, Object>();
    Iterator iterator = parentElement.getChildElements();
    while (iterator.hasNext()) {
        OMElement streamAttributeElement = (OMElement) iterator.next();
        String key = streamAttributeElement.getQName().toString();
        Object value;
        if (streamAttributeElement.getFirstElement() != null) {
            value = getMapFromXML(streamAttributeElement);
        } else {
            logger.info("getFirstElement is null now, iam in else - " + key);
            String elementText = streamAttributeElement.getText();
            if (elementText.equals("true") || elementText.equals("false")) {
                value = Boolean.parseBoolean(elementText);
            } else {
                if (NumberUtils.isNumber(elementText)) {
                    try {
                        value = numberFormat.parse(elementText);
                    } catch (ParseException e) {
                        value = elementText;
                    }
                } else {
                    value = elementText;
                }
            }
        }
        topLevelMap.put(key, value);
    }
    return topLevelMap;
}

topLevelMap should be declared as private global variable. 应该将topLevelMap声明为私有全局变量。 Could someone make ticket on wso2 github to resolve this bug please? 有人可以在wso2 github上做票以解决此错误吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM