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

}

シディエクスト:

#
# 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

このエラーは、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;
4

2 に答える 2

0

I copy the external jar to:

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

I created my jar including external jar too. I'm using the option "Runnable JAR File".

My problem persists.

I could not really make an extension to Siddhi with external libraries and do not understand why.

My MANIFEST.MF is the next:

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
于 2016-06-07T19:21:28.780 に答える
0

すべての依存関係 JAR を <DAS_HOME>\repository\components\libディレクトリに追加する必要があります。JAX-RS ライブラリを使用しているのを見ました。その JAR も追加する必要があります。

于 2016-06-06T08:54:46.703 に答える