dev@jsr311.java.net

Re: JSR311: Response isn't adequate

From: Bill Burke <bburke_at_redhat.com>
Date: Mon, 10 Mar 2008 10:11:10 -0400

Marc Hadley wrote:
> On Mar 7, 2008, at 3:51 PM, Bill Burke wrote:
>>
>> Also, can consider a simple Representation interface? I know it would
>> be easy to implement one with the @Provider model, but I think its a
>> good idea.
>>
> I think the combination of Response and ResponseBuilder already fulfill
> the role of representation.
>

@GET
public Representation get()
{

     Connection conn = ...;
     Blob blob = rs.getBlob(...);

     return new Representation() {
        public write(OutputStream stream) {
            // stream the output
            blob.close();
            rs.close();
            conn.close();
        }
     };

}

Instead of requiring the awkward creation and registration of
MessageBodyWriters, you allow the component to return a Representation
object, which is really a MessageBodyWriter-like object instantiated by
the resource.


Restlet works this way. And so does Apache HttpClient (except in the
opposite direction). I know Ryan's initial RESTEasy project had this
idea as well.

Bill

-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com