Juan Hernandez has posted comments on this change.
Change subject: restapi: Include charset in JSON Content-Type
......................................................................
Patch Set 3:
(2 comments)
I will try to make this work with less "manual" things, but it may not be
possible. I will also try to make it work for XML, but that may be a in a
different patch.
....................................................
File
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resteasy/json/JsonProvider.java
Line 38: @Produces(MediaType.APPLICATION_JSON)
Line 39: public class JsonProvider extends JacksonJsonProvider {
Line 40: // This is the content type that we will use in all the responses:
Line 41: private static final String CONTENT_TYPE_HEADER = "Content-Type";
Line 42: private static final MediaType CONTENT_TYPE_MEDIA =
MediaType.valueOf(MediaType.APPLICATION_JSON + "; charset=UTF-8");
As I explained in the comment in the "writeTo" method, the version of Jackson
that we currently use always generates the output using UTF-8, regardless of
what is requested, that is why we can always use UTF-8. This isn't ideal, of
course, but is better than specifying a character set in the header and
actually using a different one in the body.
Line 43:
Line 44: public JsonProvider() {
Line 45: // Note that we can't specify here the use of JAXB annotations
as it is ignored if the mapper is changed later,
Line 46: // thus we need to call the parent constructor first, without
a mapper, and then create the mapper and pass it
Line 77: MultivaluedMap<String, Object> httpHeaders, OutputStream
entityStream) throws IOException {
Line 78: // Jackson always generates the output using UTF-8, regardless
of what is requested, so we can safely set the
Line 79: // charset to UTF-8:
Line 80: httpHeaders.putSingle(CONTENT_TYPE_HEADER, CONTENT_TYPE_MEDIA);
Line 81: super.writeTo(value, type, genericType, annotations,
mediaType, httpHeaders, entityStream);
As far as I understand the @Produces annotation tells to the user of the
provider (the JAX-RS infra) what types the provider supports, it doesn't tell
the provider what types should be generated, not what it should actually return
for a specific request. For a specific request the JAX-RS selects a type and
provides it in the "mediaType" of the "writeTo" method, but in this particular
case whatever the JAX-RS selects isn't relevant because anything other than
UTF-8 is wrong, thus the provider has to change that manually.
Line 82: }
--
To view, visit http://gerrit.ovirt.org/20104
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I9156fe168451f103219902b821236b5a4703819d
Gerrit-PatchSet: 3
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
Gerrit-Reviewer: Juan Hernandez <[email protected]>
Gerrit-Reviewer: Michael Pasternak <[email protected]>
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches