[
https://issues.apache.org/jira/browse/WINK-262?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Bryant Luk updated WINK-262:
----------------------------
Attachment: WINK-262-2.patch
I propose moving the ;charset addition to the String and XML providers.
The reasoning is because of a few things
1) Should work on the client and the server
2) The charset should be in addition to any other handler that's on the path
and should be added when providers are invoked directly if possible.
Right now, the basic code block is:
{code}
if (httpHeaders != null && httpHeaders.get(HttpHeaders.CONTENT_TYPE) ==
null) {
// only correct the MediaType if the MediaType was not explicitly
// set
logger
.debug("Media Type not explicitly set on Response so going to
correct charset parameter if necessary");//$NON-NLS-1$
Map<String, String> parameters = mediaType.getParameters();
if (parameters != null) {
if (parameters.get("charset") == null) { //$NON-NLS-1$
try {
Map<String, String> params =
new HashMap<String,
String>(mediaType.getParameters());
params.put("charset", "UTF-8"); //$NON-NLS-1$
$NON-NLS-2$
httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE, new
MediaType(mediaType
.getType(), mediaType.getSubtype(), params));
//$NON-NLS-1$
logger.debug("Added charset=UTF-8 parameter to
Content-Type HttpHeader"); //$NON-NLS-1$
} catch (Exception e) {
// this can happen in the Atom Model since we pass in
an unmodifiable set
logger.debug("Caught exception while trying to set the
charset", e); //$NON-NLS-1$
}
}
}
}
{code}
The idea is that if a media type is explicitly set by a Response.type() to not
change it. However, if it was populated by the runtime, then go ahead and add
the charset if one does not exist. A few catches for cases where we invoked
the provider directly with unexpected parameter values.
> Content-Type of HTTP Response contains no charset.
> --------------------------------------------------
>
> Key: WINK-262
> URL: https://issues.apache.org/jira/browse/WINK-262
> Project: Wink
> Issue Type: Bug
> Components: Server
> Affects Versions: 1.0
> Environment: Jetty Server 6.1
> Reporter: Kaloyan Kolev
> Assignee: Mike Rheinheimer
> Fix For: 1.1
>
> Attachments: WINK-262-2.patch, WINK-262.patch
>
>
> I have the following handler:
> {code}
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.Produces;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.MediaType;
> import javax.ws.rs.core.Request;
> import javax.ws.rs.core.Response;
> import org.apache.wink.common.model.atom.AtomEntry;
> import org.apache.wink.common.model.atom.AtomText;
> @Path("contentType")
> public class ContentTypeTest {
> @GET
> @Produces( { MediaType.APPLICATION_XML, MediaType.TEXT_XML,
> MediaType.APPLICATION_JSON, "text/javascript" })
> public Response getRepresentation(@Context Request req) {
> AtomEntry e = new AtomEntry();
> e.setTitle(new AtomText(
>
> "\u5341\u5341\u5341\u5341\u5341\u5341\u5341\u5341\u5341\u5341\u5341\u5341\u4e00\u69cb\u30bd\u30c1\u2010"));
> return Response.ok(e).build();
> }
> }
> {code}
> When I open the resource I get the following HTTP response:
> {code}
> Content-Type: application/xml
> Content-Length: 274
> Server: Jetty(6.1.x)
> {code}
> You can see that the charset is not specified and the content is not properly
> decoded e.g. by RestClient - http://code.google.com/p/rest-client/
> However I can see that the XML is properly encoded by opening the resource in
> FF and enforcing UTF-8 decoding.
> Shouldn't wink put the encoding used during serialization if different than
> ASCII?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.