Package org.sonatype.nexus.views.rawbinaries.internal.storage

Examples of org.sonatype.nexus.views.rawbinaries.internal.storage.RawBinary


    ViewRequest request = mockRequest(PATH, HttpMethod.GET);

    HandlerContext context = mock(HandlerContext.class);
    when(context.getRequest()).thenReturn(request);

    final RawBinary localBinary = mock(RawBinary.class);
    when(localBinary.getPath()).thenReturn(PATH);

    when(store.getForPath(PATH)).thenReturn(asList(localBinary));

    handler.handle(context);
View Full Code Here


        final List<RawBinary> localBinaries = binaryStore.getForPath(requestPath);

        // Do we have a single result whose path matches the request exactly?

        final RawBinary exactMatch = exactMatch(localBinaries, requestPath);
        if (exactMatch != null) {
          return createStreamResponse(exactMatch);
        }

        // If not, contact the remote source and store whatever it has
View Full Code Here

        req.getPath() + (req.getQueryString() == null ? "" : "?" + req.getQueryString()));
    switch (req.getMethod()) {

      case PUT:
        try {
          final RawBinary created = binaryStore.create(binaryPath, req.getContentType(), req.getInputStream());

          if (created != null) {
            return Responses.created();
          }
          else {
            return new StatusResponse(409,
                "Conflict: binary already exists. To replace it, DELETE it first.");
          }
        }
        catch (IOException e) {
          Throwables.propagate(e);
        }

      case DELETE:
        if (binaryStore.delete(binaryPath)) {
          return Responses.deleted();
        }
        else {
          return Responses.notFound("No artifact to be deleted at that location.");
        }

      case GET:
        final List<RawBinary> binaries = binaryStore.getForPath(binaryPath);

        // Do we have a single result whose path matches the request exactly?
        if (isSuccesfulRequestForSingleArtifact(binaryPath, binaries)) {
          final RawBinary binary = binaries.get(0);
          return Responses
              .streamResponse(binary.getInputStream(), binary.getContentType(), binary.getModifiedDate().toDate());
        }

        StringBuilder html = new StringBuilder();
        html.append("<html><body>");
        // missing HTML encoding

        html.append("<h1>").append(HtmlEscapers.htmlEscaper().escape(binaryPath)).append("</h1>");
        html.append("<ul>");

        for (RawBinary binary : binaries) {

          html.append(
              new Formatter()
                  .format("<li><a href=\"%s\">%s</a></li>", stripLeadingSlash(binary.getPath()), binary.getPath()));
        }
        html.append("</ul>");
        html.append("</body></html>");

        return Responses.html(html.toString());
View Full Code Here

      return true;
    }
  }

  private RawBinary asRawBinary(final RawBinaryMetadata metadata, final Blob blob) {
    return new RawBinary()
    {
      @Override
      public String getPath() {
        return metadata.getPath();
      }
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.views.rawbinaries.internal.storage.RawBinary

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.