use of javax.ws.rs.DELETE in project zookeeper by apache.
the class ZNodeResource method deleteZNode.
@DELETE
@Produces({ MediaType.APPLICATION_JSON, "application/javascript", MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM })
public void deleteZNode(@PathParam("path") String path, @DefaultValue("-1") @QueryParam("version") String versionParam, @Context UriInfo ui) throws InterruptedException, KeeperException {
ensurePathNotNull(path);
int version;
try {
version = Integer.parseInt(versionParam);
} catch (NumberFormatException e) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(new ZError(ui.getRequestUri().toString(), path + " bad version " + versionParam)).build());
}
zk.delete(path, version);
}
use of javax.ws.rs.DELETE in project druid by druid-io.
the class ResourceFilterTestHelper method getRequestPaths.
// Feeds in an array of [ PathName, MethodName, ResourceFilter , Injector]
public static Collection<Object[]> getRequestPaths(final Class clazz, final Iterable<Class<?>> mockableInjections, final Iterable<Key<?>> mockableKeys, final Iterable<?> injectedObjs) {
final Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(Binder binder) {
for (Class clazz : mockableInjections) {
binder.bind(clazz).toInstance(EasyMock.createNiceMock(clazz));
}
for (Object obj : injectedObjs) {
binder.bind((Class) obj.getClass()).toInstance(obj);
}
for (Key<?> key : mockableKeys) {
binder.bind((Key<Object>) key).toInstance(EasyMock.createNiceMock(key.getTypeLiteral().getRawType()));
}
binder.bind(AuthConfig.class).toInstance(new AuthConfig(true));
}
});
//Ignore the first "/"
final String basepath = ((Path) clazz.getAnnotation(Path.class)).value().substring(1);
final List<Class<? extends ResourceFilter>> baseResourceFilters = clazz.getAnnotation(ResourceFilters.class) == null ? Collections.<Class<? extends ResourceFilter>>emptyList() : ImmutableList.copyOf(((ResourceFilters) clazz.getAnnotation(ResourceFilters.class)).value());
return ImmutableList.copyOf(Iterables.concat(// Step 3 - Merge all the Objects arrays for each endpoints
Iterables.transform(// - Resource Filter instance for the endpoint
Iterables.filter(// ResourceFilters applied to them
ImmutableList.copyOf(clazz.getDeclaredMethods()), new Predicate<Method>() {
@Override
public boolean apply(Method input) {
return input.getAnnotation(GET.class) != null || input.getAnnotation(POST.class) != null || input.getAnnotation(DELETE.class) != null && (input.getAnnotation(ResourceFilters.class) != null || !baseResourceFilters.isEmpty());
}
}), new Function<Method, Collection<Object[]>>() {
@Override
public Collection<Object[]> apply(final Method method) {
final List<Class<? extends ResourceFilter>> resourceFilters = method.getAnnotation(ResourceFilters.class) == null ? baseResourceFilters : ImmutableList.copyOf(method.getAnnotation(ResourceFilters.class).value());
return Collections2.transform(resourceFilters, new Function<Class<? extends ResourceFilter>, Object[]>() {
@Override
public Object[] apply(Class<? extends ResourceFilter> input) {
if (method.getAnnotation(Path.class) != null) {
return new Object[] { String.format("%s%s", basepath, method.getAnnotation(Path.class).value()), input.getAnnotation(GET.class) == null ? (method.getAnnotation(DELETE.class) == null ? "POST" : "DELETE") : "GET", injector.getInstance(input), injector };
} else {
return new Object[] { basepath, input.getAnnotation(GET.class) == null ? (method.getAnnotation(DELETE.class) == null ? "POST" : "DELETE") : "GET", injector.getInstance(input), injector };
}
}
});
}
})));
}
use of javax.ws.rs.DELETE in project che by eclipse.
the class GitService method deleteRepository.
@DELETE
@Path("repository")
public void deleteRepository(@Context UriInfo uriInfo) throws ApiException {
final RegisteredProject project = projectRegistry.getProject(projectPath);
final FolderEntry gitFolder = project.getBaseFolder().getChildFolder(".git");
gitFolder.getVirtualFile().delete();
projectRegistry.removeProjectType(projectPath, GitProjectType.TYPE_ID);
}
use of javax.ws.rs.DELETE in project che by eclipse.
the class OAuthAuthenticationService method invalidate.
@DELETE
@Path("token")
public void invalidate(@Required @QueryParam("oauth_provider") String oauthProvider) throws BadRequestException, NotFoundException, ServerException, ForbiddenException {
OAuthAuthenticator oauth = getAuthenticator(oauthProvider);
final Subject subject = EnvironmentContext.getCurrent().getSubject();
try {
if (!oauth.invalidateToken(subject.getUserId())) {
throw new NotFoundException("OAuth token for user " + subject.getUserId() + " was not found");
}
} catch (IOException e) {
throw new ServerException(e.getMessage());
}
}
use of javax.ws.rs.DELETE in project OpenAttestation by OpenAttestation.
the class AbstractSimpleResource method deleteOne.
// /**
// * Add an item to the collection. Input Content-Type is any of
// * application/json, application/xml, application/yaml, or text/yaml Output
// * Content-Type is any of application/json, application/xml,
// * application/yaml, or text/yaml
// *
// * The input must represent a single item NOT wrapped in a collection.
// *
// * @param item
// * @return
// */
// @POST
// public T createOne(@BeanParam L locator, T item, @Context HttpServletRequest httpServletRequest, @Context HttpServletResponse httpServletResponse){
// //try { log.debug("createOne: {}", mapper.writeValueAsString(locator)); } catch(JsonProcessingException e) { log.debug("createOne: cannot serialize locator: {}", e.getMessage()); }
// try { log.debug("createOne: {}", mapper.writeValueAsString(locator)); } catch(Exception e) { log.debug("createOne: cannot serialize locator: {}", e.getMessage()); }
// locator.copyTo(item);
// ValidationUtil.validate(item); // throw new MWException(e, ErrorCode.AS_INPUT_VALIDATION_ERROR, input, method.getName());
// if (item.getId() == null) {
// item.setId(new UUID());
// }
// getRepository().create(item);
// httpServletResponse.setStatus(Status.CREATED.getStatusCode());
// return item;
// }
// the delete method is on a specific resource id and because we don't return any content it's the same whether its simple object or json api
// jersey automatically returns status code 204 No Content (successful) to the client because
// we have a void return type
@Path("/{id}")
@DELETE
public void deleteOne(@BeanParam L locator, @Context HttpServletRequest httpServletRequest, @Context HttpServletResponse httpServletResponse) throws IOException {
try {
log.debug("deleteOne: {}", mapper.writeValueAsString(locator));
} catch (JsonProcessingException e) {
log.debug("deleteOne: cannot serialize locator: {}", e.getMessage());
}
// subclass is responsible for validating the id in whatever manner it needs to; most will return null if !UUID.isValid(id) but we don't do it here because a resource might want to allow using something other than uuid as the url key, for example uuid OR hostname for hosts
T item = getRepository().retrieve(locator);
if (item == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
getRepository().delete(locator);
httpServletResponse.setStatus(Status.NO_CONTENT.getStatusCode());
/*
T item = getRepository().retrieve(id); // subclass is responsible for validating the id in whatever manner it needs to; most will return null if !UUID.isValid(id) but we don't do it here because a resource might want to allow using something other than uuid as the url key, for example uuid OR hostname for hosts
if (item == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
getRepository().delete(id);*/
/*
// C collection = getRepository().search(selector);
// if( collection.getDocuments().isEmpty() ) {
// throw new WebApplicationException(Response.Status.NOT_FOUND);
// }
// T item = collection.getDocuments().get(0);
// getRepository().delete(item.getId().toString());
* */
}
Aggregations