Example usage for org.springframework.http HttpStatus UNSUPPORTED_MEDIA_TYPE

List of usage examples for org.springframework.http HttpStatus UNSUPPORTED_MEDIA_TYPE

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus UNSUPPORTED_MEDIA_TYPE.

Prototype

HttpStatus UNSUPPORTED_MEDIA_TYPE

To view the source code for org.springframework.http HttpStatus UNSUPPORTED_MEDIA_TYPE.

Click Source Link

Document

415 Unsupported Media Type .

Usage

From source file:apiserver.services.images.controllers.manipulations.ResizeController.java

/**
 * Resize an image//from   w w w.ja  va  2 s . c o  m
 *
 * @param file
 * @param interpolation - highestQuality,highQuality,mediumQuality,highestPerformance,highPerformance,mediumPerformance,nearest,bilinear,bicubic,bessel,blackman,hamming,hanning,hermite,lanczos,mitchell,quadratic
 * @param width
 * @param height
 * @return
 */
@ApiOperation(value = "Resize an uploaded image")
@RequestMapping(value = "/modify/resize", method = { RequestMethod.POST })
@ResponseBody
public ResponseEntity<byte[]> resizeImageByImage(HttpServletRequest request, HttpServletResponse response,
        @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file,
        @ApiParam(name = "width", required = true, defaultValue = "200") @RequestParam(required = true) Integer width,
        @ApiParam(name = "height", required = true, defaultValue = "200") @RequestParam(required = true) Integer height,
        @ApiParam(name = "interpolation", required = false, defaultValue = "bicubic") @RequestParam(required = false, defaultValue = "bicubic") String interpolation,
        @ApiParam(name = "scaleToFit", required = false, defaultValue = "false") @RequestParam(required = false, defaultValue = "false") Boolean scaleToFit,
        @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format

) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    Document _file = null;
    MimeType _outputMimeType = null;
    String _outputContentType = null;

    MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request);
    _file = new Document(_mFile);
    _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType());
    _outputContentType = _outputMimeType.contentType;
    if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) {
        return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    FileResizeJob job = new FileResizeJob();
    job.setDocumentId(null);
    job.setDocument(_file);
    //job.getDocument().setContentType(MimeType.getMimeType(file.getContentType()) );
    //job.getDocument().setFileName(file.getOriginalFilename());
    job.setWidth(width);
    job.setHeight(height);
    job.setInterpolation(interpolation.toUpperCase());
    job.setScaleToFit(scaleToFit);

    Future<Map> imageFuture = imageResizeGateway.resizeImage(job);
    FileResizeJob payload = (FileResizeJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    //pass CF Response back to the client
    return payload.getHttpResponse();
}

From source file:apiserver.services.images.controllers.filters.DespeckleController.java

/**
 * This filter reduces light noise in an image using the eight hull algorithm described in Applied Optics, Vol. 24, No. 10, 15 May 1985, "Geometric filter for Speckle Reduction", by Thomas R Crimmins. Basically, it tries to move each pixel closer in value to its neighbours. As it only has a small effect, you may need to apply it several times. This is good for removing small levels of noise from an image but does give the image some fuzziness.
 *
 * @param file/*www. j a  v a  2s.co m*/
 * @param format
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "This filter reduces light noise in an image using the eight hull algorithm described in Applied Optics, Vol. 24, No. 10, 15 May 1985, \"Geometric filter for Speckle Reduction\", by Thomas R Crimmins. Basically, it tries to move each pixel closer in value to its neighbours. As it only has a small effect, you may need to apply it several times. This is good for removing small levels of noise from an image but does give the image some fuzziness.")
@RequestMapping(value = "/filter/despeckle", method = { RequestMethod.POST })
public ResponseEntity<byte[]> imageDespeckleByFile(HttpServletRequest request, HttpServletResponse response,
        @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file,
        @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    Document _file = null;
    MimeType _outputMimeType = null;
    String _outputContentType = null;

    MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request);
    _file = new Document(_mFile);
    _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType());
    _outputContentType = _outputMimeType.contentType;
    if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) {
        return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    ImageDocumentJob job = new ImageDocumentJob();
    job.setDocumentId(null);
    job.setDocument(_file);

    Future<Map> imageFuture = imageFilterDespeckleGateway.imageDespeckleFilter(job);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(),
            _outputContentType, false);
    return result;

}

From source file:br.com.modoagil.asr.rest.support.RESTErrorHandler.java

/**
 * Manipula exceo para status HTTP {@code 415}
 *
 * @param ex//ww  w.  j  a va  2s .c o m
 *            {@link HttpMediaTypeNotSupportedException}
 * @return resposta ao cliente
 */
@ResponseBody
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public Response<E> processHttpMediaTypeNotSupportedException(final HttpMediaTypeNotSupportedException ex) {
    this.logger.info("handleHttpMediaTypeNotSupportedException - Catching: " + ex.getClass().getSimpleName(),
            ex);
    return new ResponseBuilder<E>().success(false).message(ex.getContentType().getType() + " not supported")
            .status(HttpStatus.UNSUPPORTED_MEDIA_TYPE).build();
}

From source file:apiserver.services.images.controllers.filters.LensBlurController.java

/**
 * This filter simulates the blurring caused by a camera lens. You can change the aperture size and shape and also specify blooming of the uploaded image. This filter is very slow.
 *
 * @param file/*  ww w.j av a  2 s  .c om*/
 * @param radius
 * @param sides
 * @param bloom
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "This filter simulates the blurring caused by a camera lens. You can change the aperture size and shape and also specify blooming of the image. This filter is very slow.")
@RequestMapping(value = "/filter/lensblur", method = { RequestMethod.POST })
public ResponseEntity<byte[]> imageLensBlurByFile(HttpServletRequest request, HttpServletResponse response,
        @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file,
        @ApiParam(name = "radius", required = false, defaultValue = "10") @RequestParam(value = "radius", required = false, defaultValue = "10") float radius,
        @ApiParam(name = "sides", required = false, defaultValue = "5") @RequestParam(value = "sides", required = false, defaultValue = "5") int sides,
        @ApiParam(name = "bloom", required = false, defaultValue = "2") @RequestParam(value = "bloom", required = false, defaultValue = "2") float bloom,
        @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    Document _file = null;
    MimeType _outputMimeType = null;
    String _outputContentType = null;

    MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request);
    _file = new Document(_mFile);
    _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType());
    _outputContentType = _outputMimeType.contentType;
    if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) {
        return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    LensBlurJob job = new LensBlurJob();
    job.setDocumentId(null);
    job.setDocument(new Document(file));
    job.setRadius(radius);
    job.setSides(sides);
    job.setBloom(bloom);

    Future<Map> imageFuture = imageFilterLensBlurGateway.imageLensBlurFilter(job);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(),
            _outputContentType, false);
    return result;
}

From source file:apiserver.services.images.controllers.filters.BumpController.java

/**
 * This filter does a simple convolution which emphasises edges in an uploaded image.
 *
 * @param file// www . j av a 2s.c o  m
 * @param format
 * @param edgeAction
 * @param useAlpha
 * @param matrix
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "This filter does a simple convolution which emphasises edges in an image.")
@RequestMapping(value = "/filter/bump", method = { RequestMethod.POST })
public ResponseEntity<byte[]> imageBumpByFile(HttpServletRequest request, HttpServletResponse response,
        @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file,
        @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format,
        @ApiParam(name = "edgeAction", required = false, defaultValue = "1") @RequestParam(value = "edgeAction", required = false, defaultValue = "1") int edgeAction,
        @ApiParam(name = "useAlpha", required = false, defaultValue = "true", allowableValues = "true,false") @RequestParam(value = "useAlpha", required = false, defaultValue = "true") boolean useAlpha,
        @ApiParam(name = "matrix", required = false, defaultValue = "-1.0,-1.0,0.0,-1.0,1.0,1.0,0.0,1.0,1.0") @RequestParam(value = "matrix", required = false, defaultValue = "-1.0,-1.0,0.0,-1.0,1.0,1.0,0.0,1.0,1.0") String matrix

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    Document _file = null;
    MimeType _outputMimeType = null;
    String _outputContentType = null;

    MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request);
    _file = new Document(_mFile);
    _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType());
    _outputContentType = _outputMimeType.contentType;
    if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) {
        return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    // convert string array into float array
    String[] matrixStrings = matrix.split(",");
    float[] matrixValues = new float[matrixStrings.length];
    for (int i = 0; i < matrixStrings.length; i++) {
        String s = matrixStrings[i];
        matrixValues[i] = Float.parseFloat(s);
    }

    BumpJob job = new BumpJob();
    job.setDocumentId(null);
    job.setDocument(_file);

    job.setEdgeAction(edgeAction);
    job.setUseAlpha(useAlpha);
    job.setMatrix(matrixValues);

    Future<Map> imageFuture = imageFilterBumpGateway.imageBumpFilter(job);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(),
            _outputContentType, false);
    return result;
}

From source file:apiserver.services.images.controllers.filters.GrayscaleController.java

/**
 * This filter converts an uploaded image to a grayscale image. To do this it finds the brightness of each pixel and sets the red, green and blue of the output to the brightness value. But what is the brightness? The simplest answer might be that it is the average of the RGB components, but that neglects the way in which the human eye works. The eye is much more sensitive to green and red than it is to blue, and so we need to take less acount of the blue and more account of the green. The weighting used by GrayscaleFilter is: luma = 77R + 151G + 28B
 *
 * @param file//w ww  .j  av a 2  s  .  c om
 * @param format
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "This filter converts an image to a grayscale image. To do this it finds the brightness of each pixel and sets the red, green and blue of the output to the brightness value. But what is the brightness? The simplest answer might be that it is the average of the RGB components, but that neglects the way in which the human eye works. The eye is much more sensitive to green and red than it is to blue, and so we need to take less acount of the blue and more account of the green. The weighting used by GrayscaleFilter is: luma = 77R + 151G + 28B")
@RequestMapping(value = "/filter/grayscale", method = { RequestMethod.POST })
public ResponseEntity<byte[]> imageGrayscaleByFile(HttpServletRequest request, HttpServletResponse response,
        @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file,
        @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    Document _file = null;
    MimeType _outputMimeType = null;
    String _outputContentType = null;

    MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request);
    _file = new Document(_mFile);
    _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType());
    _outputContentType = _outputMimeType.contentType;
    if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) {
        return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    ImageDocumentJob job = new ImageDocumentJob();
    job.setDocumentId(null);
    job.setDocument(new Document(file));

    Future<Map> imageFuture = imageFilterGrayScaleGateway.imageGrayScaleFilter(job);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(),
            _outputContentType, false);
    return result;
}

From source file:apiserver.services.images.controllers.filters.BoxBlurController.java

/**
 * A filter which performs a box blur on an uploaded image. The horizontal and vertical blurs can be specified separately and a number of iterations can be given which allows an approximation to Gaussian blur.
 *
 * @param file//  www . java 2  s . com
 * @param hRadius
 * @param vRadius
 * @param iterations
 * @param preMultiplyAlpha
 * @param format
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "A filter which performs a box blur on an image. The horizontal and vertical blurs can be specified separately and a number of iterations can be given which allows an approximation to Gaussian blur.")
@RequestMapping(value = "/filter/boxblur", method = { RequestMethod.POST })
@ResponseBody
public ResponseEntity<byte[]> imageBoxBlurByFile(HttpServletRequest request, HttpServletResponse response,
        @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file,
        @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format,
        @ApiParam(name = "hRadius", required = false, defaultValue = "2", value = "the horizontal radius of blur") @RequestParam(value = "hRadius", required = false, defaultValue = "2") int hRadius,
        @ApiParam(name = "vRadius", required = false, defaultValue = "2", value = "the vertical radius of blur") @RequestParam(value = "vRadius", required = false, defaultValue = "2") int vRadius,
        @ApiParam(name = "iterations", required = false, defaultValue = "1", value = "the number of time to iterate the blur") @RequestParam(value = "iterations", defaultValue = "1") int iterations,
        @ApiParam(name = "preMultiplyAlpha", required = false, defaultValue = "true", allowableValues = "true,false", value = "pre multiply the alpha channel") @RequestParam(value = "preMultiplyAlpha", required = false, defaultValue = "true") boolean preMultiplyAlpha

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    Document _file = null;
    MimeType _outputMimeType = null;
    String _outputContentType = null;

    MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request);
    _file = new Document(_mFile);
    _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType());
    _outputContentType = _outputMimeType.contentType;
    if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) {
        return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    BoxBlurJob job = new BoxBlurJob();
    job.setDocumentId(null);
    job.setDocument(_file);

    job.setHRadius(hRadius);
    job.setVRadius(vRadius);
    job.setIterations(iterations);
    job.setPreMultiplyAlpha(preMultiplyAlpha);

    Future<Map> imageFuture = imageFilterBoxBlurGateway.imageBoxBlurFilter(job);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(),
            _outputContentType, false);
    return result;
}

From source file:apiserver.services.images.controllers.filters.MotionBlurController.java

/**
 * This filter replaces each pixel by the median of the input pixel and its eight neighbours. Each of the RGB channels is considered separately.
 * @param file//  ww w .j a  v a2  s.  c o m
 * @param angle
 * @param distance
 * @param rotation
 * @param wrapEdges
 * @param zoom
 * @param format
 * @return
 * @throws java.util.concurrent.TimeoutException
 * @throws java.util.concurrent.ExecutionException
 * @throws InterruptedException
 * @throws java.io.IOException
 */
@ApiOperation(value = "This filter simulates motion blur on an image. You specify a combination of angle/distance for linear motion blur, a rotaiton angle for spin blur or a zoom factor for zoom blur. You can combine these in any proportions you want to get effects like spiral blurs.")
@RequestMapping(value = "/filter/motionblur", method = { RequestMethod.POST })
@ResponseBody
public ResponseEntity<byte[]> imageMotionBlurByFile(HttpServletRequest request, HttpServletResponse response,
        @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file,
        @ApiParam(name = "angle", required = false, defaultValue = "0") @RequestParam(value = "angle", required = false, defaultValue = "0") float angle,
        @ApiParam(name = "distance", required = false, defaultValue = "1") @RequestParam(value = "distance", required = false, defaultValue = "0") float distance,
        @ApiParam(name = "rotation", required = false, defaultValue = "0") @RequestParam(value = "rotation", required = false, defaultValue = "0") float rotation,
        @ApiParam(name = "wrapEdges", required = false, defaultValue = "false") @RequestParam(value = "wrapEdges", required = false, defaultValue = "false") boolean wrapEdges,
        @ApiParam(name = "zoom", required = false, defaultValue = "0") @RequestParam(value = "zoom", required = false, defaultValue = "0") float zoom,
        @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format

) throws TimeoutException, ExecutionException, InterruptedException, IOException {
    Document _file = null;
    MimeType _outputMimeType = null;
    String _outputContentType = null;

    MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request);
    _file = new Document(_mFile);
    _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType());
    _outputContentType = _outputMimeType.contentType;
    if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) {
        return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
    }

    MotionBlurJob job = new MotionBlurJob();
    job.setDocumentId(null);
    job.setDocument(new Document(file));
    job.setAngle(angle);
    job.setDistance(distance);
    job.setRotation(rotation);
    job.setWrapEdges(wrapEdges);
    job.setZoom(zoom);

    Future<Map> imageFuture = imageFilterMotionBlurGateway.imageMotionBlurFilter(job);
    ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS);

    ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(),
            _outputContentType, false);
    return result;
}

From source file:org.spring.data.gemfire.rest.GemFireRestInterfaceTest.java

@SuppressWarnings("deprecation")
private RestTemplate setErrorHandler(final RestTemplate restTemplate) {
    restTemplate.setErrorHandler(new ResponseErrorHandler() {
        private final Set<HttpStatus> errorStatuses = new HashSet<>();

        /* non-static */ {
            errorStatuses.add(HttpStatus.BAD_REQUEST);
            errorStatuses.add(HttpStatus.UNAUTHORIZED);
            errorStatuses.add(HttpStatus.FORBIDDEN);
            errorStatuses.add(HttpStatus.NOT_FOUND);
            errorStatuses.add(HttpStatus.METHOD_NOT_ALLOWED);
            errorStatuses.add(HttpStatus.NOT_ACCEPTABLE);
            errorStatuses.add(HttpStatus.REQUEST_TIMEOUT);
            errorStatuses.add(HttpStatus.CONFLICT);
            errorStatuses.add(HttpStatus.REQUEST_ENTITY_TOO_LARGE);
            errorStatuses.add(HttpStatus.REQUEST_URI_TOO_LONG);
            errorStatuses.add(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
            errorStatuses.add(HttpStatus.TOO_MANY_REQUESTS);
            errorStatuses.add(HttpStatus.INTERNAL_SERVER_ERROR);
            errorStatuses.add(HttpStatus.NOT_IMPLEMENTED);
            errorStatuses.add(HttpStatus.BAD_GATEWAY);
            errorStatuses.add(HttpStatus.SERVICE_UNAVAILABLE);
        }/*from   w w w .  j a  v a 2s  .  c  o m*/

        @Override
        public boolean hasError(final ClientHttpResponse response) throws IOException {
            return errorStatuses.contains(response.getStatusCode());
        }

        @Override
        public void handleError(final ClientHttpResponse response) throws IOException {
            System.err.printf("%1$d - %2$s%n", response.getRawStatusCode(), response.getStatusText());
            System.err.println(readBody(response));
        }

        private String readBody(final ClientHttpResponse response) throws IOException {
            BufferedReader responseBodyReader = null;

            try {
                responseBodyReader = new BufferedReader(new InputStreamReader(response.getBody()));

                StringBuilder buffer = new StringBuilder();
                String line;

                while ((line = responseBodyReader.readLine()) != null) {
                    buffer.append(line).append(System.getProperty("line.separator"));
                }

                return buffer.toString().trim();
            } finally {
                FileSystemUtils.close(responseBodyReader);
            }
        }
    });

    return restTemplate;
}

From source file:org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerSupport.java

/**
 * Provides handling for standard Spring MVC exceptions.
 * @param ex the target exception//ww w .j  av a2  s  .  co m
 * @param request the current request
 */
@ExceptionHandler(value = { NoSuchRequestHandlingMethodException.class,
        HttpRequestMethodNotSupportedException.class, HttpMediaTypeNotSupportedException.class,
        HttpMediaTypeNotAcceptableException.class, MissingServletRequestParameterException.class,
        ServletRequestBindingException.class, ConversionNotSupportedException.class,
        TypeMismatchException.class, HttpMessageNotReadableException.class,
        HttpMessageNotWritableException.class, MethodArgumentNotValidException.class,
        MissingServletRequestPartException.class, BindException.class })
public final ResponseEntity<Object> handleException(Exception ex, WebRequest request) {

    HttpHeaders headers = new HttpHeaders();

    HttpStatus status;
    Object body;

    if (ex instanceof NoSuchRequestHandlingMethodException) {
        status = HttpStatus.NOT_FOUND;
        body = handleNoSuchRequestHandlingMethod((NoSuchRequestHandlingMethodException) ex, headers, status,
                request);
    } else if (ex instanceof HttpRequestMethodNotSupportedException) {
        status = HttpStatus.METHOD_NOT_ALLOWED;
        body = handleHttpRequestMethodNotSupported((HttpRequestMethodNotSupportedException) ex, headers, status,
                request);
    } else if (ex instanceof HttpMediaTypeNotSupportedException) {
        status = HttpStatus.UNSUPPORTED_MEDIA_TYPE;
        body = handleHttpMediaTypeNotSupported((HttpMediaTypeNotSupportedException) ex, headers, status,
                request);
    } else if (ex instanceof HttpMediaTypeNotAcceptableException) {
        status = HttpStatus.NOT_ACCEPTABLE;
        body = handleHttpMediaTypeNotAcceptable((HttpMediaTypeNotAcceptableException) ex, headers, status,
                request);
    } else if (ex instanceof MissingServletRequestParameterException) {
        status = HttpStatus.BAD_REQUEST;
        body = handleMissingServletRequestParameter((MissingServletRequestParameterException) ex, headers,
                status, request);
    } else if (ex instanceof ServletRequestBindingException) {
        status = HttpStatus.BAD_REQUEST;
        body = handleServletRequestBindingException((ServletRequestBindingException) ex, headers, status,
                request);
    } else if (ex instanceof ConversionNotSupportedException) {
        status = HttpStatus.INTERNAL_SERVER_ERROR;
        body = handleConversionNotSupported((ConversionNotSupportedException) ex, headers, status, request);
    } else if (ex instanceof TypeMismatchException) {
        status = HttpStatus.BAD_REQUEST;
        body = handleTypeMismatch((TypeMismatchException) ex, headers, status, request);
    } else if (ex instanceof HttpMessageNotReadableException) {
        status = HttpStatus.BAD_REQUEST;
        body = handleHttpMessageNotReadable((HttpMessageNotReadableException) ex, headers, status, request);
    } else if (ex instanceof HttpMessageNotWritableException) {
        status = HttpStatus.INTERNAL_SERVER_ERROR;
        body = handleHttpMessageNotWritable((HttpMessageNotWritableException) ex, headers, status, request);
    } else if (ex instanceof MethodArgumentNotValidException) {
        status = HttpStatus.BAD_REQUEST;
        body = handleMethodArgumentNotValid((MethodArgumentNotValidException) ex, headers, status, request);
    } else if (ex instanceof MissingServletRequestPartException) {
        status = HttpStatus.BAD_REQUEST;
        body = handleMissingServletRequestPart((MissingServletRequestPartException) ex, headers, status,
                request);
    } else if (ex instanceof BindException) {
        status = HttpStatus.BAD_REQUEST;
        body = handleBindException((BindException) ex, headers, status, request);
    } else {
        logger.warn("Unknown exception type: " + ex.getClass().getName());
        status = HttpStatus.INTERNAL_SERVER_ERROR;
        body = handleExceptionInternal(ex, headers, status, request);
    }

    return new ResponseEntity<Object>(body, headers, status);
}