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.nebhale.buildmonitor.web.ControllerUtilsTest.java

@Test
public void handleConstraintViolation() {
    ResponseEntity<Set<String>> responseEntity = this.controllerUtils.handleConstraintViolation(this.exception);

    assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
    assertEquals(1, responseEntity.getBody().size());
}

From source file:com.pw.ism.controllers.CommunicationController.java

@RequestMapping(value = "/newmessage", method = RequestMethod.POST, headers = {
        "Content-type=application/json" })
public ResponseEntity<String> newReport(@Valid @RequestBody AsiNetworkReport report,
        BindingResult bindingResults) {//from  w  ww.  j av a2s  .c o m

    if (bindingResults.hasErrors()) {
        LOGGER.info("JSON not correct, BADREQUEST! Count: {}", bindingResults.getFieldErrorCount());
        return new ResponseEntity<>("NOK!", HttpStatus.BAD_REQUEST);
    } else {
        LOGGER.info("new post for message, customer: {}, network: {}, text: {}, sensor: {}", new Object[] {
                report.getCustomer(), report.getNetwork(), report.getText(), report.getSensor() });
        Message message = new Message(report.getCustomer(), report.getNetwork(),
                "Sensor ID: " + report.getSensor() + " Message: " + report.getText());
        messageRepository.save(message);
        return new ResponseEntity<>("OK", HttpStatus.OK);
    }

}

From source file:com.jwt.exceptions.GlobalExceptionHandler.java

@ExceptionHandler(AccessDeniedException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody// w ww  .  j ava 2  s .c  om
public Map handleAccessDeniedException(AccessDeniedException exception) {

    return error("Access denied, insufficient rights.");
}

From source file:de.knightsoftnet.validators.server.controller.RestErrorHandler.java

/**
 * handle validation errors.//from ww w .j av a2  s.c  o m
 *
 * @param pexception exception which is thrown when data is invalid.
 * @return ValidationResultData with validation errors
 */
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public ValidationResultInterface processValidationError(final MethodArgumentNotValidException pexception) {
    final BindingResult result = pexception.getBindingResult();
    final List<FieldError> fieldErrors = result.getFieldErrors();

    return this.processFieldErrors(fieldErrors);
}

From source file:io.kahu.hawaii.util.exception.ValidationException.java

@Override
public HttpStatus getStatus() {
    return HttpStatus.BAD_REQUEST; // 400
}

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

@CrossOrigin
@RequestMapping(path = "/login", method = RequestMethod.POST)
@ResponseBody/*from w  w w . j  a  v  a  2s . co  m*/
public ResponseEntity<String> login(@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);
    UserAuthDAO userAuthDAO = context.getBean(UserAuthDAO.class);

    User foundUser = userDAO.findByUsernameAndPassword(user.getUsername(), user.getPassword());
    if (foundUser == null) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("bad_credentials"), HttpStatus.BAD_REQUEST);
    }

    TokenGenerator tg = new TokenGenerator();
    Date date = new Date();
    Timestamp timestamp = new Timestamp(date.getTime());

    UserAuth userAuth = new UserAuth();
    userAuth.setIdUser(foundUser.getId());
    userAuth.setToken(tg.getToken());
    userAuth.setCreateDate(timestamp);
    userAuthDAO.create(userAuth);

    context.close();

    return new ResponseEntity(new SuccessLoginResponse(userAuth.getToken()), HttpStatus.OK);
}

From source file:edu.pitt.dbmi.ccd.anno.error.ErrorHandler.java

@ExceptionHandler(PropertyReferenceException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody/* w  w  w .j  a  v a 2  s. c  o  m*/
public ErrorMessage handlePropertyReferenceException(PropertyReferenceException ex, HttpServletRequest req) {
    LOGGER.info(ex.getMessage());
    return new ErrorMessage(HttpStatus.BAD_REQUEST, ex.getMessage(), req);
}

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

@RequestMapping(value = "/cadastrar", headers = "Accept=*/*", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody ResponseEntity<?> adicionarCategoria(Categoria categoria) {
    try {/*from  w w w  . ja  va 2  s. c om*/
        fachada.cadastrar(categoria);
        return new ResponseEntity<String>(HttpStatus.OK);
    } catch (CategoriaExistenteException e) {
        return new ResponseEntity<CategoriaExistenteException>(e, HttpStatus.BAD_REQUEST);
    }
}

From source file:br.com.s2it.snakes.controllers.CarController.java

@CrossOrigin("*")
@RequestMapping(value = "/damage/{licensePlate}", method = RequestMethod.PUT)
public ResponseEntity<Car> doDamage(final @RequestBody List<CarDamage> damage,
        final @PathVariable(value = "licensePlate") String licensePlate) {
    if (licensePlate == null || licensePlate.isEmpty() || damage == null)
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);

    try {//from  www.ja v  a 2  s  .c  o  m
        Car car = service.findByLicensePlate(licensePlate);

        if (car.getDamages() == null)
            car.setDamages(new ArrayList<>());

        car.getDamages().addAll(damage);

        return ResponseEntity.status(HttpStatus.OK).body(service.save(car));
    } catch (Exception e) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
    }
}

From source file:application.controllers.RestController.java

@RequestMapping(value = "/transfer", method = RequestMethod.POST)
public ResponseEntity<?> newTransfer(@RequestBody Transfer transfer) {
    Account sender = myBatisService.getByName(transfer.getSender());
    Account reciever = myBatisService.getByName(transfer.getReciever());
    if (reciever == null || sender == null || transfer.getAmount() <= 0
            || sender.getBalance() < transfer.getAmount()) {
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }//from w  ww.  j av  a2s.c o m
    myBatisService.transferFunds(sender, reciever, transfer);
    return new ResponseEntity<>(HttpStatus.ACCEPTED);
}