Java Code Examples for org.sonatype.nexus.repository.http.HttpResponses#ok()
The following examples show how to use
org.sonatype.nexus.repository.http.HttpResponses#ok() .
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: ComposerHostedUploadHandler.java From nexus-repository-composer with Eclipse Public License 1.0 | 6 votes |
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { String vendor = getVendorToken(context); String project = getProjectToken(context); String version = getVersionToken(context); Request request = checkNotNull(context.getRequest()); Payload payload = checkNotNull(request.getPayload()); Repository repository = context.getRepository(); ComposerHostedFacet hostedFacet = repository.facet(ComposerHostedFacet.class); hostedFacet.upload(vendor, project, version, payload); return HttpResponses.ok(); }
Example 2
Source File: AptHostedHandler.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private Response doPost(final Context context, final String path, final String method, final AptHostedFacet hostedFacet) throws IOException { if ("rebuild-indexes".equals(path)) { hostedFacet.rebuildIndexes(); return HttpResponses.ok(); } else if ("".equals(path)) { hostedFacet.ingestAsset(context.getRequest().getPayload()); return HttpResponses.created(); } else { return HttpResponses.methodNotAllowed(method, GET, HEAD); } }
Example 3
Source File: OrientArchetypeCatalogHandler.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * 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 4
Source File: PackagesGroupHandler.java From nexus-repository-r with Eclipse Public License 1.0 | 6 votes |
@Override protected Response doGet(@Nonnull final Context context, @Nonnull final GroupHandler.DispatchedRepositories dispatched) throws Exception { GroupFacet groupFacet = context.getRepository().facet(GroupFacet.class); Map<Repository, Response> responses = getAll(context, groupFacet.members(), dispatched); List<Response> successfulResponses = responses.values().stream() .filter(response -> response.getStatus().getCode() == HttpStatus.OK && response.getPayload() != null) .collect(Collectors.toList()); if (successfulResponses.isEmpty()) { return notFoundResponse(context); } if (successfulResponses.size() == 1) { return successfulResponses.get(0); } List<List<Map<String, String>>> parts = successfulResponses.stream().map(this::parseResponse).collect( Collectors.toList()); List<Map<String, String>> merged = RPackagesUtils.merge(parts); return HttpResponses.ok(RPackagesUtils.buildPackages(merged)); }
Example 5
Source File: OrientPyPiHostedHandlers.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Handle request for search. */ public Handler search() { return context -> { Payload payload = checkNotNull(context.getRequest().getPayload()); try (InputStream is = payload.openInputStream()) { QueryBuilder query = parseSearchRequest(context.getRepository().getName(), is); List<PyPiSearchResult> results = new ArrayList<>(); for (SearchHit hit : searchQueryService.browse(unrestricted(query))) { Map<String, Object> source = hit.getSource(); Map<String, Object> formatAttributes = (Map<String, Object>) source.getOrDefault( MetadataNodeEntityAdapter.P_ATTRIBUTES, Collections.emptyMap()); Map<String, Object> pypiAttributes = (Map<String, Object>) formatAttributes.getOrDefault(PyPiFormat.NAME, Collections.emptyMap()); String name = Strings.nullToEmpty((String) pypiAttributes.get(PyPiAttributes.P_NAME)); String version = Strings.nullToEmpty((String) pypiAttributes.get(PyPiAttributes.P_VERSION)); String summary = Strings.nullToEmpty((String) pypiAttributes.get(PyPiAttributes.P_SUMMARY)); results.add(new PyPiSearchResult(name, version, summary)); } String response = buildSearchResponse(results); return HttpResponses.ok(new StringPayload(response, ContentTypes.APPLICATION_XML)); } }; }
Example 6
Source File: NpmSearchGroupHandler.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Override protected Response doGet(@Nonnull final Context context, @Nonnull final DispatchedRepositories dispatched) throws Exception { checkNotNull(context); checkNotNull(dispatched); Request request = context.getRequest(); Parameters parameters = request.getParameters(); String text = npmSearchParameterExtractor.extractText(parameters); NpmSearchResponse response; if (text.isEmpty()) { response = npmSearchResponseFactory.buildEmptyResponse(); } else { response = searchMembers(context, dispatched, parameters); } String content = npmSearchResponseMapper.writeString(response); return HttpResponses.ok(new StringPayload(content, ContentTypes.APPLICATION_JSON)); }
Example 7
Source File: ComposerGroupMergingHandler.java From nexus-repository-composer with Eclipse Public License 1.0 | 6 votes |
@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)); }
Example 8
Source File: NpmPingHandler.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { StringPayload payload = new StringPayload("{}", APPLICATION_JSON); return HttpResponses.ok(payload); }
Example 9
Source File: AptSigningHandler.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@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 10
Source File: OrientPyPiIndexGroupHandler.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected Response doGet(@Nonnull final Context context, @Nonnull final GroupHandler.DispatchedRepositories dispatched) throws Exception { checkNotNull(context); checkNotNull(dispatched); String name; AssetKind assetKind = context.getAttributes().get(AssetKind.class); if (ROOT_INDEX.equals(assetKind)) { name = INDEX_PATH_PREFIX; } else { name = name(context.getAttributes().require(TokenMatcher.State.class)); } OrientPyPiGroupFacet groupFacet = context.getRepository().facet(OrientPyPiGroupFacet.class); Content content = groupFacet.getFromCache(name, assetKind); Map<Repository, Response> memberResponses = getAll(context, groupFacet.members(), dispatched); if (groupFacet.isStale(name, content, memberResponses)) { return HttpResponses.ok( groupFacet.buildIndexRoot( name, assetKind, lazyMergeResult(name, assetKind, memberResponses))); } return HttpResponses.ok(content); }
Example 11
Source File: IndexGroupHandler.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@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 12
Source File: AptHostedHandler.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
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 13
Source File: AptHostedHandler.java From nexus-repository-apt with Eclipse Public License 1.0 | 5 votes |
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 14
Source File: AptHostedHandler.java From nexus-repository-apt with Eclipse Public License 1.0 | 5 votes |
@Override public Response handle(Context context) throws Exception { String path = assetPath(context); String method = context.getRequest().getAction(); AptFacet aptFacet = context.getRepository().facet(AptFacet.class); AptHostedFacet hostedFacet = context.getRepository().facet(AptHostedFacet.class); switch (method) { case GET: case HEAD: { return doGet(path, aptFacet); } case POST: { if (path.equals("rebuild-indexes")) { hostedFacet.rebuildIndexes(); return HttpResponses.ok(); } else if (path.equals("")) { hostedFacet.ingestAsset(context.getRequest().getPayload()); return HttpResponses.created(); } else { return HttpResponses.methodNotAllowed(method, GET, HEAD); } } default: return HttpResponses.methodNotAllowed(method, GET, HEAD, POST); } }
Example 15
Source File: AptSigningHandler.java From nexus-repository-apt with Eclipse Public License 1.0 | 5 votes |
@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(); }
Example 16
Source File: AptSnapshotHandler.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
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 17
Source File: NpmResponses.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Nonnull static Response ok() { return HttpResponses.ok(successPayload); }
Example 18
Source File: NpmResponses.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Nonnull public static Response ok(@Nonnull final Payload payload) { return HttpResponses.ok(checkNotNull(payload)); }
Example 19
Source File: ProxyHandler.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
protected Response buildPayloadResponse(final Context context, final Payload payload) { return HttpResponses.ok(payload); }
Example 20
Source File: MergingGroupHandler.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@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(); } }