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.mycompany.addressbookmvc.validation.RestValidationHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody/*from  w ww.  j a  v a  2 s  . c  o  m*/
public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException ex) {

    BindingResult result = ex.getBindingResult();

    List<FieldError> fieldErrors = result.getFieldErrors();

    ValidationErrorContainer container = new ValidationErrorContainer();

    for (FieldError error : fieldErrors) {

        ValidationError valError = new ValidationError();
        valError.setFieldName(error.getField());
        valError.setMessage(error.getDefaultMessage());

        container.AddError(valError);

    }

    return container;

}

From source file:org.cloudfoundry.identity.uaa.scim.exception.InvalidScimResourceException.java

/**
 * @param message a message for the caller
 */
public InvalidScimResourceException(String message) {
    super(message, HttpStatus.BAD_REQUEST);
}

From source file:com.mycompany.springboot.handler.MethodArgumentNotValidExceptionHandler.java

@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MethodArgumentNotValidException.class)
public Map<String, Object> handler(MethodArgumentNotValidException ex) {
    //        Map<String, Object> map = new HashMap<>();
    //        List<Object> list = new ArrayList<>();
    ///* w  ww .  j a  v  a 2 s .  com*/
    //        for (FieldError error : ex.getBindingResult().getFieldErrors()) {
    //            Map<String, Object> mapError = new HashMap<>();
    //            mapError.put("field", error.getField());
    //            mapError.put("message", error.getDefaultMessage());
    //            list.add(mapError);
    //        }
    //        map.put("errors", list);
    //        return map;

    //        Map<String,Object> map = new HashMap<>();
    //        map.put("error_id","1");
    //        map.put("error", ex.getBindingResult().getFieldError().getDefaultMessage());
    //        return map;

    Map<String, Object> map = new HashMap<>();
    List<Object> list = new ArrayList<>();

    ex.getBindingResult().getFieldErrors().stream().map((error) -> {
        Map<String, Object> mapError = new HashMap<>();
        mapError.put("field", error.getField());
        mapError.put("message", error.getDefaultMessage());
        return mapError;
    }).forEach((mapError) -> {
        list.add(mapError);
    });

    map.put("errors", list);
    return map;
}

From source file:com.thesoftwareguild.flightmaster.validation.RestValidaitonHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody//from  w ww.j a v  a2s .co  m
public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) {

    BindingResult result = e.getBindingResult();

    List<FieldError> fieldErrors = result.getFieldErrors();

    ValidationErrorContainer errors = new ValidationErrorContainer();

    for (FieldError currentError : fieldErrors) {
        errors.addValidationError(currentError.getField(), currentError.getDefaultMessage());
    }

    return errors;

}

From source file:com.tsguild.dolphinblog.controller.RestValidationHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseBody/*w ww  .  j  a  v a  2  s .  c  om*/
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ValidationErrorContainer processValidationErrors(MethodArgumentNotValidException e) {
    BindingResult result = e.getBindingResult();
    List<FieldError> fieldErrors = result.getFieldErrors();

    ValidationErrorContainer errors = new ValidationErrorContainer();
    for (FieldError fError : fieldErrors) {
        errors.addValidationError(fError.getField(), fError.getDefaultMessage());
    }

    return errors;
}

From source file:org.oncoblocks.centromere.web.exceptions.RequestFailureException.java

public RequestFailureException(Integer code, String message, String developerMessage, String moreInfoUrl) {
    super(HttpStatus.BAD_REQUEST, code, message, developerMessage, moreInfoUrl);
}

From source file:th.co.geniustree.dental.controller.ValidationExceptionHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody/*  w  w  w . j a  v a2  s.c  om*/
public Map<String, Object> handleValidation(MethodArgumentNotValidException ex) {
    Map<String, Object> error = new HashMap<>();
    error.put("type", "validation");
    error.put("violations", extractError(ex));
    return error;
}

From source file:org.oncoblocks.centromere.web.exceptions.InvalidParameterException.java

public InvalidParameterException(String message) {
    super(HttpStatus.BAD_REQUEST, 40001, message, "", "");
}

From source file:de.tobiasbruns.fs20.sender.ExceptionController.java

@ExceptionHandler(value = CommandErrorException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public String handleCommandErrorException(CommandErrorException e) {
    return e.getMessage();
}

From source file:com.example.session.app.account.IllegalOperationExceptionHandler.java

@ExceptionHandler({ IllegalOperationException.class })
@ResponseStatus(HttpStatus.BAD_REQUEST)
ModelAndView handleOrderException(IllegalOperationException e) {
    return new ModelAndView("common/error/illegalOperationError").addObject(e.getResultMessages());
}