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.ogaclejapan.dotapk.WebApiException.java

public static WebApiException asBadRequest(String message) {
    return new WebApiException(HttpStatus.BAD_REQUEST, message);
}

From source file:es.fdi.reservas.reserva.web.ExceptionHandlerController.java

@ExceptionHandler(ReservaSolapadaException.class)
@ResponseBody/*from   www  .j  ava 2  s . c  o m*/
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorResult reservaSolapadaException(HttpServletRequest request, HttpServletResponse response,
        Exception e) throws IOException {

    return new ErrorResult(HttpStatus.BAD_REQUEST.value(), e.getMessage());
}

From source file:com.citibanamex.api.locator.atm.exceptions.GlobalExceptionHandler.java

/**
 * This method is to handle BadRequestException category
 * /* ww w .j a va 2s  .  co m*/
 * @param BadRequestException
 * @return Response
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(value = BadRequestException.class)
public ResponseEntity<?> handleBadRequestException(BadRequestException ex) {
    Response respObj = new Response();
    respObj.setTimeStamp(new Date().getTime());
    respObj.setStatus("FAILURE");
    respObj.setErrorCode(HttpStatus.BAD_REQUEST.value());
    respObj.setMessage("Bad Request");
    respObj.setDescription("Invalid 'radius' or/and 'address' parameters");
    logger.info("Http response -" + respObj.getErrorCode() + "-" + respObj.getDescription() + "-"
            + respObj.getMessage());
    return new ResponseEntity<Response>(respObj, HttpStatus.BAD_REQUEST);
}

From source file:com.hrofirst.exception.handler.DefaultExceptionHandler.java

/**
 * handle for  Exception/* w w w  .j av a2  s  .  c  o  m*/
 */
@ExceptionHandler({ Exception.class })
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ModelAndView processException(HttpServletRequest request, Exception e, HttpServletResponse response)
        throws IOException {
    //TODO
    return new ModelAndView();
}

From source file:org.sharetask.controller.handler.MethodConstraintViolationExceptionHandler.java

@ExceptionHandler
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody//from  w  ww  .ja  v  a 2s  .c  o m
public ValidationError handlException(final MethodConstraintViolationException error) {
    final ValidationError validationError = new ValidationError();
    final Set<MethodConstraintViolation<?>> violations = error.getConstraintViolations();
    for (final MethodConstraintViolation<?> methodConstraintViolation : violations) {
        final String path = methodConstraintViolation.getPropertyPath().toString();
        final String template = methodConstraintViolation.getMessageTemplate();
        validationError.addError(path, template);
    }
    return validationError;
}

From source file:io.getlime.security.powerauth.app.server.service.controller.RESTControllerAdvice.java

/**
 * Handle all service exceptions using the same error format. Response has a status code 400 Bad Request.
 *
 * @param e   Service exception.//w w w  .j  a v  a 2s  .  c  o  m
 * @return REST response with error collection.
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(value = GenericServiceException.class)
public @ResponseBody RESTResponseWrapper<List<RESTErrorModel>> returnGenericError(GenericServiceException e) {
    RESTErrorModel error = new RESTErrorModel();
    error.setCode(e.getCode());
    error.setMessage(e.getMessage());
    error.setLocalizedMessage(e.getLocalizedMessage());
    List<RESTErrorModel> errorList = new LinkedList<>();
    errorList.add(error);
    Logger.getLogger(RESTControllerAdvice.class.getName()).log(Level.SEVERE, null, e);
    return new RESTResponseWrapper<>("ERROR", errorList);
}

From source file:io.getlime.security.powerauth.app.rest.api.spring.errorhandling.DefaultExceptionHandler.java

/**
 * Handle Exception exceptions.//from  w ww. j  av a 2  s.c o  m
 * @param exception Exception instance.
 * @return Error response.
 */
@ExceptionHandler(value = Exception.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public @ResponseBody PowerAuthApiResponse<ErrorModel> handleException(Exception exception) {
    Logger.getLogger(DefaultExceptionHandler.class.getName()).log(Level.SEVERE, exception.getMessage(),
            exception);
    ErrorModel error = new ErrorModel("ERR_GENERIC", exception.getMessage());
    return new PowerAuthApiResponse<>(PowerAuthApiResponse.Status.ERROR, error);
}

From source file:org.trustedanalytics.utils.errorhandling.RestErrorHandlerTest.java

@Test
public void exceptionMarkedWithResponseStatusSendsProperErrorCode() throws Exception {
    RestErrorHandler handler = new RestErrorHandler();
    Exception ex = new ExceptionWithResponseStatus();
    HttpServletResponse httpResponse = mock(HttpServletResponse.class);

    handler.handleException(ex, httpResponse);

    verify(httpResponse, times(1)).sendError(eq(HttpStatus.BAD_REQUEST.value()), anyString());
}

From source file:org.trustedanalytics.kafka.adminapi.api.ExceptionHandlerAdvice.java

@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody//w w  w .j a v a  2s . c  o m
public String handleBadRequest(InvalidTopicException ex) {
    LOG.error("Invalid topic", ex);
    return ex.getMessage();
}

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

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody//from  ww  w  . j a v a  2  s. c om
public ValidationErrorContainer processMethodArgumentNotValidException(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;

}