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

The following examples show how to use org.sonatype.nexus.repository.view.Context#getRequest() . 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: NpmSearchGroupHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@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 2
Source File: OrientPyPiHostedHandlers.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Utility method to extract the uploaded content. Populates the attributes map with any other metadata. One and only
 * one file upload with a field name of "content" should be present in the upload, or {@link IllegalStateException}
 * is thrown to indicate unexpected input.
 */
private SignablePyPiPackage extractPayloads(final Context context) throws IOException {
  checkNotNull(context);
  Map<String, String> attributes = new LinkedHashMap<>();
  Request request = context.getRequest();
  TempBlobPartPayload contentBlob = null;
  TempBlobPartPayload signatureBlob = null;

  for (PartPayload payload : checkNotNull(request.getMultiparts())) {
    if (payload.isFormField()) {
      addAttribute(attributes, payload);
    }
    else if (FIELD_CONTENT.equals(payload.getFieldName())) {
      checkState(contentBlob == null);
      contentBlob = createBlobFromPayload(payload, context.getRepository());
    } else if (GPG_SIGNATURE.equals(payload.getFieldName())) {
      checkState(signatureBlob == null);
      signatureBlob = createBlobFromPayload(payload, context.getRepository());
    }
  }
  checkState (contentBlob != null);
  return new SignablePyPiPackage(contentBlob, attributes, signatureBlob);
}
 
Example 3
Source File: OrientPyPiProxyFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected HttpRequestBase buildFetchHttpRequest(final URI uri, final Context context) {
  Request request = context.getRequest();
  // If we're doing a search operation, we have to proxy the content of the XML-RPC POST request to the PyPI server...
  if (isSearchRequest(request)) {
    Payload payload = checkNotNull(request.getPayload());
    try {
      ContentType contentType = ContentType.parse(payload.getContentType());
      HttpPost post = new HttpPost(uri);
      post.setEntity(new InputStreamEntity(payload.openInputStream(), payload.getSize(), contentType));
      return post;
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
  return super.buildFetchHttpRequest(uri, context); // URI needs to be replaced here
}
 
Example 4
Source File: GroupHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the first OK response from member repositories or {@link HttpResponses#notFound()} if none of the members
 * responded with OK.
 */
protected Response getFirst(@Nonnull final Context context,
                            @Nonnull final List<Repository> members,
                            @Nonnull final DispatchedRepositories dispatched)
    throws Exception
{
  final Request request = context.getRequest();
  for (Repository member : members) {
    log.trace("Trying member: {}", member);
    // track repositories we have dispatched to, prevent circular dispatch for nested groups
    if (dispatched.contains(member)) {
      log.trace("Skipping already dispatched member: {}", member);
      continue;
    }
    dispatched.add(member);

    final ViewFacet view = member.facet(ViewFacet.class);
    final Response response = view.dispatch(request, context);
    log.trace("Member {} response {}", member, response.getStatus());
    if (isValidResponse(response)) {
      return response;
    }
  }
  return notFoundResponse(context);
}