Allow the user for overriding the default Viewable MediaType

Signed-off-by: Jan Supol <jan.supol@oracle.com>
diff --git a/ext/mvc/src/main/java/org/glassfish/jersey/server/mvc/internal/ViewableMessageBodyWriter.java b/ext/mvc/src/main/java/org/glassfish/jersey/server/mvc/internal/ViewableMessageBodyWriter.java
index 61820ef..0949838 100644
--- a/ext/mvc/src/main/java/org/glassfish/jersey/server/mvc/internal/ViewableMessageBodyWriter.java
+++ b/ext/mvc/src/main/java/org/glassfish/jersey/server/mvc/internal/ViewableMessageBodyWriter.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v. 2.0, which is available at
@@ -102,7 +102,9 @@
                 throw new WebApplicationException(new ProcessingException(message), Response.Status.NOT_FOUND);
             }
 
-            httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE, resolvedViewable.getMediaType());
+            if (!httpHeaders.containsKey(HttpHeaders.CONTENT_TYPE)) {
+                httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE, resolvedViewable.getMediaType());
+            }
             resolvedViewable.writeTo(entityStream, httpHeaders);
         } catch (ViewableContextException vce) {
             throw new NotFoundException(vce);
diff --git a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/mvc/ExceptionViewProcessorTest.java b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/mvc/ExceptionViewProcessorTest.java
index 772c099..287b614 100644
--- a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/mvc/ExceptionViewProcessorTest.java
+++ b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/mvc/ExceptionViewProcessorTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v. 2.0, which is available at
@@ -26,6 +26,7 @@
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.client.Invocation;
 import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.Provider;
@@ -37,6 +38,7 @@
 import org.glassfish.jersey.test.TestProperties;
 import org.glassfish.jersey.tests.e2e.server.mvc.provider.TestViewProcessor;
 
+import org.junit.Assert;
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 
@@ -71,7 +73,9 @@
 
             // Relative.
             if (exception.getResponse().getStatus() == 406) {
-                return Response.status(406).entity(
+                return Response.status(406)
+                        .type(MediaType.TEXT_PLAIN_TYPE)
+                        .entity(
                         new Viewable(
                                 "/org/glassfish/jersey/tests/e2e/server/mvc/ExceptionViewProcessorTest/WebAppExceptionMapper/406",
                                 "406")).build();
@@ -102,6 +106,8 @@
         p.load(cr.readEntity(InputStream.class));
         assertEquals("/org/glassfish/jersey/tests/e2e/server/mvc/ExceptionViewProcessorTest/404.testp", p.getProperty("path"));
         assertEquals("404", p.getProperty("model"));
+
+        cr.close();
     }
 
     @Test
@@ -116,5 +122,8 @@
         assertEquals("/org/glassfish/jersey/tests/e2e/server/mvc/ExceptionViewProcessorTest/WebAppExceptionMapper/406.testp",
                 p.getProperty("path"));
         assertEquals("406", p.getProperty("model"));
+
+        Assert.assertEquals(MediaType.TEXT_PLAIN_TYPE, cr.getMediaType());
+        cr.close();
     }
 }