Package org.sonatype.nexus.proxy.storage.remote

Examples of org.sonatype.nexus.proxy.storage.remote.RemoteItemNotFoundException


      // Even though it is unlikely that we actually see a request for a collection here,
      // requests for paths like this over the REST layer will be localOnly not trigger a remote request.
      //
      // The usual case is that there is a request for a directory that is redirected to '/', see below behavior
      // for SC_MOVED_*
      throw new RemoteItemNotFoundException(request, repository, "remoteIsCollection", remoteURL.toString());
    }

    final HttpGet method = new HttpGet(url);

    final HttpResponse httpResponse = executeRequest(repository, request, method, baseUrl, true);

    if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
      InputStream is;
      try {
        is = new Hc4InputStream(repository,
            new InterruptableInputStream(method, httpResponse.getEntity().getContent()));

        String mimeType = null;
        try {
          mimeType = ContentType.getOrDefault(httpResponse.getEntity()).getMimeType();
        }
        catch (ParseException | UnsupportedCharsetException e) {
          // NEXUS-6622: Java/HC4 gave up, let's ask mime support instead then
        }
        if (mimeType == null) {
          mimeType =
              getMimeSupport().guessMimeTypeFromPath(repository.getMimeRulesSource(),
                  request.getRequestPath());
        }

        final long entityLength = httpResponse.getEntity().getContentLength();
        final DefaultStorageFileItem httpItem =
            new DefaultStorageFileItem(repository, request, CAN_READ, CAN_WRITE, new PreparedContentLocator(
                is, mimeType, entityLength != -1 ? entityLength : ContentLocator.UNKNOWN_LENGTH));

        httpItem.setRemoteUrl(remoteURL.toString());
        httpItem.setModified(makeDateFromHeader(httpResponse.getFirstHeader("last-modified")));
        httpItem.setCreated(httpItem.getModified());

        return httpItem;
      }
      catch (IOException ex) {
        release(httpResponse);
        throw new RemoteStorageException("IO Error during response stream handling [repositoryId=\""
            + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\""
            + remoteURL.toString() + "\"]!", ex);
      }
      catch (RuntimeException ex) {
        release(httpResponse);
        throw ex;
      }
    }
    else {
      release(httpResponse);
      if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
        throw new RemoteItemNotFoundException(request, repository, "NotFound", remoteURL.toString());
      }
      else if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY
          || httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY) {
        // NEXUS-5125 unfollowed redirect means collection (path.endsWith("/"))
        // see also HttpClientUtil#configure
        throw new RemoteItemNotFoundException(request, repository, "redirected", remoteURL.toString());
      }
      else {
        throw new RemoteStorageException("The method execution returned result code "
            + httpResponse.getStatusLine().getStatusCode() + " (expected 200). [repositoryId=\""
            + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\""
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.storage.remote.RemoteItemNotFoundException

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.