Java Code Examples for org.sonatype.nexus.repository.http.HttpResponses#notFound()

The following examples show how to use org.sonatype.nexus.repository.http.HttpResponses#notFound() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrientArchetypeCatalogHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tries to get the catalog from hosted repository, and generate it if not present.
 */
private Response doGet(final MavenPath path, final Repository repository) throws IOException {
  MavenFacet mavenFacet = repository.facet(MavenFacet.class);
  Content content = mavenFacet.get(path);
  if (content == null) {
    // try to generate it
    repository.facet(MavenHostedFacet.class).rebuildArchetypeCatalog();
    content = mavenFacet.get(path);
    if (content == null) {
      return HttpResponses.notFound(path.getPath());
    }
  }
  AttributesMap attributesMap = content.getAttributes();
  MavenFacetUtils.mayAddETag(attributesMap, getHashAlgorithmFromContent(attributesMap));
  return HttpResponses.ok(content);
}
 
Example 2
Source File: IndexHtmlForwardHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  String path = context.getRequest().getPath();

  // sanity, to ensure we don't corrupt the path
  if (!path.endsWith("/")) {
    path = path + "/";
  }

  for (String file : INDEX_FILES) {
    Response response = forward(context, path + file);
    // return response if it was successful or an error which was not not found
    if (response.getStatus().isSuccessful() || response.getStatus().getCode() != HttpStatus.NOT_FOUND) {
      return response;
    }
    // otherwise try next index file
  }

  // or there is no such file, give up not found
  return HttpResponses.notFound(context.getRequest().getPath());
}
 
Example 3
Source File: ConanHostedFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
public Response get(final Context context) {
  log.debug("Request {}", context.getRequest().getPath());

  TokenMatcher.State state = context.getAttributes().require(TokenMatcher.State.class);
  ConanCoords coord = ConanHostedHelper.convertFromState(state);
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);
  String assetPath = ConanHostedHelper.getHostedAssetPath(coord, assetKind);

  Content content = doGet(assetPath);
  if (content == null) {
    return HttpResponses.notFound();
  }

  return new Response.Builder()
      .status(success(OK))
      .payload(new StreamPayload(
          new InputStreamSupplier()
          {
            @Nonnull
            @Override
            public InputStream get() throws IOException {
              return content.openInputStream();
            }
          },
          content.getSize(),
          content.getContentType()))
      .build();
}
 
Example 4
Source File: AptHostedHandler.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
private Response doGet(String path, AptFacet aptFacet) throws IOException {
  Content content = aptFacet.get(path);
  if (content == null) {
    return HttpResponses.notFound(path);
  }
  return HttpResponses.ok(content);
}
 
Example 5
Source File: AptSnapshotHandler.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
private Response handleSnapshotFetchRequest(Context context, String id, String path) throws Exception {
  Repository repository = context.getRepository();
  AptSnapshotFacet snapshotFacet = repository.facet(AptSnapshotFacet.class);
  if (snapshotFacet.isSnapshotableFile(path)) {
    Content content = snapshotFacet.getSnapshotFile(id, path);
    return content == null ? HttpResponses.notFound() : HttpResponses.ok(content);
  }
  context.getAttributes().set(AptSnapshotHandler.State.class, new AptSnapshotHandler.State(path));
  return context.proceed();
}
 
Example 6
Source File: RawContentHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  String path = contentPath(context);
  String method = context.getRequest().getAction();

  Repository repository = context.getRepository();
  log.debug("{} repository '{}' content-path: {}", method, repository.getName(), path);

  RawContentFacet storage = repository.facet(RawContentFacet.class);

  switch (method) {
    case HEAD:
    case GET: {
      return storage.get(path).map(HttpResponses::ok)
          .orElseGet(() -> HttpResponses.notFound(path));
    }

    case PUT: {
      Payload content = context.getRequest().getPayload();
      storage.put(path, content);
      return HttpResponses.created();
    }

    case DELETE: {
      boolean deleted = storage.delete(path);
      if (deleted) {
        return HttpResponses.noContent();
      }
      return HttpResponses.notFound(path);
    }

    default:
      return HttpResponses.methodNotAllowed(method, GET, HEAD, PUT, DELETE);
  }
}
 
Example 7
Source File: IndexGroupHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  MavenPath mavenPath = context.getAttributes().require(MavenPath.class);
  MavenFacet mavenFacet = context.getRepository().facet(MavenFacet.class);
  Content content = mavenFacet.get(mavenPath);
  if (content == null) {
    return HttpResponses.notFound(mavenPath.getPath());
  }
  return HttpResponses.ok(content);
}
 
Example 8
Source File: HostedHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Response doGet(final MavenPath path, final MavenFacet mavenFacet) throws IOException {
  Content content = mavenFacet.get(path);
  if (content == null) {
    return HttpResponses.notFound(path.getPath());
  }
  AttributesMap attributesMap = content.getAttributes();
  MavenFacetUtils.mayAddETag(attributesMap, getHashAlgorithmFromContent(attributesMap));
  return HttpResponses.ok(content);
}
 
Example 9
Source File: HostedHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Response doDelete(final MavenPath path, final MavenFacet mavenFacet) throws IOException {
  boolean deleted = mavenFacet.delete(path);
  if (!deleted) {
    return HttpResponses.notFound(path.getPath());
  }
  return HttpResponses.noContent();
}
 
Example 10
Source File: MavenContentHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Response doDelete(final MavenPath mavenPath, final MavenContentFacet storage) throws IOException {
  boolean deleted = storage.delete(mavenPath);
  if (deleted) {
    return HttpResponses.noContent();
  }
  return HttpResponses.notFound(mavenPath.getPath());
}
 
Example 11
Source File: AptHostedHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Response doGet(final String path, final AptFacet aptFacet) throws IOException {
  Content content = aptFacet.get(path);
  if (content == null) {
    return HttpResponses.notFound(path);
  }
  return HttpResponses.ok(content);
}
 
Example 12
Source File: AptSnapshotHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Response handleSnapshotFetchRequest(final Context context, final String id, final String path) throws Exception {
  Repository repository = context.getRepository();
  AptSnapshotFacet snapshotFacet = repository.facet(AptSnapshotFacet.class);
  if (snapshotFacet.isSnapshotableFile(path)) {
    Content content = snapshotFacet.getSnapshotFile(id, path);
    return content == null ? HttpResponses.notFound() : HttpResponses.ok(content);
  }
  context.getAttributes().set(AptSnapshotHandler.State.class, new AptSnapshotHandler.State(path));
  return context.proceed();
}
 
Example 13
Source File: ComposerHostedDownloadHandler.java    From nexus-repository-composer with Eclipse Public License 1.0 4 votes vote down vote up
private Response responseFor(@Nullable final Content content) {
  if (content == null) {
    return HttpResponses.notFound();
  }
  return HttpResponses.ok(content);
}
 
Example 14
Source File: MergingGroupHandler.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected Response doGet(@Nonnull final Context context,
                         @Nonnull final DispatchedRepositories dispatched) throws Exception
{
  final MavenPath mavenPath = context.getAttributes().require(MavenPath.class);
  final MavenGroupFacet groupFacet = context.getRepository().facet(MavenGroupFacet.class);
  log.trace("Incoming request for {} : {}", context.getRepository().getName(), mavenPath.getPath());

  final List<Repository> members = groupFacet.members();

  Map<Repository, Response> passThroughResponses = ImmutableMap.of();

  if (!mavenPath.isHash()) {
    // pass request through to proxies/nested-groups before checking our group cache
    Iterable<Repository> proxiesOrGroups = Iterables.filter(members, PROXY_OR_GROUP);
    if (proxiesOrGroups.iterator().hasNext()) {
      passThroughResponses = getAll(context, proxiesOrGroups, dispatched);
    }
  }

  Content content;

  try {
    // now check group-level cache to see if it's been invalidated by any updates
    content = groupFacet.getCached(mavenPath);
    if (content != null) {
      log.trace("Serving cached content {} : {}", context.getRepository().getName(), mavenPath.getPath());
      return HttpResponses.ok(content);
    }
  }
  catch (RetryDeniedException e) {
    log.debug("Conflict fetching cached content {} : {}", context.getRepository().getName(), mavenPath.getPath(), e);
  }

  if (!mavenPath.isHash()) {
    // this will fetch the remaining responses, thanks to the 'dispatched' tracking
    Map<Repository, Response> remainingResponses = getAll(context, members, dispatched);

    // merge the two sets of responses according to member order
    LinkedHashMap<Repository, Response> responses = new LinkedHashMap<>();
    for (Repository member : members) {
      Response response = passThroughResponses.get(member);
      if (response == null) {
        response = remainingResponses.get(member);
      }
      if (response != null) {
        responses.put(member, response);
      }
    }

    // merge the individual responses and cache the result
    content = groupFacet.mergeAndCache(mavenPath, responses);

    if (content != null) {
      log.trace("Responses merged {} : {}", context.getRepository().getName(), mavenPath.getPath());
      return HttpResponses.ok(content);
    }

    log.trace("Not found respone to merge {} : {}", context.getRepository().getName(), mavenPath.getPath());
    return HttpResponses.notFound();
  }
  else {
    // hash should be available if corresponding content fetched. out of bound request?
    log.trace("Outbound request for hash {} : {}", context.getRepository().getName(), mavenPath.getPath());
    return HttpResponses.notFound();
  }
}
 
Example 15
Source File: GroupHandler.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns standard 404 with no message. Override for format specific messaging.
 */
protected Response notFoundResponse(final Context context) {
  return HttpResponses.notFound();
}
 
Example 16
Source File: ProxyHandler.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
protected Response buildNotFoundResponse(final Context context) {
  return HttpResponses.notFound();
}