Java Code Examples for org.sonatype.nexus.repository.http.HttpResponses#methodNotAllowed()

The following examples show how to use org.sonatype.nexus.repository.http.HttpResponses#methodNotAllowed() . 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: HostedHandler.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 {
  MavenPath path = context.getAttributes().require(MavenPath.class);
  MavenFacet mavenFacet = context.getRepository().facet(MavenFacet.class);
  String action = context.getRequest().getAction();
  switch (action) {
    case GET:
    case HEAD:
      return doGet(path, mavenFacet);

    case PUT:
      return doPut(context, path, mavenFacet);

    case DELETE:
      return doDelete(path, mavenFacet);

    default:
      return HttpResponses.methodNotAllowed(context.getRequest().getAction(), GET, HEAD, PUT, DELETE);
  }
}
 
Example 2
Source File: AptHostedHandler.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 = 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:
      return doPost(context, path, method, hostedFacet);
    default:
      return HttpResponses.methodNotAllowed(method, GET, HEAD, POST);
  }
}
 
Example 3
Source File: AptHostedHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
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 4
Source File: AptSnapshotHandler.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private Response handleSnapshotAdminRequest(final Context context, final String id) throws Exception {
  String method = context.getRequest().getAction();
  Repository repository = context.getRepository();
  AptSnapshotFacet snapshotFacet = repository.facet(AptSnapshotFacet.class);

  switch (method) {
    case MKCOL:
      return doMkcol(id, snapshotFacet);
    case PUT:
      return doPut(context, id, snapshotFacet);
    case DELETE:
      return doDelete(id, snapshotFacet);
    default:
      return HttpResponses.methodNotAllowed(method, DELETE, MKCOL, PUT);
  }
}
 
Example 5
Source File: GroupHandler.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 {
  final String method = context.getRequest().getAction();
  switch (method) {
    case GET:
    case HEAD: {
      final DispatchedRepositories dispatched = context.getRequest().getAttributes()
          .getOrCreate(DispatchedRepositories.class);
      return doGet(context, dispatched);
    }

    default:
      return HttpResponses.methodNotAllowed(method, GET, HEAD);
  }
}
 
Example 6
Source File: AptHostedHandler.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
@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 7
Source File: AptSnapshotHandler.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
private Response handleSnapshotAdminRequest(Context context, String id) throws Exception {
  String method = context.getRequest().getAction();
  Repository repository = context.getRepository();
  AptSnapshotFacet snapshotFacet = repository.facet(AptSnapshotFacet.class);

  switch (method) {
    case MKCOL: {
      snapshotFacet.createSnapshot(id, new AllSnapshotComponentSelector());
      return HttpResponses.created();
    }

    case PUT: {
      try (InputStream is = context.getRequest().getPayload().openInputStream()) {
        ControlFile settings = new ControlFileParser().parseControlFile(is);
        snapshotFacet.createSnapshot(id, new FilteredSnapshotComponentSelector(settings));
      }
      return HttpResponses.created();
    }

    case DELETE: {
      snapshotFacet.deleteSnapshot(id);
      return HttpResponses.noContent();
    }

    default:
      return HttpResponses.methodNotAllowed(method, DELETE, MKCOL, PUT);
  }
}
 
Example 8
Source File: SearchGroupHandler.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 {
  checkNotNull(context);
  final String method = context.getRequest().getAction();
  if (POST.equals(method)) {
    final DispatchedRepositories dispatched = context.getRequest().getAttributes()
        .getOrCreate(DispatchedRepositories.class);
    return doPost(context, dispatched);
  }
  return HttpResponses.methodNotAllowed(method, POST);
}
 
Example 9
Source File: RawContentHandler.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 path = contentPath(context);
  String method = context.getRequest().getAction();

  Repository repository = context.getRepository();
  log.debug("{} repository '{}' content-path: {}", method, repository.getName(), path);

  RawContentFacet storage = repository.facet(RawContentFacet.class);

  switch (method) {
    case HEAD:
    case GET: {
      return storage.get(path).map(HttpResponses::ok)
          .orElseGet(() -> HttpResponses.notFound(path));
    }

    case PUT: {
      Payload content = context.getRequest().getPayload();
      storage.put(path, content);
      return HttpResponses.created();
    }

    case DELETE: {
      boolean deleted = storage.delete(path);
      if (deleted) {
        return HttpResponses.noContent();
      }
      return HttpResponses.notFound(path);
    }

    default:
      return HttpResponses.methodNotAllowed(method, GET, HEAD, PUT, DELETE);
  }
}
 
Example 10
Source File: OrientArchetypeCatalogHandler.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 {
  MavenPath path = context.getAttributes().require(MavenPath.class);
  Repository repository = context.getRepository();
  String action = context.getRequest().getAction();
  switch (action) {
    case GET:
    case HEAD:
      return doGet(path, repository);

    default:
      return HttpResponses.methodNotAllowed(context.getRequest().getAction(), GET, HEAD);
  }
}
 
Example 11
Source File: MavenContentHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  MavenPath mavenPath = contentPath(context);
  String path = mavenPath.getPath();
  String method = context.getRequest().getAction();
  Repository repository = context.getRepository();

  log.debug("{} repository '{}' content-path: {}", method, repository.getName(), path);

  MavenContentFacet storage = repository.facet(MavenContentFacet.class);

  switch (method) {
    case HEAD:
    case GET:
      return doGet(path, storage);

    case PUT:
      doPut(context, mavenPath, storage);
      return HttpResponses.created();

    case DELETE:
      return doDelete(mavenPath, storage);

    default:
      return HttpResponses.methodNotAllowed(method, GET, HEAD, PUT, DELETE);
  }
}
 
Example 12
Source File: MavenArchetypeCatalogHandler.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 method = context.getRequest().getAction();
  switch (method) {
    case GET:
    case HEAD:
      return fetchOrGenerateArchetypeCatalog(context);
    default:
      return HttpResponses.methodNotAllowed(context.getRequest().getAction(), GET, HEAD);
  }
}
 
Example 13
Source File: ProxyHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Builds a not-allowed response if the specified method is unsupported under the specified context, null otherwise.
 */
@Nullable
protected Response buildMethodNotAllowedResponse(final Context context) {
  final String action = context.getRequest().getAction();
  if (!GET.equals(action) && !HEAD.equals(action)) {
    return HttpResponses.methodNotAllowed(action, GET, HEAD);
  }
  return null;
}