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.seabee.snapdragon.validation.RestValidationHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)
// #3: Specify the HTTP Status code to return when an error occurs
@ResponseStatus(HttpStatus.BAD_REQUEST)
// #4: Let Spring know that we have something to return in the body of the
// response. In this case it will be a ValidationErrorContainer containing
// a ValidationError object for each field that did not pass validation.
@ResponseBody/*from ww  w. j a va 2s.c  o m*/
public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) {
    // #5: get the Binding Result and all field errors
    BindingResult result = e.getBindingResult();
    List<FieldError> fieldErrors = result.getFieldErrors();

    // #6: Create a new ValidationError for each fieldError in the Binding Result
    ValidationErrorContainer errors = new ValidationErrorContainer();
    for (FieldError currentError : fieldErrors) {
        errors.addValidationError(currentError.getField(), currentError.getDefaultMessage());
    }
    return errors;
}

From source file:com.mycompany.contactlistmvc.validation.RestValidationHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)

// #3: Specify the Http Status code to return when an error occurs 
@ResponseStatus(HttpStatus.BAD_REQUEST)

// #4: Let Spring know that we have something to return in the body of the
//     response.  In this case it will be a ValidationErrorContainer containing
// a ValidationError object for each field that did not pass validation. 
@ResponseBody/*w  w w.  j  a v a 2  s. co  m*/
public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) {
    // #5: get the Binding Result and all field errors 
    BindingResult result = e.getBindingResult();
    List<FieldError> fieldErrors = result.getFieldErrors();

    // #6: Create a new ValidationError for each fieldError in the Binding Result
    ValidationErrorContainer errors = new ValidationErrorContainer();
    for (FieldError currentError : fieldErrors) {
        errors.addValidationError(currentError.getField(), currentError.getDefaultMessage());
    }
    return errors;
}

From source file:io.fabric8.che.starter.exception.GlobalExceptionHandler.java

@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "MasterUrl is not valid")
@ExceptionHandler(UnknownHostException.class)
public String handleHostException(UnknownHostException e) {
    return e.getMessage();
}

From source file:com.tsg.addressbookmvc.validation.RESTValidationHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)
// #3: Specify the HTTP Status code to return when an error occurs 
@ResponseStatus(HttpStatus.BAD_REQUEST)
// #4: Let Spring know that we have something to return in the body of the
// response. In this case it will be a ValidationErrorContainer containing
// a ValidationError object for each field that did not pass validation. 
@ResponseBody//from   w w w. java  2  s . c  o m
public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) {
    // #5: get the Binding Result and all field errors 
    BindingResult result = e.getBindingResult();
    List<FieldError> fieldErrors = result.getFieldErrors();

    // #6: Create a new ValidationError for each fieldError in the Binding Result 
    ValidationErrorContainer errors = new ValidationErrorContainer();
    for (FieldError currentError : fieldErrors) {
        errors.addValidationError(currentError.getField(), currentError.getDefaultMessage());

    }
    return errors;
}

From source file:com.nebhale.devoxx2013.web.ErrorHandling.java

@ExceptionHandler(IllegalStateException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
void illegalStateException() {
}

From source file:com.swcguild.vendingmachinemvc.validation.RestValidationHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)
// #3: Specify the Http Status code to return when an error occurs
@ResponseStatus(HttpStatus.BAD_REQUEST)
// #4: Let Spring know that we have something to return in the body of the
// response. In this case it will be a ValidationErrorContainer containing
// a ValidationError object for each field that did not pass validation.
@ResponseBody/*  ww  w .  j  a v  a 2 s  .c  o  m*/
public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) {
    // #5: get the Binding Result and all field errors
    BindingResult result = e.getBindingResult();
    List<FieldError> fieldErrors = result.getFieldErrors();

    // #6: Create a new ValidationError for each fieldError in the Binding Result
    ValidationErrorContainer errors = new ValidationErrorContainer();
    for (FieldError currentError : fieldErrors) {
        errors.addValidationError(currentError.getField(), currentError.getDefaultMessage());
    }
    return errors;
}

From source file:com.swcguild.capstoneproject.validation.RestValidationHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)

// #3: Specify the Http Status code to return when an error occurs
@ResponseStatus(HttpStatus.BAD_REQUEST)

// #4: Let Spring know that we have something to return in the body of the
// response. In this case it will be a ValidationErrorContainer containing
// a ValidationError object for each field that did not pass validation.
@ResponseBody/*w  ww . j  av  a  2 s. c o  m*/
public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) {
    // #5: get the Binding Result and all field errors
    BindingResult result = e.getBindingResult();
    List<FieldError> fieldErrors = result.getFieldErrors();

    // #6: Create a new ValidationError for each fieldError in the Binding Result
    ValidationErrorContainer errors = new ValidationErrorContainer();
    for (FieldError currentError : fieldErrors) {
        errors.addValidationError(currentError.getField(), currentError.getDefaultMessage());
    }
    return errors;
}

From source file:de.hska.ld.core.exception.ValidationException.java

public ValidationException(String field) {
    super(field, "INVALID");
    httpStatus = HttpStatus.BAD_REQUEST;
}

From source file:com.appglu.AppGluHttpIncompatibleClientVersionException.java

public AppGluHttpIncompatibleClientVersionException(Error error) {
    super(HttpStatus.BAD_REQUEST.value(), error);
}

From source file:com.example.notes.RestNotesControllerAdvice.java

@ExceptionHandler(IllegalArgumentException.class)
public void handleIllegalArgumentException(IllegalArgumentException ex, HttpServletResponse response)
        throws IOException {
    response.sendError(HttpStatus.BAD_REQUEST.value(), ex.getMessage());
}