Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user for overriding the default Viewable MediaType #4461

Merged
merged 1 commit into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -102,7 +102,9 @@ public void writeTo(final Viewable viewable,
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -71,7 +73,9 @@ public Response toResponse(WebApplicationException exception) {

// 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();
Expand Down Expand Up @@ -102,6 +106,8 @@ public void testAbsoluteExplicitTemplate() throws IOException {
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
Expand All @@ -116,5 +122,8 @@ public void testResolvingClassExplicitTemplate() throws IOException {
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();
}
}