You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 28, 2018. It is now read-only.
This will drop the charset from the response and only return text/html. However, if you change the content type to anything other than text/html the charset will be left intact:
@Path(...) @Produces("text/plain; charset=utf-8") // Charset won't get dropped public Response get() {
return Response.ok("Test");
}
The only way I've found to keep the charset with text/html, is to specify it in the response like so:
@Path(...)
public Response get() {
return Response.ok("Test", "text/html; charset=utf-8"); // Charset won't get dropped }
Cheers
Environment
Jersey 2.0, GlassFish 4.0, NetBeans 7.3.1, Windows 8.
Affected Versions
[2.0]
The text was updated successfully, but these errors were encountered:
mfuksa said:
The problem is probably in the Accept header of the request. I did some tests and it looks like when the Accept header defines "Accept: text/html" then the response will contain only "text/html" and the charset will be removed. In this case, the media type of accept header is used precisely. When Accept header is "Accept: /" the charset is added correctly to the response. So, it looks when there Accept header and Produces media type matches, the Accept header value is used exactly as it is. In my opinion, the charset parameter should be added to the response even in the case that Accept is "text/html". The JAX-RS 2.0 spec, chapter 3.8 does not define these details.
I move this bug to backlog. Here is the test code
public class SimpleCharsetTest extends JerseyTest {
@Path("resource")
public static class MyResource {
@GET
@Produces("text/html;charset=UTF-8")
public String get() {
return "html";
}
}
@Test
public void test() {
Response response = target().path("resource").request("*/*").get();
assertEquals(200, response.getStatus());
assertEquals("text/html; charset=UTF-8", response.getMediaType().toString());
}
@Override
protected Application configure() {
return new ResourceConfig(MyResource.class, LoggingFilter.class);
}
}
In Jersey 2.0/GlassFish 4.0 there seems to be some weird behavior when specifying the charset in a @produces annotation:
This will drop the charset from the response and only return text/html. However, if you change the content type to anything other than text/html the charset will be left intact:
The only way I've found to keep the charset with text/html, is to specify it in the response like so:
Cheers
Environment
Jersey 2.0, GlassFish 4.0, NetBeans 7.3.1, Windows 8.
Affected Versions
[2.0]
The text was updated successfully, but these errors were encountered: