import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.ws.rs.core.Context;
LOG.debug("In toResponse: {}", exception.getMessage());
- final List<MediaType> accepts = headers.getAcceptableMediaTypes();
- if (accepts != null) {
- accepts.remove(MediaType.WILDCARD_TYPE);
+ final List<MediaType> mediaTypeList = new ArrayList<>();
+ if (headers.getMediaType() != null) {
+ mediaTypeList.add(headers.getMediaType());
}
- LOG.debug("Accept headers: {}", accepts);
-
- final MediaType mediaType;
- if (accepts != null && accepts.size() > 0) {
- mediaType = accepts.get(0); // just pick the first one
- } else {
- // Default to the content type if there's no Accept header
- mediaType = MediaType.APPLICATION_JSON_TYPE;
- }
+ mediaTypeList.addAll(headers.getAcceptableMediaTypes());
+ final MediaType mediaType = mediaTypeList.stream().filter(type -> !type.equals(MediaType.WILDCARD_TYPE))
+ .findFirst().orElse(MediaType.APPLICATION_JSON_TYPE);
LOG.debug("Using MediaType: {}", mediaType);