Seen in CSIT run after jersey 2 upgrade:
2018-05-31T08:47:19,494 | ERROR | qtp315470863-147 | ServerRuntime$Responder | 190 - org.glassfish.jersey.core.jersey-server - 2.25.1 | An exception has been thrown from an exception mapper class org.opendaylight.netconf.sal.rest.impl.RestconfDocumentedExceptionMapper.
java.lang.UnsupportedOperationException: null
at java.util.Collections$UnmodifiableList$1.remove(Collections.java:1349) [?:?]
at jersey.repackaged.com.google.common.collect.TransformedIterator.remove(TransformedIterator.java:53) [185:org.glassfish.jersey.bundles.repackaged.jersey-guava:2.25.1]
at java.util.AbstractCollection.remove(AbstractCollection.java:293) [?:?]
at org.opendaylight.netconf.sal.rest.impl.RestconfDocumentedExceptionMapper.toResponse(RestconfDocumentedExceptionMapper.java:104) [346:org.opendaylight.netconf.restconf-nb-bierman02:1.8.0.SNAPSHOT]
at org.opendaylight.netconf.sal.rest.impl.RestconfDocumentedExceptionMapper.toResponse(RestconfDocumentedExceptionMapper.java:76) [346:org.opendaylight.netconf.restconf-nb-bierman02:1.8.0.SNAPSHOT]
headers.getAcceptableMediaTypes() now returns an immutable list so rework
the code to use stream -> filter - findFirst.
Change-Id: I346c884226c1cfe3afce1b6937176f5397cc3367
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
LOG.debug("In toResponse: {}", exception.getMessage());
- final List<MediaType> accepts = headers.getAcceptableMediaTypes();
- if (accepts != null) {
- accepts.remove(MediaType.WILDCARD_TYPE);
- }
-
- 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;
- }
+ final MediaType mediaType = headers.getAcceptableMediaTypes().stream()
+ .filter(type -> type != MediaType.WILDCARD_TYPE).findFirst().orElse(MediaType.APPLICATION_JSON_TYPE);
LOG.debug("Using MediaType: {}", mediaType);