Package org.sonatype.nexus.proxy

Examples of org.sonatype.nexus.proxy.ItemNotFoundException$ItemNotFoundInRepositoryReason


    }
    else if (target.isFile()) {
      return null;
    }
    else {
      throw new ItemNotFoundException(reasonFor(request, repository,
          "Path %s not found in local storage of repository %s", request.getRequestPath(),
          RepositoryStringUtils.getHumanizedNameString(repository)));
    }
  }
View Full Code Here


      if (attributes == null) {
        throw new LocalStorageException("Null item repository attributes");
      }

      if (Boolean.parseBoolean(attributes.get(noattrname)) && !request.isRequestAsExpired()) {
        throw new ItemNotFoundException(request);
      }

      String hash = attributes.get(attrname);
      if (hash == null || request.isRequestAsExpired()) {
        try {
          final StorageFileItem remoteItem =
              (StorageFileItem) proxy.getRemoteStorage().retrieveItem(proxy, request, proxy.getRemoteUrl());
          hash = MUtils.readDigestFromFileItem(remoteItem); // closes http input stream
        }
        catch (ItemNotFoundException e) {
          // fall through
        }
        catch (RemoteAccessException e) {
          // fall through
        }
        catch (RemoteStorageException e) {
          // this is (potentially) transient network or remote server problem will be cached
          // there is no automatic retry for this hash time
          // either expire the artifact or request the hash asExpired to retry
        }

        doStoreChechsumItem(proxy, artifact, attrname, noattrname, hash);
      }

      if (hash != null) {
        return new RemoteHashResponse(inspector, hash, newHashItem(proxy, request, artifact, hash));
      }
      else {
        throw new ItemNotFoundException(request);
      }
    }
    catch (IOException e) {
      throw new LocalStorageException(e);
    }
View Full Code Here

      URI.create(request.getRequestPath());
    }
    catch (IllegalArgumentException e) {
      log.warn("Remote HTTP request with malformed path attempted: repository {}, path {}", repository,
          request.getRequestPath());
      throw new ItemNotFoundException(
          ItemNotFoundException
              .reasonFor(request, repository, "Malformed HTTP request path '{}'", request.getRequestPath()),
          e);
    }
  }
View Full Code Here

    try {
      Gav gav = repository.getMetadataManager().resolveArtifact(gavRequest);

      if (gav == null) {
        throw new ItemNotFoundException(reasonFor(gavRequest, repository,
            "Request %s is not resolvable in repository %s", gavRequest.getRequestPath(),
            RepositoryStringUtils.getHumanizedNameString(repository)));
      }

      return gav;
View Full Code Here

    try {
      return getMasterRepository().retrieveItem(request);
    }
    catch (AccessDeniedException e) {
      // if client has no access to content over shadow, we just hide the fact
      throw new ItemNotFoundException(reasonFor(request, this,
          "Path %s not found in repository %s",
          RepositoryStringUtils.getHumanizedNameString(this)), e);
    }
  }
View Full Code Here

      throws StorageException, IllegalOperationException, UnsupportedStorageOperationException, ItemNotFoundException
  {
    List<StorageItem> items = doRetrieveItems(request);

    if (items.isEmpty()) {
      throw new ItemNotFoundException(reasonFor(request, this,
          "Metadata %s not found in any of the members of %s.", request.getRequestPath(),
          RepositoryStringUtils.getHumanizedNameString(this)));
    }

    if (!isMergeMetadata()) {
      // not merging: return the 1st and ciao
      return items.get(0);
    }

    List<Metadata> existingMetadatas = new ArrayList<Metadata>();

    try {
      for (StorageItem item : items) {
        if (!(item instanceof StorageFileItem)) {
          break;
        }

        StorageFileItem fileItem = (StorageFileItem) item;

        try {
          existingMetadatas.add(parseMetadata(fileItem));
        }
        catch (IOException e) {
          log.warn(
              "IOException during parse of metadata UID=\"" + fileItem.getRepositoryItemUid().toString()
                  + "\", will be skipped from aggregation!", e);

          eventBus().post(
              newMetadataFailureEvent(fileItem,
                  "Invalid metadata served by repository. If repository is proxy, please check out what is it serving!"));
        }
        catch (MetadataException e) {
          log.warn(
              "Metadata exception during parse of metadata from UID=\""
                  + fileItem.getRepositoryItemUid().toString() + "\", will be skipped from aggregation!", e);

          eventBus().post(
              newMetadataFailureEvent(fileItem,
                  "Invalid metadata served by repository. If repository is proxy, please check out what is it serving!"));
        }
      }

      if (existingMetadatas.isEmpty()) {
        throw new ItemNotFoundException(reasonFor(request, this,
            "Metadata %s not parseable in any of the members of %s.", request.getRequestPath(),
            RepositoryStringUtils.getHumanizedNameString(this)));
      }

      Metadata result = existingMetadatas.get(0);
View Full Code Here

  protected void shouldTryRemote(final ResourceStoreRequest request)
      throws IllegalOperationException, ItemNotFoundException
  {
    if (request.isRequestLocalOnly()) {
      throw new ItemNotFoundException(ItemNotFoundException.reasonFor(request, this,
          "Request is marked as local-only, remote access not allowed from %s", this));
    }
    if (getProxyMode() != null && !getProxyMode().shouldProxy()) {
      throw new ItemNotFoundException(ItemNotFoundException.reasonFor(request, this,
          "Repository proxy-mode is %s, remote access not allowed from %s", getProxyMode(), this));
    }
  }
View Full Code Here

  {
    AbstractStorageItem item = null;
    AbstractStorageItem remoteItem = null;

    // proxyMode and request.localOnly decides 1st
    ItemNotFoundException noRemoteAccessReason = null;
    try {
      shouldTryRemote(request);
    }
    catch (ItemNotFoundException e) {
      noRemoteAccessReason = e;
    }

    if (noRemoteAccessReason == null) {
      for (RequestStrategy strategy : getRegisteredStrategies().values()) {
        try {
          strategy.onRemoteAccess(this, request, localItem);
        }
        catch (ItemNotFoundException e) {
          noRemoteAccessReason = e;
          // escape
          break;
        }
      }
    }

    if (noRemoteAccessReason == null) {
      // we are able to go remote
      if (localItem == null || request.isRequestAsExpired() || isOld(localItem)) {
        // we should go remote coz we have no local copy or it is old
        try {
          boolean shouldGetRemote = false;

          if (localItem != null) {
            if (log.isDebugEnabled()) {
              log.debug(
                  "Item " + request.toString()
                      + " is old, checking for newer file on remote then local: "
                      + new Date(localItem.getModified()));
            }

            // check is the remote newer than the local one
            try {
              shouldGetRemote = doCheckRemoteItemExistence(localItem, request);

              if (!shouldGetRemote) {
                markItemRemotelyChecked(localItem);

                if (log.isDebugEnabled()) {
                  log.debug(
                      "No newer version of item " + request.toString() + " found on remote storage.");
                }
              }
              else {
                if (log.isDebugEnabled()) {
                  log.debug(
                      "Newer version of item " + request.toString() + " is found on remote storage.");
                }
              }

            }
            catch (RemoteStorageException ex) {
              // NEXUS-4593 HTTP status 403 should not lead to autoblock
              if (!(ex instanceof RemoteAccessDeniedException)
                  && !(ex instanceof RemoteStorageTransportException)) {
                autoBlockProxying(ex);
              }

              if (ex instanceof RemoteStorageTransportException) {
                throw ex;
              }

              // do not go remote, but we did not mark it as "remote checked" also.
              // let the user do proper setup and probably it will try again
              shouldGetRemote = false;
            }
            catch (IOException ex) {
              // do not go remote, but we did not mark it as "remote checked" also.
              // let the user do proper setup and probably it will try again
              shouldGetRemote = false;
            }
          }
          else {
            // we have no local copy of it, try to get it unconditionally
            shouldGetRemote = true;
          }

          if (shouldGetRemote) {
            // this will GET it unconditionally
            try {
              remoteItem = doRetrieveRemoteItem(request);

              if (log.isDebugEnabled()) {
                log.debug("Item " + request.toString() + " found in remote storage.");
              }
            }
            catch (StorageException ex) {
              if (ex instanceof RemoteStorageException
                  // NEXUS-4593 HTTP status 403 should not lead to autoblock
                  && !(ex instanceof RemoteAccessDeniedException)
                  && !(ex instanceof RemoteStorageTransportException)) {
                autoBlockProxying(ex);
              }

              if (ex instanceof RemoteStorageTransportException
                  || ex instanceof LocalStorageEOFException) {
                throw ex;
              }

              if (ex instanceof RemoteAccessDeniedException) {
                log.debug("Error code 403 {} obtaining {} from remote storage.", ex.getMessage(), request);
                request.getRequestContext().put("remote.accessDeniedException", ex);
              }

              remoteItem = null;

              // cleanup if any remnant is here
              try {
                if (localItem == null) {
                  deleteItem(false, request);
                }
              }
              catch (ItemNotFoundException ex1) {
                // ignore
              }
              catch (UnsupportedStorageOperationException ex2) {
                // will not happen
              }
            }
          }
          else {
            remoteItem = null;
          }
        }
        catch (ItemNotFoundException ex) {
          if (log.isDebugEnabled()) {
            log.debug("Item " + request.toString() + " not found in remote storage.");
          }

          remoteItem = null;
        }
      }

      if (localItem == null && remoteItem == null) {
        // we dont have neither one, NotFoundException
        if (log.isDebugEnabled()) {
          log.debug(
              "Item " + request.toString()
                  + " does not exist in local or remote storage, throwing ItemNotFoundException.");
        }

        throw new ItemNotFoundException(reasonFor(request, this,
            "Path %s not found in local nor in remote storage of %s", request.getRequestPath(),
            this));
      }
      else if (localItem != null && remoteItem == null) {
        // simple: we have local but not remote (coz we are offline or coz it is not newer)
        if (log.isDebugEnabled()) {
          log.debug(
              "Item " + request.toString()
                  + " does exist in local storage and is fresh, returning local one.");
        }

        item = localItem;
      }
      else {
        // the fact that remoteItem != null means we _have_ to return that one
        // OR: we had no local copy
        // OR: remoteItem is for sure newer (look above)
        item = remoteItem;
      }

    }
    else {
      // we cannot go remote
      if (localItem != null) {
        if (log.isDebugEnabled()) {
          log.debug(
              "Item " + request.toString() + " does exist locally and cannot go remote, returning local one.");
        }

        item = localItem;
      }
      else {
        if (log.isDebugEnabled()) {
          log.debug(
              "Item " + request.toString()
                  + " does not exist locally and cannot go remote, throwing ItemNotFoundException.");
        }

        throw new ItemNotFoundException(ItemNotFoundException.reasonFor(request, this,
            noRemoteAccessReason.getMessage()), noRemoteAccessReason);
      }
    }

    return item;
  }
View Full Code Here

      else if (lastException instanceof ItemNotFoundException) {
        throw (ItemNotFoundException) lastException;
      }

      // validation failed, I guess.
      throw new ItemNotFoundException(reasonFor(request, this,
          "Path %s fetched from remote storage of %s but failed validation.", request.getRequestPath(),
          this));
    }
    finally {
      itemUidLock.unlock();
View Full Code Here

      try {
        try {
          if (!getProxyMode().shouldCheckRemoteStatus()) {
            setRemoteStatus(
                RemoteStatus.UNAVAILABLE,
                new ItemNotFoundException(reasonFor(request, AbstractProxyRepository.this,
                    "Proxy mode %s or repository %s forbids remote storage use.", getProxyMode(),
                    AbstractProxyRepository.this)));
          }
          else {
            if (isRemoteStorageReachable(request)) {
              autoUnBlockProxying();
            }
            else {
              autoBlockProxying(new ItemNotFoundException(reasonFor(request,
                  AbstractProxyRepository.this, "Remote peer of repository %s detected as unavailable.",
                  AbstractProxyRepository.this)));
            }
          }
        }
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.ItemNotFoundException$ItemNotFoundInRepositoryReason

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.