首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >上传后从nexus访问Sonatype nexus工件

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

Stack Overflow用户
提问于 2016-10-12 00:20:30
回答 1查看 93关注 0票数 1

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

我能够挂接到创建操作的句柄请求中,但是,此时工件还没有上载到存储库。

代码语言:javascript
复制
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());
}

日志条目:

代码语言:javascript
复制
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]) 

而是一个呼唤

代码语言:javascript
复制
    repository.getLocalStorage().retrieveItem(repository,resourceStoreRequest)

(自然地)失败了。

在上传文件并可以处理之后,有没有关于使用什么钩子的建议?

致以最好的问候,爱德华

EN

回答 1

Stack Overflow用户

发布于 2016-10-13 00:28:46

我使用了一个不太好的变通方法来实现所需的功能。

在原始类中,我向EventBus注册了一个侦听器。

代码语言:javascript
复制
@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发送的所有事件。

代码语言:javascript
复制
@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
    }
}

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

致以最好的问候,爱德华

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39982014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档