Example usage for org.springframework.http HttpStatus BAD_REQUEST

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

Introduction

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

Prototype

HttpStatus BAD_REQUEST

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

Click Source Link

Document

400 Bad Request .

Usage

From source file:com.infinity.controller.ExpController.java

@RequestMapping(value = { "/exp/del/{expId}" }, method = RequestMethod.GET, produces = "application/json")
public ResponseEntity delExpbyId(@PathVariable String expId) throws IOException {

    ResponseEntity<String> responseEntity = null;
    try {//  ww w. ja  va2 s.c  om
        expService.deleteById(expId);
        responseEntity = new ResponseEntity<>("OK ", HttpStatus.OK);
    } catch (Exception e) {
        LOG.error(e.getMessage());
        responseEntity = new ResponseEntity<>("error ", HttpStatus.BAD_REQUEST);
    }
    return responseEntity;
}

From source file:com.mycompany.projetsportmanager.spring.rest.exceptions.SportManagerResponseEntityExceptionHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody//from   w  w w. j  a v a 2 s  .  com
public ErrorListResource processValidationError(MethodArgumentNotValidException ex) {
    List<ValidationErrorResource> validationErrorResources = errorListsMapper.mapEntityIterableToBeanList(
            dozerBeanMapper, ex.getBindingResult().getFieldErrors(), ValidationErrorResource.class);
    return new ErrorListResource(validationErrorResources, HttpStatus.BAD_REQUEST);
}

From source file:org.ff4j.spring.boot.exceptions.FF4jExceptionHandler.java

@ExceptionHandler(value = FeatureIdNotMatchException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "feature uid did not match with the requested feature uid to be created or updated")
public void featureIdNotMatchException() {
    // Not necessary to handle this exception
}

From source file:se.sawano.scala.examples.scalaspringmvc.ValidationTestIT.java

@Test
public void javaPostWithInvalidAge() {
    try {/*from  w  w  w  .j a v a 2  s  . c  o m*/
        JavaIndata indata = new JavaIndata("Daniel", -1);
        restTemplate.postForObject(baseUrl + "java/indata", indata, Void.class, (Object) null);
        fail("Expected JSR-303 validation to fail");
    } catch (HttpClientErrorException e) {
        assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
    }
}

From source file:reconf.server.services.security.DeleteUserService.java

@RequestMapping(value = "/user/{user}", method = RequestMethod.DELETE)
@Transactional/*from w  ww .  jav  a 2 s .co m*/
public ResponseEntity<Client> doIt(@PathVariable("user") String user, Authentication authentication) {

    if (ApplicationSecurity.isRoot(user)) {
        return new ResponseEntity<Client>(new Client(user, cannotDeleteRoot), HttpStatus.BAD_REQUEST);
    }

    if (!userDetailsManager.userExists(user)) {
        return new ResponseEntity<Client>(new Client(user, userNotFound), HttpStatus.NOT_FOUND);
    }

    userProducts.deleteByKeyUsername(user);
    userDetailsManager.deleteUser(user);
    return new ResponseEntity<Client>(HttpStatus.OK);
}

From source file:com._8x8.presentation.restfulController.GCMRestController.java

@RequestMapping(value = "/gcm/{id}/update", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> updateGCMById(@PathVariable("id") String id, @RequestBody GCM gcm,
        UriComponentsBuilder ucBuilder) {

    try {//from   w ww . j  a va 2  s.  c  o m
        _gcmService.UpdateGCMById(gcm);
        return new ResponseEntity<String>("{'status': 'success'}", HttpStatus.OK);
    } catch (Exception ex) {
        return new ResponseEntity<String>(HttpStatus.BAD_REQUEST);
    }

}

From source file:br.upe.community.ui.ControllerDoacao.java

@RequestMapping(value = "/cadastrar", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody ResponseEntity<?> cadastrarDoacao(Doacao doacao, Produto produto, String emailUsuario,
        String nomeCategoria) {/*from   w w  w .ja  v  a  2  s.c o  m*/
    try {
        fachada.cadastrarDoacao(doacao, produto, emailUsuario, nomeCategoria);
        return new ResponseEntity<String>(HttpStatus.OK);
    } catch (UsuarioInexistenteException e) {
        return new ResponseEntity<UsuarioInexistenteException>(e, HttpStatus.BAD_REQUEST);
    } catch (CategoriaInexistenteException ex) {
        return new ResponseEntity<CategoriaInexistenteException>(ex, HttpStatus.BAD_REQUEST);

    }
}

From source file:com.example.api.UrlShortener.java

@RequestMapping(value = "/", method = RequestMethod.POST)
ResponseEntity<String> save(@RequestParam String url) {
    if (validator.isValid(url)) {
        String hash = getHash(url);
        String shorten = new StringBuilder(urlShortenerUrl).append('/').append(hash).toString();
        return new ResponseEntity<>(shorten, HttpStatus.OK);
    } else {/* www .  j  ava 2s. c o  m*/
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

From source file:com.chevres.rss.restapi.controller.RegisterController.java

@CrossOrigin
@RequestMapping(path = "/register", method = RequestMethod.POST)
@ResponseBody//from  ww  w.j  a v  a2  s.  com
public HttpEntity<String> register(@RequestBody User user, BindingResult bindingResult) {

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

    userValidator.validate(user, bindingResult);

    if (bindingResult.hasErrors()) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("bad_params"), HttpStatus.BAD_REQUEST);
    }

    UserDAO userDAO = context.getBean(UserDAO.class);

    if (userDAO.doesExist(user.getUsername())) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("already_exist"), HttpStatus.BAD_REQUEST);
    }

    PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    String hashedPassword = passwordEncoder.encode(user.getPassword());
    user.setPassword(hashedPassword);
    user.setType(User.USER_TYPE_LABEL);
    userDAO.create(user);

    context.close();

    return new ResponseEntity(new SuccessMessageResponse("success"), HttpStatus.OK);
}

From source file:reconf.server.services.component.UpsertComponentService.java

@RequestMapping(value = "/product/{prod}/component/{comp}", method = RequestMethod.PUT)
@Transactional//from  w w w .  j  a v  a  2 s  .c o  m
public ResponseEntity<ComponentResult> doIt(@PathVariable("prod") String productId,
        @PathVariable("comp") String componentId,
        @RequestParam(value = "desc", required = false) String description, HttpServletRequest request,
        Authentication auth) {

    ComponentKey key = new ComponentKey(productId, componentId);
    Component reqComponent = new Component(key, description);

    List<String> errors = DomainValidator.checkForErrors(key);
    if (!errors.isEmpty()) {
        return new ResponseEntity<ComponentResult>(new ComponentResult(reqComponent, errors),
                HttpStatus.BAD_REQUEST);
    }

    Product product = products.findOne(key.getProduct());
    if (product == null) {
        return new ResponseEntity<ComponentResult>(new ComponentResult(reqComponent, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }
    HttpStatus status = null;
    Component dbComponent = components.findOne(key);
    if (dbComponent == null) {
        dbComponent = new Component(key, description);
        components.save(dbComponent);
        status = HttpStatus.CREATED;

    } else {
        dbComponent.setDescription(description);
        status = HttpStatus.OK;
    }
    return new ResponseEntity<ComponentResult>(
            new ComponentResult(dbComponent, CrudServiceUtils.getBaseUrl(request)), status);
}