dev@jsr311.java.net

Re: JSR311: Setting response content-type should be required

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Mon, 09 Feb 2009 10:01:19 -0500

What does the request accept header look like, I'm guessing its not
very specific ? If it has anything other than text/yaml then the
runtime should select the ToStringProvider, for text/yaml it should
select the YamlProvider.

Requiring the content-type to be set means you have to edit all of the
resource classes to add support for a new media type, currently you
can just drop in a new MBW. I think the issue you bring up only occurs
when the client doesn't include a specific accept header with a request.

Marc.

On Feb 7, 2009, at 12:10 AM, Bill Burke wrote:

> I've recently run into problems with the current rules on
> "Determining the MediaType of Responses" in Section 3.8.
>
> Specifically, if there is no @Produces and no Content-Type header
> set, the the JAX-RS provider creates a set of possible media types
> from MessageBodyWriters that "support" the entity type.
>
> *THIS IS BAD*
>
> Why? Adding a new provider can drastically change the behavior or
> your application.
>
> I have a writer that just does object.toString() for all text/*:
>
> @Produces("text/*")
> public class ToStringProvider implements MessageBodyWriter
> {
> boolean isWritable(...)
> {
> return true;
> }
> }
>
> I come along later in the app development cycle and introduce a
> provider that can generate YAML from any Java Object:
>
> @Produces({"text/yaml", "text/x-yaml", "application/x-yaml"})
> public class YamlProvider implements MessageBodyWriter
> {
> boolean isWritable(...)
> {
> return true;
> }
> }
>
> Now, instead of writing text/plain, I'm not outputting YAML. A
> seemingly innocent introduction of a provider change the whole
> behavior of the application (unknowingly).
>
> --
> Bill Burke
> JBoss, a division of Red Hat
> http://bill.burkecentral.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: dev-help_at_jsr311.dev.java.net
>

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.