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.jwt.exceptions.GlobalExceptionHandler.java

@ExceptionHandler(BindException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody/*from www .j a  v a 2  s .  co m*/
public Map handleException(BindException exception) {
    _LOGGER.log(Level.INFO, (Supplier<String>) exception);
    List<String> errors = new ArrayList<>();
    for (FieldError fe : exception.getFieldErrors()) {
        errors.add(fe.getDefaultMessage());
    }
    return error(errors);
}

From source file:org.osiam.addons.selfadministration.exception.InvalidAttributeException.java

public InvalidAttributeException(String message, String key) {
    super(message, key, HttpStatus.BAD_REQUEST.value());
}

From source file:io.pivotal.strepsirrhini.chaoslemur.state.AbstractRestControllerStateProvider.java

@RequestMapping(method = RequestMethod.POST, value = "/state", consumes = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<?> changeState(@RequestBody Map<String, String> payload) {
    String value = payload.get(STATUS_KEY);

    if (value == null) {
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }/*from  ww  w  .  ja  v a2 s  .co m*/

    try {
        set(State.valueOf(value.toUpperCase()));
        return new ResponseEntity<>(HttpStatus.OK);
    } catch (IllegalArgumentException e) {
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }

}

From source file:com.hypersocket.auth.json.BootstrapResourceController.java

@ExceptionHandler(ResourceCreationException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public void resourceChangeError(HttpServletRequest request, HttpServletResponse response,
        ResourceCreationException e) {/* w  ww .ja  v a2 s .  com*/
    log.error("Resource creation error", e);
}

From source file:org.zalando.riptide.OAuth2CompatibilityResponseErrorHandlerTest.java

@Test
public void isNoErrorForClientError() throws IOException {
    final ClientHttpResponse response = new MockClientHttpResponse(new byte[] {}, HttpStatus.BAD_REQUEST);
    assertThat(unit.hasError(response), is(false));
}

From source file:com.sastix.cms.common.services.web.ExceptionHandlingController.java

@ExceptionHandler({ CommonException.class })
public void handleBadRequests(HttpServletRequest request, HttpServletResponse response, Exception e)
        throws IOException {
    LOG.error("Bad request: {} from {}, Exception: {} {}", request.getRequestURI(), request.getRemoteHost(),
            e.getStackTrace()[0].toString(), e.getLocalizedMessage());

    response.sendError(HttpStatus.BAD_REQUEST.value(), e.getLocalizedMessage());
}

From source file:com.todo.backend.web.rest.exception.ExceptionResolver.java

@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ExceptionHandler(MethodArgumentNotValidException.class)
public @ResponseBody ErrorResponse validationException(HttpServletRequest request,
        MethodArgumentNotValidException exception) {
    if (log.isErrorEnabled()) {
        log.error(exception.getMessage(), exception);
    }// w  w  w .  jav a2s  .  c  o  m
    final List<String> errorCodes = exception.getBindingResult().getFieldErrors().stream()
            .map(e -> String.format("%s.%s.%s", e.getObjectName(), e.getField(), e.getCode()))
            .collect(Collectors.toList());
    return new ErrorResponse(exception.getMessage(), errorCodes);
}

From source file:com.ar.dev.tierra.api.controller.CategoriaController.java

@RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAll() {
    List<Categoria> categorias = facadeService.getCategoriaDAO().getAll();
    if (!categorias.isEmpty()) {
        return new ResponseEntity<>(categorias, HttpStatus.OK);
    } else {/*from w  w  w  . j a v a2  s.c om*/
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.ws.controller.TaxonomyExceptionHandler.java

@ExceptionHandler(ParseException.class)
public ResponseEntity<TaxonomyErrorResponse> handleLuceneParseException(ParseException ex,
        WebRequest webRequest) {/* w  w w. j  a  v a2s  . c  o  m*/
    TaxonomyErrorResponse errorResponse = new TaxonomyErrorResponse(TaxonomyErrorType.INVALID_CATEGORY_QUERY,
            ex.getMessage());
    logger.error("{} < {}", extractPathFromWebRequest(webRequest), errorResponse.toString());
    return new ResponseEntity<TaxonomyErrorResponse>(errorResponse, HttpStatus.BAD_REQUEST);
}