Example usage for org.springframework.http HttpStatus NO_CONTENT

List of usage examples for org.springframework.http HttpStatus NO_CONTENT

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus NO_CONTENT.

Prototype

HttpStatus NO_CONTENT

To view the source code for org.springframework.http HttpStatus NO_CONTENT.

Click Source Link

Document

204 No Content .

Usage

From source file:com.tsg.addressbookmvc.RESTController.java

@RequestMapping(value = "/address/{id}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateAddress(@PathVariable("id") int id, @Valid @RequestBody Address address) {
    // set the value of the PathVariable id on the incoming Address object
    // to ensure that a) the address id is set on the object and b) that
    // the value of the PathVariable id and the Address object id are the
    // same./*from w  w w . j  av a2 s.  c  o m*/
    address.setAddressId(id);
    // update the address
    dao.updateAddress(address);

}

From source file:com.insys.cfclient.nozzle.InfluxDBSender.java

@Async
public void sendBatch(List<String> messages) {
    log.debug("ENTER sendBatch");
    httpClient.setErrorHandler(new ResponseErrorHandler() {
        @Override//from   w w w .java  2 s .  com
        public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
            return clientHttpResponse.getRawStatusCode() > 399;
        }

        @Override
        public void handleError(ClientHttpResponse clientHttpResponse) throws IOException {

        }
    });

    RetryTemplate retryable = new RetryTemplate();
    retryable.setBackOffPolicy(getBackOffPolicy());
    retryable.setRetryPolicy(new SimpleRetryPolicy(properties.getMaxRetries(),
            Collections.singletonMap(ResourceAccessException.class, true)));

    final AtomicInteger counter = new AtomicInteger(0);
    retryable.execute(retryContext -> {
        int count = counter.incrementAndGet();
        log.trace("Attempt {} to deliver this batch", count);
        final StringBuilder builder = new StringBuilder();
        messages.forEach(s -> builder.append(s).append("\n"));

        String body = builder.toString();

        RequestEntity<String> entity = new RequestEntity<>(body, HttpMethod.POST, getUri());

        ResponseEntity<String> response;

        response = httpClient.exchange(entity, String.class);

        if (response.getStatusCode() != HttpStatus.NO_CONTENT) {
            log.error("Failed to write logs to InfluxDB! Expected error code 204, got {}",
                    response.getStatusCodeValue());

            log.trace("Request Body: {}", body);
            log.trace("Response Body: {}", response.getBody());

        } else {
            log.debug("batch sent successfully!");
        }

        log.debug("EXIT sendBatch");

        return null;
    }, recoveryContext -> {
        log.trace("Failed after {} attempts!", counter.get());
        return null;
    });
}

From source file:com.consol.citrus.samples.javaee.employee.EmployeeResourceTest.java

@Test
@InSequence(4)/*from  w  ww .  j a  va  2s .co  m*/
@CitrusTest
public void testDelete(@CitrusResource TestDesigner citrus) {
    citrus.http().client(serviceUri).send().delete("/Leonard");

    citrus.http().client(serviceUri).receive().response(HttpStatus.NO_CONTENT);

    citrus.http().client(serviceUri).send().get().accept(MediaType.APPLICATION_XML);

    citrus.http().client(serviceUri).receive().response(HttpStatus.OK)
            .payload("<employees>" + "<employee>" + "<age>20</age>" + "<name>Penny</name>" + "</employee>"
                    + "<employee>" + "<age>22</age>" + "<name>Sheldon</name>" + "</employee>" + "<employee>"
                    + "<age>21</age>" + "<name>Howard</name>" + "<email>howard@example.com</email>"
                    + "</employee>" + "</employees>");

    citrusFramework.run(citrus.getTestCase());
}

From source file:com.tsguild.upsproject.controller.HomeController.java

@ResponseStatus(HttpStatus.NO_CONTENT)
@RequestMapping(value = "/package/{packageId}", method = RequestMethod.DELETE)
public void removePackage(@PathVariable("packageId") String packageId) {
    dao.removeBox(packageId);//from w  w w.  j a va 2  s . c  o m
}

From source file:com.jiwhiz.rest.author.AuthorBlogRestController.java

@RequestMapping(method = RequestMethod.PUT, value = URL_AUTHOR_BLOGS_BLOG)
@Transactional//from  ww  w.j  av  a2 s  .  co m
public HttpEntity<Void> updateBlogPost(@PathVariable("blogId") String blogId,
        @RequestBody BlogPostForm blogPostForm) throws ResourceNotFoundException {
    BlogPost blogPost = getBlogByIdAndCheckAuthor(blogId);
    blogPost.setContent(blogPostForm.getContent());
    blogPost.setTitle(blogPostForm.getTitle());
    blogPost.parseAndSetTagString(blogPostForm.getTagString());
    blogPost = blogPostRepository.save(blogPost);

    AuthorBlogResource resource = authorBlogResourceAssembler.toResource(blogPost);
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setLocation(URI.create(resource.getLink("self").getHref()));

    return new ResponseEntity<Void>(httpHeaders, HttpStatus.NO_CONTENT);
}

From source file:com.netflix.genie.web.controllers.ApplicationRestController.java

/**
 * Delete all applications from database.
 *
 * @throws GenieException For any error/*  w  ww  .j  a v  a 2s.c  o  m*/
 */
@DeleteMapping
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteAllApplications() throws GenieException {
    log.debug("Delete all Applications");
    this.applicationService.deleteAllApplications();
}

From source file:io.syndesis.runtime.BaseITCase.java

protected <T> ResponseEntity<T> delete(String url, Class<T> responseClass) {
    return delete(url, responseClass, tokenRule.validToken(), HttpStatus.NO_CONTENT);
}

From source file:org.nekorp.workflow.backend.controller.imp.ServicioControllerImp.java

@Override
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public void borrarServicio(@PathVariable final Long id, final HttpServletResponse response) {
    Servicio dato = this.servicioDAO.consultar(id);
    if (dato == null) {
        //no hay nada que responder
        response.setStatus(HttpStatus.NO_CONTENT.value());
        return;/*www  .  jav a2 s  .c  o m*/
    }
    //hay que borrar costos y bitacora primero
    this.saveBitacora(id, new LinkedList<Evento>(), response);
    this.saveCosto(id, new LinkedList<RegistroCosto>(), response);
    //se borra servicio y listo
    servicioDAO.borrar(dato);
    //se acepto la peticion de borrado, no quiere decir que sucede de inmediato.
    response.setStatus(HttpStatus.ACCEPTED.value());
}

From source file:nc.noumea.mairie.organigramme.core.ws.BaseWsConsumer.java

public <T> List<T> readResponseAsList(Class<T> targetClass, ClientResponse response, String url) {

    List<T> result = null;//from  ww w .ja va2 s  .  c o  m

    result = new ArrayList<T>();

    if (response.getStatus() == HttpStatus.NO_CONTENT.value()) {
        return result;
    }

    if (response.getStatus() != HttpStatus.OK.value()) {
        throw new WSConsumerException(String.format("An error occured when querying '%s'. Return code is : %s",
                url, response.getStatus()));
    }

    String output = response.getEntity(String.class);

    result = new JSONDeserializer<List<T>>().use(null, ArrayList.class).use(Date.class, new MSDateTransformer())
            .use("values", targetClass).deserialize(output);

    return result;
}

From source file:tv.arte.resteventapi.web.controllers.EventsController.java

/**
 * Deletes an event/*from w  w w  . j  a  v  a2  s.c  o m*/
 * 
 * @param baseEventRequestParam A set of params
 * @return The created evet
 * @throws RestEventApiValidationException 
 */
@RequestMapping(value = { "/{id}" }, produces = {
        RestEventApiMediaType.APPLICATION_VND_API_JSON_VALUE }, method = { RequestMethod.DELETE })
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteEvent(BaseRestEventRequestParam baseEventRequestParam)
        throws RestEventApiValidationException {
    eventService.deleteRestEventForId(baseEventRequestParam.getId());
}