dev@jsr311.java.net

Re: ProduceMime and ConsumeMime

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Mon, 09 Apr 2007 13:22:12 -0400

On Apr 9, 2007, at 11:46 AM, Julian Reschke wrote:

> Marc Hadley schrieb:
>> Right. The thinking is that if you have a lot of methods with
>> common media type characteristics you can put the annotations at
>> the class level and then only override them for individual methods
>> that differ. If you only have a couple of methods in total and
>> they are different you can just put the annotations at the method
>> level since class level annotations won't save anything.
>
> OK, thanks for the clarification.
>
> Do you have a real-world use case in mind where a resource would
> actually accept many methods with the same types of payloads? Right
> now, I can't think of any...
>
You might want a bunch of POST methods that all return different
media types. That way you can leave the content negotiation to the
JSR 311 runtime which will call the correct method based on the value
of the Accept header in the request, e.g.:

@UriTemplate("someuri")
@ConsumeMime("application/x-www-form-urlencoded")
public class FormProcessor {

   @ProduceMime("application/xml")
   @HttpMethod
   public Source postFormAsXml(FormURLEncodedProperties data) {
     ...
   }

   @ProduceMime("text/html")
   @HttpMethod
   public Source postFormAsHtml(FormURLEncodedProperties data) {
     ...
   }

   @ProduceMime("application/json")
   @HttpMethod
   public JSONObject postFormAsJson(FormURLEncodedProperties data) {
     ...
   }
}

Marc.

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