HttpMediaTypeNotAcceptableException (#2145)

* code snippets for the `Java 9 Stream API improvements` article

* code snippets for the `Java 9 Stream API improvements` article [2 attempt]

* removed the first attempt

* the Spring 5 WebClient

* delted stream features test

* HttpMediaTypeNotAcceptableExceptionExampleController [0]

* reactive web client service was removed
This commit is contained in:
Andrew 2017-06-25 19:23:25 +03:00 committed by Grzegorz Piwowarek
parent ed7c1694a7
commit 18b56311e5
1 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,27 @@
package com.baeldung.exception;
import org.springframework.http.MediaType;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.Map;
@RestController
public class HttpMediaTypeNotAcceptableExceptionExampleController {
@PostMapping(value = "/test", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, String> test() {
return Collections.singletonMap("key", "value");
}
@ResponseBody
@ExceptionHandler(HttpMediaTypeNotAcceptableException.class)
public String handleHttpMediaTypeNotAcceptableException() {
return "acceptable MIME type:" + MediaType.APPLICATION_JSON_VALUE;
}
}