1

I want to access an artifact (zip File containing a delivery) uploaded to a sonaytype nexus 2.14.0-01 to unzip it in a tmp directory and examine its content.

I am able to hook into the on handle request for the create action, however, at that time the artifact is not yet uploaded to the repository.

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

Log entries:

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]) 

but a call for

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

is failing (naturally).

Is there any advice on what hook to use after a file is uploaded and can be processed?

Best regards, Eduard

user2402987
  • 43
  • 1
  • 3

1 Answers1

0

I used a not-so-nice workaround to implement the needed functionality.

In the original class, I register a Listener to the 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());
   }
}

I have created another class, subscribing to all events nexus is sending.

@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
    }
}

The solution has some drawbacks, e.g. the event fires multiple times and you need to ensure that the processing only is performed one, but for a first solution its acceptable (for me).

Best regards, Eduard

user2402987
  • 43
  • 1
  • 3