首页 文章

JAR扩展了SIDDHI

提问于
浏览
0

我想扩展siddhi,mi java代码是:

package org.wso2.siddhi.extension.fraude;

import org.wso2.siddhi.core.config.ExecutionPlanContext;
import org.wso2.siddhi.core.executor.ExpressionExecutor;
import org.wso2.siddhi.core.executor.function.FunctionExecutor;
import org.wso2.siddhi.query.api.definition.Attribute;
import org.wso2.siddhi.query.api.definition.Attribute.Type;


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;
import java.io.StringReader;

public class Swordphish extends FunctionExecutor {
    ExpressionExecutor[] url;

    public static void main (String[] arg1){
        System.out.println("Programa test phishing");
    }

    @Override
    protected void init(ExpressionExecutor[] url, ExecutionPlanContext arg1) {
        // TODO Auto-generated method stub
        this.url    =   url;
    }

    @Override
    public Type getReturnType() {
        // TODO Auto-generated method stub
        return Attribute.Type.FLOAT;
    }

    @Override
    public void start() {
        // TODO Auto-generated method stub

    }

    @Override
    public void stop() {
        // TODO Auto-generated method stub

    }

    @Override
    public Object[] currentState() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void restoreState(Object[] arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    protected Object execute(Object[] arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected Object execute(Object arg0) {
        // TODO Auto-generated method stub
        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 new Float(res);
    }

}

siddhiext:

#
# Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
#
# WSO2 Inc. licenses this file to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

swordurl=org.wso2.siddhi.extension.fraude.Swordphish

我生成了我的JAR,你的位置是C:\ wso2 \ wso2das-3.0.1 \ repository \ components \ lib

我可以使用siddhi的“swordurl”:

from DSBStream
select fraude:swordurl('www.babas.com') as porcsword
insert into testswordphish;

但我运行我的执行计划,我得到了下一个错误:

java.lang.NoClassDefFoundError: javax/ws/rs/client/ClientBuilder

this error always happens when I use external dependencies to Siddhi. 为什么?

在这种情况下,我使用下一个外部依赖项:

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;
import java.io.StringReader;

2 回答

  • 0

    您必须将所有依赖项JAR添加到 <DAS_HOME>\repository\components\lib 目录 . 我看到你正在使用JAX-RS库,你也必须添加JAR .

  • 0

    我将外部jar复制到:

    <DAS_HOME>\repository\components\lib
    <DAS_HOME>\repository\components\plugins
    

    我也创造了我的 jar ,包括外部 jar . 我正在使用选项“Runnable JAR File” .

    我的问题仍然存在 .

    我无法用外部库扩展Siddhi并且不明白为什么 .

    我的MANIFEST.MF是下一个:

    Manifest-Version: 1.0
    Rsrc-Class-Path: ./ siddhi-query-api_3.0.4.jar javax.json-1.0.4.jar ja
     vax.json-api-1.0.jar jaxrs-api-3.0.2.Final.jar resteasy-client-3.0.2.
     Final.jar resteasy-jaxrs-3.0.2.Final.jar siddhi-core_3.0.4.jar
    Class-Path: .
    Rsrc-Main-Class: org.wso2.siddhi.extension.fraude.Swordphish
    Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
    

相关问题