首页 文章

编写自定义扩展Siddhi

提问于
浏览
1

我有一个用于创建siddhi扩展的java程序,我的代码是下一个:

package co.com.easysol.phisingRestClient;

import java.io.StringReader;

import javax.json.Json;
import javax.json.JsonReader;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;

public class App {
    public static void main(String[] args) {
        float res = new App().phisingProbability("http://dinas.tomsk.ru/js/index.html?paypal.com/uk/cgi-bin/");
        System.out.println("res: " + res);
    }

    public float phisingProbability(String url) {
        float res = 0;
        String e = null;
        try {
            Client client = ClientBuilder.newClient();
            e = client.target("http://52.37.125.225:3000/phishing").queryParam("url", url).request(MediaType.TEXT_HTML)
                    .get(String.class);

            try (JsonReader jr = Json.createReader(new StringReader(e))) {
                String valor = jr.readObject().getString("result");
                try {
                    res = Float.parseFloat(valor);
                } catch (Exception ex1) {
                    res = 0;
                }
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return res;
    }
}

和我的Custom.siddhiext:

url=co.com.easysol.phisingRestClient.App

在我的ExecutionPlan中,我使用下一个代码:

from DSBStream
select custom:url(meta_phr_id_pharming_resume) as porc
insert into conteo;

custom.siddhiext文件位于/ repository / components / lib中,但我有下一个错误:

'url' is neither a function extension nor an aggregated attribute extension in execution plan "ExecutionPlan"

为什么?

2 回答

  • 0

    这里的问题是你的类没有扩展Siddhi中的扩展类 . 由于您的要求是编写自定义函数,因此修改它以扩展FunctionExecutor并覆盖所需的方法as in this document .

    有关扩展的更多信息可以是found here .

  • 2

    您可以使用原型生成custom siddhi extensions以及您的资源名称中的更多内容是Custom.siddhiext,但是当您使用键入自定义时,请检查它 .

相关问题