2

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 ?

2 Answers2

2

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.

Rajeev Sampath
  • 2,739
  • 1
  • 16
  • 19
  • I have created a custom extension as 'public class RunningTime extends FunctionExecutor { ..... } ' as per the doc you have suggested. After building the jar i have placed it in 'dropin' folder. "sample.siddhiext" file entry is 'RunningTime=com.siddhi.sample.RunningTime' But while using the I am trying to use this in 'try it' tool I am getting RunningTime is neither a function nor an aggregated attribute. ? where i am doing wrong???? – Sidharth Dash Sep 01 '16 at 14:08
0

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.

HM.Rajjaz
  • 369
  • 1
  • 3
  • 17