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:org.venice.piazza.servicecontroller.messaging.handlers.SearchServiceHandlerTest.java

/**
 * Test Null Criteria/* w  ww.  j  a v a 2s.  c om*/
 */
@Test
public void testNullCriteria() {
    SearchCriteria criteria = null;

    ResponseEntity<String> responseEntity = new ResponseEntity<String>("No criteria was specified",
            HttpStatus.NO_CONTENT);
    Mockito.doReturn(services).when(accessorMock).search(criteria);

    ResponseEntity<String> result = ssHandler.handle(criteria);

    assertEquals("The response code is correct", responseEntity.getStatusCode(), HttpStatus.NO_CONTENT);
    assertEquals("The body of the response is correct", responseEntity.getBody(), result.getBody());

}

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

@Override
@RequestMapping(value = "/{idRegistro}", method = RequestMethod.DELETE)
public void borrarRegistro(@PathVariable final Long idServicio, @PathVariable final Long idRegistro,
        final HttpServletResponse response) {
    if (!idServicioValido(idServicio)) {
        response.setStatus(HttpStatus.NOT_FOUND.value());
        return;/*from   w ww.j ava 2s .c o  m*/
    }
    RegistroCosto dato = registroCostoDAO.consultar(idServicio, idRegistro);
    if (dato == null) {
        //no hay nada que responder
        response.setStatus(HttpStatus.NO_CONTENT.value());
        return;
    }
    registroCostoDAO.borrar(idServicio, 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 byte[] readResponseWithFile(ClientResponse response, String url) {

    if (response.getStatus() == HttpStatus.NO_CONTENT.value()) {
        return null;
    }/*from w ww.ja v  a  2  s. c om*/

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

    return response.getEntity(byte[].class);
}

From source file:org.bozzo.ipplan.web.RangeController.java

@RequestMapping(value = "/{rangeId}", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteRange(@PathVariable Integer infraId, @PathVariable Long zoneId, @PathVariable Long rangeId) {
    logger.info("delete range with id: {} (infra id: {}, zone id: {})", rangeId, infraId, zoneId);
    this.repository.deleteByInfraIdAndZoneIdAndId(infraId, zoneId, rangeId);
}

From source file:com.expedia.seiso.web.controller.v2.ItemControllerV2.java

/**
 * Handles HTTP PUT requests against top-level resources. Following HTTP semantics, this creates the resource if it
 * doesn't already exist; otherwise, it completely replaces the existing resource (as opposed to merging it). With
 * respect to the latter, null and missing fields in the incoming representation map to null fields in the
 * persistent resource./*w ww  . j av  a  2  s .com*/
 * 
 * @param repoKey
 *            Repository key
 * @param itemKey
 *            Item key
 * @param peResource
 *            Item to save
 */
@RequestMapping(value = "/{repoKey}/{itemKey}", method = RequestMethod.PUT, consumes = MediaTypes.APPLICATION_HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void put(@PathVariable String repoKey, @PathVariable String itemKey, PEResource peResource) {
    // mergeAssociations = false because v2 treats associations as separate resources, and merging associations
    // would null out the current item's associations.
    delegate.put(peResource.getItem(), false);
}

From source file:com.wisemapping.rest.AdminController.java

@ApiOperation("Note: Administration permissions required.")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
@RequestMapping(method = RequestMethod.GET, value = "admin/database/purge")
public void purgeDB(@RequestParam(required = true) Integer minUid,
        @RequestParam(required = true) Integer maxUid, @RequestParam(required = true) Boolean apply)
        throws WiseMappingException, UnsupportedEncodingException {

    for (int i = minUid; i < maxUid; i++) {

        try {//  w w w.  j  a v a  2 s  .  com
            System.out.println("Looking for user:" + i);
            final User user = userService.getUserBy(i);
            if (user != null) {
                // Do not process admin accounts ...
                if (user.getEmail().contains("wisemapping")) {
                    continue;
                }
                // Iterate over the list of maps ...
                final List<Collaboration> collaborations = mindmapService.findCollaborations(user);
                for (Collaboration collaboration : collaborations) {
                    final Mindmap mindmap = collaboration.getMindMap();
                    if (MindmapFilter.MY_MAPS.accept(mindmap, user)) {

                        final Calendar yearAgo = Calendar.getInstance();
                        yearAgo.add(Calendar.MONTH, -4);

                        // The use has only two maps... When they have been modified ..
                        System.out.println("Checking map id:" + mindmap.getId());
                        if (mindmap.getLastModificationTime().before(yearAgo) && !mindmap.isPublic()) {
                            System.out.println("Old map months map:" + mindmap.getId());

                            if (isWelcomeMap(mindmap) || isSimpleMap(mindmap)) {
                                System.out.println(
                                        "Purged map id:" + mindmap.getId() + ", userId:" + user.getId());
                                if (apply) {
                                    mindmapService.removeMindmap(mindmap, user);
                                }
                            }
                        }

                        // Purge history ...
                        mindmapService.purgeHistory(mindmap.getId());
                    }
                }
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (WiseMappingException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (RuntimeException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
    }
}

From source file:eu.freme.broker.integration_tests.UserControllerTest.java

@Test
public void testUserSecurity() throws UnirestException {

    String username = "myuser";
    String password = "mypassword";

    logger.info("create user");
    logger.info(baseUrl + "/user");
    HttpResponse<String> response = Unirest.post(baseUrl + "/user").queryString("username", username)
            .queryString("password", password).asString();
    assertTrue(response.getStatus() == HttpStatus.OK.value());
    String responseUsername = new JSONObject(response.getBody()).getString("name");
    assertTrue(username.equals(responseUsername));

    logger.info("create user with dublicate username - should not work, exception is ok");
    loggerIgnore("eu.freme.broker.exception.BadRequestException");
    response = Unirest.post(baseUrl + "/user").queryString("username", username)
            .queryString("password", password).asString();
    assertTrue(response.getStatus() == HttpStatus.BAD_REQUEST.value());
    loggerUnignore("eu.freme.broker.exception.BadRequestException");

    logger.info("create users with invalid usernames - should not work");
    loggerIgnore("eu.freme.broker.exception.BadRequestException");
    response = Unirest.post(baseUrl + "/user").queryString("username", "123").queryString("password", password)
            .asString();//  w ww.j  a va 2 s  . c  o m
    assertTrue(response.getStatus() == HttpStatus.BAD_REQUEST.value());

    response = Unirest.post(baseUrl + "/user").queryString("username", "*abc").queryString("password", password)
            .asString();
    assertTrue(response.getStatus() == HttpStatus.BAD_REQUEST.value());

    response = Unirest.post(baseUrl + "/user").queryString("username", adminUsername)
            .queryString("password", password).asString();
    assertTrue(response.getStatus() == HttpStatus.BAD_REQUEST.value());

    response = Unirest.post(baseUrl + "/user").queryString("username", "").queryString("password", password)
            .asString();
    assertTrue(response.getStatus() == HttpStatus.BAD_REQUEST.value());
    loggerUnignore("eu.freme.broker.exception.BadRequestException");

    logger.info("login with bad password should fail");
    loggerIgnore(accessDeniedExceptions);
    response = Unirest.post(baseUrl + BaseRestController.authenticationEndpoint)
            .header("X-Auth-Username", username).header("X-Auth-Password", password + "xyz").asString();
    assertTrue(response.getStatus() == HttpStatus.UNAUTHORIZED.value());
    loggerUnignore(accessDeniedExceptions);

    logger.info("login with new user / create token");
    response = Unirest.post(baseUrl + BaseRestController.authenticationEndpoint)
            .header("X-Auth-Username", username).header("X-Auth-Password", password).asString();
    assertTrue(response.getStatus() == HttpStatus.OK.value());
    String token = new JSONObject(response.getBody()).getString("token");
    assertTrue(token != null);
    assertTrue(token.length() > 0);

    logger.info("delete user without providing credentials - should fail, exception is ok");
    loggerIgnore(accessDeniedExceptions);
    response = Unirest.delete(baseUrl + "/user/" + username).asString();
    assertTrue(response.getStatus() == HttpStatus.UNAUTHORIZED.value());
    loggerUnignore(accessDeniedExceptions);

    logger.info("create a 2nd user");
    String otherUsername = "otheruser";
    response = Unirest.post(baseUrl + "/user").queryString("username", otherUsername)
            .queryString("password", password).asString();
    assertTrue(response.getStatus() == HttpStatus.OK.value());
    String responseOtherUsername = new JSONObject(response.getBody()).getString("name");
    assertTrue(otherUsername.equals(responseOtherUsername));

    logger.info("delete other user should fail");
    loggerIgnore(accessDeniedExceptions);
    response = Unirest.delete(baseUrl + "/user/" + otherUsername).header("X-Auth-Token", token).asString();
    assertTrue(response.getStatus() == HttpStatus.UNAUTHORIZED.value());
    loggerUnignore(accessDeniedExceptions);

    logger.info("cannot do authenticated call with username / password, only token should work");
    loggerIgnore(accessDeniedExceptions);
    response = Unirest.delete(baseUrl + "/user/" + username).header("X-Auth-Username", username)
            .header("X-Auth-Password", password).asString();
    assertTrue(response.getStatus() == HttpStatus.UNAUTHORIZED.value());
    loggerUnignore(accessDeniedExceptions);

    logger.info("get user information");
    response = Unirest.get(baseUrl + "/user/" + username).header("X-Auth-Token", token).asString();
    assertTrue(response.getStatus() == HttpStatus.OK.value());
    responseUsername = new JSONObject(response.getBody()).getString("name");
    assertTrue(responseUsername.equals(username));

    logger.info("delete own user - should work");
    response = Unirest.delete(baseUrl + "/user/" + username).header("X-Auth-Token", token).asString();
    assertTrue(response.getStatus() == HttpStatus.NO_CONTENT.value());

}

From source file:com.javiermoreno.springboot.mvc.users.UserCtrl.java

/**
 * Deletes an user.//from w  ww.j a  va 2  s .c o m
 * @param emailOrId identified by looking for an "@". 
 */
@RequestMapping(value = "/{emailOrId}", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation(value = "DELETE /users/{emailOrId}", notes = "204 no content if ok, 404 if not found.")
ResponseEntity deleteUser(@PathVariable String emailOrId) {
    try {
        DailyUser user;
        if (emailOrId.contains("@") == true) {
            int affected = userRepository.deleteByEmail(emailOrId);
        } else {
            int id = Integer.parseInt(emailOrId);
            userRepository.delete(id);
        }
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    } catch (EmptyResultDataAccessException ex) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}

From source file:de.thm.arsnova.controller.LecturerQuestionController.java

@RequestMapping(value = "/", method = RequestMethod.GET)
public List<Question> getSkillQuestions(@RequestParam final String sessionkey,
        @RequestParam(value = "lecturequestionsonly", defaultValue = "false") final boolean lectureQuestionsOnly,
        @RequestParam(value = "flashcardsonly", defaultValue = "false") final boolean flashcardsOnly,
        @RequestParam(value = "preparationquestionsonly", defaultValue = "false") final boolean preparationQuestionsOnly,
        final HttpServletResponse response) {
    List<Question> questions;
    if (lectureQuestionsOnly) {
        questions = questionService.getLectureQuestions(sessionkey);
    } else if (flashcardsOnly) {
        questions = questionService.getFlashcards(sessionkey);
    } else if (preparationQuestionsOnly) {
        questions = questionService.getPreparationQuestions(sessionkey);
    } else {//  w  ww .j  a  va 2  s  .c  om
        questions = questionService.getSkillQuestions(sessionkey);
    }
    if (questions == null || questions.isEmpty()) {
        response.setStatus(HttpStatus.NO_CONTENT.value());
        return null;
    }
    return questions;
}

From source file:org.openbaton.nfvo.api.RestNetworkServiceRecord.java

/**
 * Removes multiple Network Service Descriptor from the NSDescriptors repository
 *
 * @param ids: the id list of Network Service Descriptors
 * @throws NotFoundException//from  w  w w.  j av a  2s  .  c  om
 * @throws InterruptedException
 * @throws ExecutionException
 * @throws WrongStatusException
 * @throws VimException
 */
@RequestMapping(value = "/multipledelete", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void multipleDelete(@RequestBody @Valid List<String> ids,
        @RequestHeader(value = "project-id") String projectId)
        throws InterruptedException, ExecutionException, WrongStatusException, VimException, NotFoundException {
    for (String id : ids) {
        networkServiceRecordManagement.delete(id, projectId);
    }
}