private boolean isNotFound(final Response response) { return HttpStatus.NOT_FOUND == response.getStatus().getCode(); }
private boolean isSuccessfulOrNotModified(final Response response) { return response.getStatus().isSuccessful() || response.getStatus().getCode() == 304; }
/** * Parses a search response, returning the marshaled {@link NpmSearchResponse}. */ @Nullable private NpmSearchResponse parseSearchResponse(final Repository repository, final Response response) { Payload payload = response.getPayload(); if (response.getStatus().getCode() == HttpStatus.OK && payload != null) { try (InputStream in = payload.openInputStream()) { return npmSearchResponseMapper.readFromInputStream(in); } catch (IOException e) { if (log.isDebugEnabled()) { log.warn("Unable to process search response for repository {}, skipping", repository.getName(), e); } else { log.warn("Unable to process search response for repository {}, cause: {}, skipping", repository.getName(), e.getMessage()); } } } return null; } }
@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 protected final Response doGet(@Nonnull final Context context, @Nonnull final GroupHandler.DispatchedRepositories dispatched) throws Exception { Repository repository = context.getRepository(); GroupFacet groupFacet = repository.facet(GroupFacet.class); makeUnconditional(context.getRequest()); Map<Repository, Response> responses; try { responses = getAll(context, groupFacet.members(), dispatched); } finally { makeConditional(context.getRequest()); } List<Payload> payloads = responses.values().stream() .filter(response -> response.getStatus().getCode() == HttpStatus.OK && response.getPayload() != null) .map(Response::getPayload) .collect(Collectors.toList()); if (payloads.isEmpty()) { return notFoundResponse(context); } return HttpResponses.ok(merge(repository, payloads)); }
LinkedHashMap<Repository, Content> contents = Maps.newLinkedHashMap(); for (Map.Entry<Repository, Response> entry : responses.entrySet()) { if (entry.getValue().getStatus().getCode() == HttpStatus.OK) { Response response = entry.getValue(); if (response.getPayload() instanceof Content) {
@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()); }
@Override protected Response buildResponse(final Status status, final Context context) { if (status.getCode() == HttpStatus.SC_NOT_FOUND) { State state = context.getAttributes().require(TokenMatcher.State.class); NpmPackageId packageId = NpmHandlers.packageId(state); return NpmResponses.packageNotFound(packageId); } return super.buildResponse(status, context); } }
if (response.getStatus().getCode() != HttpStatus.OK) {