ROBY HERNAN RUBIANO
ROBY HERNAN RUBIANO

Reputation: 157

Writing a Custom Extension Siddhi

I have a java program for create a siddhi extension, my code is the next:

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;
    }
}

And My Custom.siddhiext:

url=co.com.easysol.phisingRestClient.App

In my ExecutionPlan I using the next code:

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

The custom.siddhiext file is in /repository/components/lib, but I have the next error:

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

Why ?

Upvotes: 2

Views: 694

Answers (2)

HM.Rajjaz
HM.Rajjaz

Reputation: 389

You can use archetype to generate the custom siddhi extensions and more over that in your resource name is Custom.siddhiext but when you use you typed as custom please check on that.

Upvotes: 0

Rajeev Sampath
Rajeev Sampath

Reputation: 2757

The problem here is that your class does not extend an extension class in Siddhi. Since your requirement is to write a custom function, modify it to extend FunctionExecutor and override the required methods as in this document.

More information on extensions can be found here.

Upvotes: 2

Related Questions