Example usage for org.springframework.http.converter HttpMessageNotReadableException getMessage

List of usage examples for org.springframework.http.converter HttpMessageNotReadableException getMessage

Introduction

In this page you can find the example usage for org.springframework.http.converter HttpMessageNotReadableException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:org.exoplatform.acceptance.rest.JsonErrorHandler.java

/**
 * Catch HttpMessageNotReadableException to log it (helps to diagnose errors and attacks on REST services).
 *
 * @param ex The exception trapped//from   w  ww.ja va 2s.  c  o m
 * @return A standardized {@link org.exoplatform.acceptance.rest.JsonErrorResponse}
 * @throws java.io.IOException if any.
 */
@ExceptionHandler(HttpMessageNotReadableException.class)
@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public JsonErrorResponse handleHttpMessageNotReadableException(HttpMessageNotReadableException ex)
        throws IOException {
    LOGGER.warn("Http Message Not Readable : {}", ex.getMessage());
    return new JsonErrorResponse(ex);
}

From source file:com.orange.cepheus.cep.controller.AdminController.java

@ExceptionHandler({ HttpMessageNotReadableException.class })
public ResponseEntity<Object> messageNotReadableExceptionHandler(HttpServletRequest req,
        HttpMessageNotReadableException exception) {
    logger.error("Request not readable: {}", exception.toString());
    StatusCode statusCode = new StatusCode();
    statusCode.setCode("400");
    statusCode.setReasonPhrase(exception.getMessage());
    if (exception.getCause() != null) {
        statusCode.setDetail(exception.getCause().getMessage());
    }//  w  w  w  .j a  v  a2 s.c  om
    return new ResponseEntity<>(statusCode, HttpStatus.BAD_REQUEST);
}

From source file:business.CustomResponseEntityExceptionHandler.java

@Override
protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
        HttpHeaders headers, HttpStatus status, WebRequest request) {
    Throwable mostSpecificCause = ex.getMostSpecificCause();
    ErrorMessage errorMessage;/*from   w  w  w.  java2s .  com*/
    if (mostSpecificCause != null) {
        String exceptionName = mostSpecificCause.getClass().getName();
        String message = mostSpecificCause.getMessage();
        errorMessage = new ErrorMessage(exceptionName, message);
    } else {
        errorMessage = new ErrorMessage(ex.getMessage());
    }
    return new ResponseEntity<Object>(errorMessage, headers, status);
}

From source file:com.garyclayburg.persistence.repository.CustomResponseEntityExceptionHandler.java

@Override
protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
        HttpHeaders headers, HttpStatus status, WebRequest request) {
    Throwable mostSpecificCause = ex.getMostSpecificCause();
    ErrorMessage errorMessage;// w  w w.j a v a2s  .c  o  m
    if (mostSpecificCause != null) {
        String exceptionName = mostSpecificCause.getClass().getName();
        String message = mostSpecificCause.getMessage();
        errorMessage = new ErrorMessage(exceptionName, message);
    } else {
        errorMessage = new ErrorMessage(ex.getMessage());
    }
    return new ResponseEntity(errorMessage, headers, status);
}

From source file:com.ns.retailmgr.controller.exception.RestControllerExceptionHandler.java

@Override
protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
        HttpHeaders headers, HttpStatus status, WebRequest request) {
    Throwable mostSpecificCause = ex.getMostSpecificCause();
    RestErrorMessage RestErrorMessage;//from www.  java 2 s.  com
    if (mostSpecificCause != null) {
        String exceptionName = mostSpecificCause.getClass().getName();
        String message = mostSpecificCause.getMessage();
        RestErrorMessage = new RestErrorMessage(exceptionName, message);
    } else {
        RestErrorMessage = new RestErrorMessage(ex.getMessage());
    }
    return new ResponseEntity(RestErrorMessage, headers, status);
}