Search in sources :

Example 6 with DELETE

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);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ZError(org.apache.zookeeper.server.jersey.jaxb.ZError) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 7 with DELETE

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 };
                    }
                }
            });
        }
    })));
}
Also used : Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) AuthConfig(io.druid.server.security.AuthConfig) Method(java.lang.reflect.Method) Predicate(com.google.common.base.Predicate) Binder(com.google.inject.Binder) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) Function(com.google.common.base.Function) ResourceFilter(com.sun.jersey.spi.container.ResourceFilter) DELETE(javax.ws.rs.DELETE) Injector(com.google.inject.Injector) GET(javax.ws.rs.GET) Collection(java.util.Collection) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Module(com.google.inject.Module) Key(com.google.inject.Key)

Example 8 with DELETE

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);
}
Also used : FolderEntry(org.eclipse.che.api.project.server.FolderEntry) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 9 with DELETE

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());
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) IOException(java.io.IOException) Subject(org.eclipse.che.commons.subject.Subject) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 10 with DELETE

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());
* */
}
Also used : GET(javax.ws.rs.GET) POST(javax.ws.rs.POST) PUT(javax.ws.rs.PUT) WebApplicationException(javax.ws.rs.WebApplicationException) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

DELETE (javax.ws.rs.DELETE)202 Path (javax.ws.rs.Path)186 ApiOperation (io.swagger.annotations.ApiOperation)59 ApiResponses (io.swagger.annotations.ApiResponses)48 Produces (javax.ws.rs.Produces)43 Timed (com.codahale.metrics.annotation.Timed)31 AuditEvent (org.graylog2.audit.jersey.AuditEvent)25 IOException (java.io.IOException)20 Response (javax.ws.rs.core.Response)20 WebApplicationException (javax.ws.rs.WebApplicationException)17 HashMap (java.util.HashMap)15 NotFoundException (javax.ws.rs.NotFoundException)15 RestException (com.yahoo.pulsar.broker.web.RestException)12 Consumes (javax.ws.rs.Consumes)12 KeeperException (org.apache.zookeeper.KeeperException)12 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)11 ApiResponse (io.swagger.annotations.ApiResponse)11 NamespaceId (co.cask.cdap.proto.id.NamespaceId)9 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)9 Event (keywhiz.log.Event)9