Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Nexus2-插件开发-事件_Java_Nexus - Fatal编程技术网

Java Nexus2-插件开发-事件

Java Nexus2-插件开发-事件,java,nexus,Java,Nexus,编辑:我想我知道我必须使用EventBus。因此,我必须将我的侦听器类(使用@subscribe方法的侦听器类)注册到EventBus。如何让Nexus的EventBus实例注册我的“侦听器” 我目前正在为Nexus2开发一个webhook插件,特别是OSS 2.13.0-01。类似于(对于Nexus1.x)。不过,eventinspector在Nexus2.x中的工作方式不同。我浏览了Nexus2.x的源代码,但还没有找到线索。我最初的想法是,我只需要实现一个侦听器,仅此而已,但我无法获得任何

编辑:我想我知道我必须使用EventBus。因此,我必须将我的侦听器类(使用@subscribe方法的侦听器类)注册到EventBus。如何让Nexus的EventBus实例注册我的“侦听器”

我目前正在为Nexus2开发一个webhook插件,特别是OSS 2.13.0-01。类似于(对于Nexus1.x)。不过,eventinspector在Nexus2.x中的工作方式不同。我浏览了Nexus2.x的源代码,但还没有找到线索。我最初的想法是,我只需要实现一个侦听器,仅此而已,但我无法获得任何事件,也看不到任何好的调试机会来了解如何进行。那个么:在Nexus2.x中发生事件时,我如何侦听事件来调用我的方法呢?这辆公共汽车是去的路吗

谢谢! bigcrash

我不确定您对哪些事件感兴趣,但我构建了一个插件,用于检测是否向Nexus添加了新的工件。我实现了一个类

@Named
@Singleton
public class ArtifactFinder extends ComponentSupport implements EventSubscriber
并实现了一种方法

@Subscribe
public void onDeployEvent(RepositoryItemEventStoreCreate event)
{
  StorageItem item = event.getItem();
  writeOut(item, "+ "); 
}

根据JF Meiers的回答,以下是Nexus Repository Manager OSS 2.13.0-01的工作版本,我们希望在其中获得所有ItemEventStoreCreate事件,以便在存储项目时发送webhook:

@Named
@Singleton
public class testEventPlugin extends ComponentSupport implements EventSubscriber {

    @Subscribe
    public void onDeployEvent(RepositoryItemEventStoreCreate event) {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod("http://api.webhookinbox.com/i/EfwQnwLM/in/");
        try {
            int statusCode = client.executeMethod(method);
            byte[] responseBody = method.getResponseBody();
            System.out.println(new String(responseBody));
        } catch (Exception e) {
            System.err.println("Fatal error: " + e.getMessage());
            e.printStackTrace();
        } finally {
            method.releaseConnection();
        }
    }
}
谢谢!
bigcrash

您需要使用Nexus存储库2吗?如果对你有用的话,Webhook是内置在Nexus Repository 3上的。嗯,是的,我必须使用Nexus Repository 2…但是谢谢,这增加了pro Nexus 3的参数数量,我真的很感激!我将尝试并报告:)这不起作用,我更新了我的答案,也许我做错了什么。我唯一能说的是,插件出现在插件列表中,并被标记为活动:)正如您所看到的,我用一个最终工作类100%您的解决方案更新了答案。此解决方案最初不起作用,因为我最初使用requestbin进行测试,requestbin的cloudflare保护阻止了我的java apache http“浏览器”签名。请还原您的问题并将答案作为答案发布。