/** * Start route. */ @Nonnull Response start(final Route route) throws Exception { checkNotNull(route); checkState(handlers == null, "Already started"); log.debug("Starting: {}", route); // Copy the handler list to allow modification this.handlers = new ArrayList<>(route.getHandlers()).listIterator(); return proceed(); } }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { Stopwatch watch = Stopwatch.createStarted(); try { return context.proceed(); } finally { String elapsed = watch.toString(); context.getAttributes().set(ELAPSED_KEY, elapsed); log.trace("Timing: {}", elapsed); } } }
@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(); }
@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); } }
@Override public Response handle(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(); }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { final Predicate<Response> requestPredicate = requestPredicate(context.getRequest()); if (requestPredicate != null) { makeUnconditional(context.getRequest()); try { return handleConditional(context, requestPredicate); } finally { makeConditional(context.getRequest()); } } return context.proceed(); }
@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(); } }
@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; } }
@Override public Response handle(Context context) throws Exception { UnitOfWork.begin(context.getRepository().facet(StorageFacet.class).txSupplier()); try { return context.proceed(); } finally { UnitOfWork.end(); } } }
@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; }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { final Response response = context.proceed(); Payload payload = response.getPayload(); if (response.getStatus().isSuccessful() && payload instanceof Content) { final Content content = (Content) payload; final DateTime lastModified = content.getAttributes().get(Content.CONTENT_LAST_MODIFIED, DateTime.class); if (lastModified != null) { response.getHeaders().set(HttpHeaders.LAST_MODIFIED, DateUtils.formatDate(lastModified.toDate())); } final String etag = content.getAttributes().get(Content.CONTENT_ETAG, String.class); if (etag != null) { response.getHeaders().set(HttpHeaders.ETAG, "\"" + etag + "\""); } } return response; } }
@Override public Response handle(final Context context) throws Exception { Response response = context.proceed(); try { if (isSuccessfulRequestWithContent(context, response)) { Repository repository = context.getRepository(); StorageFacet storageFacet = repository.facet(StorageFacet.class); Content content = (Content) response.getPayload(); AttributesMap attributes = content.getAttributes(); maybeUpdateLastDownloaded(storageFacet, attributes); } } catch (Exception e) { log.error("Failed to update last downloaded time for request {}", context.getRequest().getPath(), e); } return response; }
public Response handle(@Nonnull final Context context) throws Exception { try { return context.proceed();
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { final Response response = context.proceed();
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(); } }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { 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(); } }
public Response handle(@Nonnull final Context context) throws Exception { //NOSONAR try { return context.proceed();
@Override public Response handle(final Context context) throws Exception { Response response = context.proceed(); if (assetDownloadCountStore.isEnabled() && response != null && response.getStatus().isSuccessful() && isGetRequest(context.getRequest())) { Asset asset = getAssetFromPayload(response.getPayload()); if (asset != null) { assetDownloadCountStore.incrementCount(context.getRepository().getName(), asset.name()); } } return response; }