上传后从nexus插件访问Sonatype nexus工件

时间:2016-10-11 16:20:30

标签: java nexus

我想访问上传到sonaytype nexus 2.14.0-01的工件(包含交付的zip文件),将其解压缩到tmp目录中并检查其内容。

我能够挂钩创建操作的on handle请求,但是,当时工件尚未上传到存储库。

public void onHandle(Repository repository, ResourceStoreRequest resourceStoreRequest, Action action) throws ItemNotFoundException, IllegalOperationException
{
    log.info("got onHandle Request for " + repository.toString() + " " +   action.toString() + " " + resourceStoreRequest.toString());
    log.info("that is the file to process: " + resourceStoreRequest.getRequestPath());
}

日志条目:

2016-10-11 18:01:23,760+0200 INFO  [qtp1685232414-73] admin DeliveryRequestProcessor - got onHandle Request for M2Repository(id=deliveries) create ResourceStoreRequest{requestPath='/fakepath/configurationmanagement/0.1/configurationmanagement-0.1.zip', requestContext=RequestContext{this=org.sonatype.nexus.proxy.RequestContext@3476eab3, parent=null}, pathStack=[], processedRepositories=[], appliedMappings={}}(GAVCE=fakepath:configurationmanagement:0.1:c=null:e=zip, for "deliveries" [id=deliveries]) 

但要求

    repository.getLocalStorage().retrieveItem(repository,resourceStoreRequest)

失败(自然)。

对文件上传后可以处理的钩子有什么建议吗?

祝你好运, 爱德华

1 个答案:

答案 0 :(得分:0)

我使用了一个不那么好的解决方法来实现所需的功能。

在原始课程中,我向EventBus注册了一个监听器。

@Named(DeliveryRequestProcessor.ID)
public class DeliveryRequestProcessor extends ComponentSupport
    implements RequestStrategy {

    @Inject
    public DeliveryRequestProcessor(final EventBus eventBus)
    {
       this.eventBus = Preconditions.checkNotNull(eventBus);
       eventBus.register(new EventBusListener());
   }
}

我创建了另一个类,订阅了nexus正在发送的所有事件。

@Named
@EagerSingleton
public class EventBusListener 
{
    public void onEvent (RepositoryItemEventStoreCreate e)
    {
        ... the functionality to access the item
        e.getItem() // -> that is the Storage Item I was looking for
    }
}

该解决方案有一些缺点,例如事件会多次触发,您需要确保只执行一次处理,但对于第一种解决方案,它是可接受的(对我而言)。

祝你好运, 爱德华