Package org.sonatype.nexus.proxy

Examples of org.sonatype.nexus.proxy.ResourceStoreRequest


  private AbstractStorageItem getStorageItem(final String path, final boolean localOnly)
      throws IOException
  {
    try {
      return repository.getLocalStorage().retrieveItem(repository, new ResourceStoreRequest(path, localOnly));
    }
    catch (ItemNotFoundException e) {
      final FileNotFoundException exception = new FileNotFoundException("Item not found!");
      exception.initCause(e);
      throw exception;
View Full Code Here


  private void putStorageItem(final String path, final ContentLocator contentLocator)
      throws IOException
  {
    try {
      ResourceStoreRequest req = new ResourceStoreRequest(path);

      DefaultStorageFileItem mdFile = new DefaultStorageFileItem(repository, req, true, true, contentLocator);

      repository.storeItem(false, mdFile);
View Full Code Here

  private void deleteStorageItem(final String path)
      throws IOException
  {
    try {
      ResourceStoreRequest request = new ResourceStoreRequest(path, true);
      request.getRequestContext().put(DeleteOperation.DELETE_OPERATION_CTX_KEY, operation);
      repository.deleteItem(false, request);
    }
    catch (Exception e) {
      throw new IOException(e);
    }
View Full Code Here

  public void onCollectionExit(WalkerContext context, StorageCollectionItem coll) {
    try {
      mdHelper.onDirExit(coll.getPath());

      if (coll.list().size() == 0) {
        ResourceStoreRequest request = new ResourceStoreRequest(coll);
        if (deleteOperation != null) {
          request.getRequestContext().put(DeleteOperation.DELETE_OPERATION_CTX_KEY, this.deleteOperation);
        }

        repository.deleteItem(false, request);
      }
    }
View Full Code Here

      for (File file : files) {
        String newPath = PathUtils.concatPaths(request.getRequestPath(), file.getName());

        request.pushRequestPath(newPath);
        try {
          ResourceStoreRequest collMemberReq = new ResourceStoreRequest(request);
          try {
            result.add(retrieveItemFromFile(repository, collMemberReq, file));
          }
          catch (ItemNotFoundException e) {
            log.debug("ItemNotFoundException while listing directory, for request: {}",
                collMemberReq.getRequestPath(), e);
          }
        }
        finally {
          request.popRequestPath();
        }
View Full Code Here

  {
    final DiscoveryResult<MavenRepository> discoveryResult =
        new DiscoveryResult<MavenRepository>(mavenRepository);
    // NEXUS-6485: Since this fix, prefixes will do include empty directories due to "depth" optimization
    final WalkerContext context =
        new DefaultWalkerContext(mavenRepository, new ResourceStoreRequest("/"),
            new DepthLimitedStoreWalkerFilter(config.getLocalScrapeDepth()),
            true);
    final PrefixCollectorProcessor prefixCollectorProcessor = new PrefixCollectorProcessor();
    context.getProcessors().add(prefixCollectorProcessor);
View Full Code Here

    String mdString = outputStream.toString("UTF-8");

    outputStream.close();

    DefaultStorageFileItem file =
        new DefaultStorageFileItem(uid.getRepository(), new ResourceStoreRequest(uid.getPath()), true, true,
            new StringContentLocator(mdString));

    ((MavenRepository) uid.getRepository()).storeItemWithChecksums(false, file);
  }
View Full Code Here

  {
    if (!contentValid && remoteHash != null && remoteHash.getHashItem() != null) {
      // TODO should we remove bad checksum if policy==WARN?
      try {
        String path = remoteHash.getHashItem().getRepositoryItemUid().getPath();
        proxy.getLocalStorage().deleteItem(proxy, new ResourceStoreRequest(path, true));
      }
      catch (ItemNotFoundException e) {
        // ignore
      }
      catch (UnsupportedStorageOperationException e) {
View Full Code Here

  protected RemoteHashResponse retrieveRemoteHash(AbstractStorageItem item, ProxyRepository proxy, String baseUrl)
      throws LocalStorageException
  {
    RepositoryItemUid uid = item.getRepositoryItemUid();

    ResourceStoreRequest request = new ResourceStoreRequest(item);

    RemoteHashResponse response = null;
    try {
      // we prefer SHA1 ...
      request.pushRequestPath(uid.getPath() + SUFFIX_SHA1);
      try {
        response = doRetrieveSHA1(proxy, request, item);
      }
      finally {
        request.popRequestPath();
      }
    }
    catch (ItemNotFoundException e) {
      // ... but MD5 will do too
      request.pushRequestPath(uid.getPath() + SUFFIX_MD5);
      try {
        response = doRetrieveMD5(proxy, request, item);
      }
      catch (ItemNotFoundException e1) {
        log.debug("Item checksums (SHA1, MD5) remotely unavailable " + uid.toString());
      }
      finally {
        request.popRequestPath();
      }
    }

    return response;
  }
View Full Code Here

    if (!(item instanceof StorageFileItem)) {
      throw new UnsupportedStorageOperationException("Storing of non-files remotely is not supported!");
    }
    final StorageFileItem fileItem = (StorageFileItem) item;

    final ResourceStoreRequest request = new ResourceStoreRequest(item);

    try {
      validatePath(repository, request);
    }
    catch (ItemNotFoundException e) {
      throw new RemoteStorageException("Invalid path to store", e);
    }

    final URL remoteUrl = appendQueryString(repository, request, getAbsoluteUrlFromBase(repository, request));

    final HttpPut method = new HttpPut(remoteUrl.toExternalForm());

    final InputStreamEntity entity;
    try {
      entity =
          new InputStreamEntity(new InterruptableInputStream(fileItem.getInputStream()), fileItem.getLength());
    }
    catch (IOException e) {
      throw new RemoteStorageException(e.getMessage() + " [repositoryId=\"" + repository.getId()
          + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteUrl.toString() + "\"]",
          e);
    }

    entity.setContentType(fileItem.getMimeType());
    method.setEntity(entity);

    final HttpResponse httpResponse = executeRequestAndRelease(repository, request, method, repository.getRemoteUrl());
    final int statusCode = httpResponse.getStatusLine().getStatusCode();

    if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED
        && statusCode != HttpStatus.SC_NO_CONTENT && statusCode != HttpStatus.SC_ACCEPTED) {
      throw new RemoteStorageException("Unexpected response code while executing " + method.getMethod()
          + " method [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath()
          + "\", remoteUrl=\"" + remoteUrl.toString() + "\"]. Expected: \"any success (2xx)\". Received: "
          + statusCode + " : " + httpResponse.getStatusLine().getReasonPhrase());
    }
  }
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.ResourceStoreRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.