Java Code Examples for org.sonatype.nexus.repository.view.Context#proceed()

The following examples show how to use org.sonatype.nexus.repository.view.Context#proceed() . 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: TimingHandler.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 {
  Stopwatch watch = Stopwatch.createStarted();

  try {
    if (meteringHandler != null) {
      context.insertHandler(meteringHandler);
    }
    return context.proceed();
  }
  finally {
    String elapsed = watch.toString();
    context.getAttributes().set(ELAPSED_KEY, elapsed);
    log.trace("Timing: {}", elapsed);
  }
}
 
Example 2
Source File: AptSnapshotHandler.java    From nexus-repository-apt with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Response handle(Context context) throws Exception {
  String path = context.getRequest().getPath();
  Matcher matcher = SNAPSHOT_PATH_PATTERN.matcher(path);
  if (!matcher.matches()) {
    context.getAttributes().set(AptSnapshotHandler.State.class, new AptSnapshotHandler.State(path.substring(1)));
    return context.proceed();
  }

  String id = matcher.group(1);
  path = matcher.group(2);

  if (path.length() == 0) {
    return handleSnapshotAdminRequest(context, id);
  }
  else {
    return handleSnapshotFetchRequest(context, id, path);
  }
}
 
Example 3
Source File: LastDownloadedHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Response handle(final Context context) throws Exception {
  Response response = context.proceed();

  try {
    if (isSuccessfulRequestWithContent(context, response)) {
      Content content = (Content) response.getPayload();
      maybeUpdateLastDownloaded(content.getAttributes());
    }
  }
  catch (Exception e) {
    log.error("Failed to update last downloaded time for request {}", context.getRequest().getPath(), e);
  }

  return response;
}
 
Example 4
Source File: OrientVersionPolicyHandler.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 httpMethod = context.getRequest().getAction();
  if (GET.equals(httpMethod) || HEAD.equals(httpMethod)) {
    return context.proceed();
  }
  final MavenPath path = context.getAttributes().require(MavenPath.class);
  final MavenFacet mavenFacet = context.getRepository().facet(MavenFacet.class);
  final VersionPolicy versionPolicy = mavenFacet.getVersionPolicy();
  if (path.getCoordinates() != null && !versionPolicyValidator.validArtifactPath(versionPolicy, path.getCoordinates())) {
    return HttpResponses.badRequest("Repository version policy: " + versionPolicy + " does not allow version: " +
        path.getCoordinates().getVersion());
  }
  if (!versionPolicyValidator.validMetadataPath(versionPolicy, path.main().getPath())) {
    return HttpResponses.badRequest("Repository version policy: " + versionPolicy +
        " does not allow metadata in path: " + path.getPath());
  }
  return context.proceed();
}
 
Example 5
Source File: VersionPolicyHandler.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 httpMethod = context.getRequest().getAction();
  if (GET.equals(httpMethod) || HEAD.equals(httpMethod)) {
    return context.proceed();
  }
  final MavenPath path = context.getAttributes().require(MavenPath.class);
  final MavenContentFacet mavenFacet = context.getRepository().facet(MavenContentFacet.class);
  final VersionPolicy versionPolicy = mavenFacet.getVersionPolicy();
  final Coordinates coordinates = path.getCoordinates();
  if (coordinates != null && !versionPolicyValidator.validArtifactPath(versionPolicy, coordinates)) {
    return HttpResponses.badRequest("Repository version policy: " + versionPolicy + " does not allow version: " +
        coordinates.getVersion());
  }
  if (!versionPolicyValidator.validMetadataPath(versionPolicy, path.main().getPath())) {
    return HttpResponses.badRequest("Repository version policy: " + versionPolicy +
        " does not allow metadata in path: " + path.getPath());
  }
  return context.proceed();
}
 
Example 6
Source File: AptSnapshotHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Response handle(final Context context) throws Exception {
  String path = context.getRequest().getPath();
  Matcher matcher = SNAPSHOT_PATH_PATTERN.matcher(path);
  if (!matcher.matches()) {
    context.getAttributes().set(AptSnapshotHandler.State.class, new AptSnapshotHandler.State(path.substring(1)));
    return context.proceed();
  }

  String id = matcher.group(1);
  path = matcher.group(2);

  if (path.length() == 0) {
    return handleSnapshotAdminRequest(context, id);
  }
  else {
    return handleSnapshotFetchRequest(context, id, path);
  }
}
 
Example 7
Source File: NegativeCacheHandler.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 action = context.getRequest().getAction();
  if (!NFC_CACHEABLE_ACTIONS.contains(action)) {
    return context.proceed();
  }
  NegativeCacheFacet negativeCache = context.getRepository().facet(NegativeCacheFacet.class);
  NegativeCacheKey key = negativeCache.getCacheKey(context);

  Response response;
  Status status = negativeCache.get(key);
  if (status == null) {
    response = context.proceed();
    if (isNotFound(response)) {
      negativeCache.put(key, response.getStatus());
    }
    else if (response.getStatus().isSuccessful()) {
      negativeCache.invalidate(key);
    }
  }
  else {
    response = buildResponse(status, context);

    log.debug("Found {} in negative cache, returning {}", key, response);
  }
  return response;
}
 
Example 8
Source File: ComposerProviderHandler.java    From nexus-repository-composer with Eclipse Public License 1.0 5 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  Response response = context.proceed();
  if (!Boolean.parseBoolean(context.getRequest().getAttributes().get(DO_NOT_REWRITE, String.class))) {
    if (response.getStatus().getCode() == HttpStatus.OK && response.getPayload() != null) {
      response = HttpResponses
          .ok(composerJsonProcessor.rewriteProviderJson(context.getRepository(), response.getPayload()));
    }
  }
  return response;
}
 
Example 9
Source File: RoutingRuleHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Response handle(final Context context) throws Exception {
  if (routingRuleHelper.isAllowed(context.getRepository(), path(context.getRequest()))) {
    return context.proceed();
  }
  return HttpResponses.forbidden(PATH_IS_BLOCKED);
}
 
Example 10
Source File: SecurityHandler.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 {
  SecurityFacet securityFacet = context.getRepository().facet(SecurityFacet.class);

  //we employ the model that one security check per request is all that is necessary, if this handler is in a nested
  //repository (because this is a group repository), there is no need to check authz again
  if (context.getAttributes().get(AUTHORIZED_KEY) == null) {
    securityFacet.ensurePermitted(context.getRequest());
    context.getAttributes().set(AUTHORIZED_KEY, true);
  }

  return context.proceed();
}
 
Example 11
Source File: UnitOfWorkHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Response handle(Context context) throws Exception {
  UnitOfWork.begin(context.getRepository().facet(StorageFacet.class).txSupplier());
  try {
    return context.proceed();
  }
  finally {
    UnitOfWork.end();
  }
}
 
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: AptSigningHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Response handle(final Context context) throws Exception {
  String path = assetPath(context);
  String method = context.getRequest().getAction();
  AptSigningFacet facet = context.getRepository().facet(AptSigningFacet.class);

  if ("repository-key.gpg".equals(path) && GET.equals(method)) {
    return HttpResponses.ok(facet.getPublicKey());
  }

  return context.proceed();
}
 
Example 14
Source File: MavenArchetypeCatalogHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Response fetchOrGenerateArchetypeCatalog(final Context context) throws Exception {
  Response response = context.proceed();
  if (!response.getStatus().isSuccessful()) {
    return generateArchetypeCatalog(context);
  }
  else {
    return response;
  }
}
 
Example 15
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 16
Source File: HandlerContributor.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 {
  // Ensure the extra handlers are inserted only once, in the case that a handler higher
  // on the stack calls proceed() twice for some reason
  if (!isMarkedExtended(context)) {
    ListIterator<ContributedHandler> handlerIterator = contributedHandlers.listIterator(contributedHandlers.size());
    while (handlerIterator.hasPrevious()) {
      context.insertHandler(handlerIterator.previous());
    }
    markExtended(context);
  }

  return context.proceed();
}
 
Example 17
Source File: MavenArchetypeCatalogHandler.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private Response generateArchetypeCatalog(final Context context) throws Exception {
  Repository repository = context.getRepository();
  MavenArchetypeCatalogFacet archetypeCatalogFacet = repository.facet(MavenArchetypeCatalogFacet.class);
  archetypeCatalogFacet.rebuildArchetypeCatalog();
  return context.proceed();
}
 
Example 18
Source File: PartialFetchHandler.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  final Response response = context.proceed();

  // Range requests only apply to GET
  if (!HttpMethods.GET.equals(context.getRequest().getAction())) {
    return response;
  }

  if (response.getStatus().getCode() != HttpStatus.OK) {
    // We don't interfere with any non-200 responses
    return response;
  }

  final Payload payload = response.getPayload();
  if (payload == null) {
    return response;
  }

  if (payload.getSize() == Payload.UNKNOWN_SIZE) {
    // We can't do much if we don't know how big the payload is
    return response;
  }

  final String rangeHeader = getHeaderValue(context.getRequest(), HttpHeaders.RANGE);
  if (rangeHeader == null) {
    return response;
  }

  final List<Range<Long>> ranges = rangeParser.parseRangeSpec(rangeHeader, payload.getSize());

  if (ranges == null) {
    // The ranges were not satisfiable
    return HttpResponses.rangeNotSatisfiable(payload.getSize());
  }

  if (ranges.isEmpty()) {
    // No ranges were specified, or they could not be parsed
    return response;
  }

  if (ranges.size() > 1) {
    return HttpResponses.notImplemented("Multiple ranges not supported.");
  }

  final String ifRangeHeader = getHeaderValue(context.getRequest(), HttpHeaders.IF_RANGE);
  if (ifRangeHeader != null && !ifRangeHeaderMatches(response, ifRangeHeader)) {
    return response;
  }

  Range<Long> requestedRange = ranges.get(0);

  // Mutate the response
  return partialResponse(response, payload, requestedRange);
}
 
Example 19
Source File: NpmAuditTarballFacet.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception
{
  return context.proceed();
}
 
Example 20
Source File: CondaProxyRecipeTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private static Answer<Response> createPropagationAnswer() {
  return invocation -> {
    Context context = (Context) invocation.getArguments()[0];
    return context.proceed();
  };
}