From b83e7d09a2ca8fb98dd434d8c256402ab378d51b Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Fri, 1 Jun 2018 17:16:46 -0400 Subject: [PATCH] Use requested media type in RestconfDocumentedExceptionMapper The code uses headers.getAcceptableMediaTypes() to select the media type for the response but, from what I've seen, that only contains the wildcard "\", in which case we always return json. We should use the requested media type via headers.getMediaType(), if set, and fallback to getAcceptableMediaTypes() or json as default. Change-Id: I391cf054ddab18ddc2855d8d4337cac376d71825 Signed-off-by: Tom Pantelis --- .../rest/impl/RestconfDocumentedExceptionMapper.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfDocumentedExceptionMapper.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfDocumentedExceptionMapper.java index aa6b7c0b69..9f25da0f0c 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfDocumentedExceptionMapper.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfDocumentedExceptionMapper.java @@ -18,6 +18,7 @@ import java.io.OutputStreamWriter; 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; @@ -99,9 +100,14 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper !type.equals(MediaType.WILDCARD_TYPE)).findFirst() - .orElse(MediaType.APPLICATION_JSON_TYPE); + final List mediaTypeList = new ArrayList<>(); + if (headers.getMediaType() != null) { + mediaTypeList.add(headers.getMediaType()); + } + + 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); -- 2.36.6