Hello,
is it possible to code in Restlet, that I create a message head, than
start to send it and afterwoods start to create the entity data (the
message body) in one method, without creating a new Representation
subclass that does it?
I think not, or does I miss something?
The reason is, that they discuss this for JAX-RS (JSR 311). In general
it's a good and efficient idea for a HTTP server, but I think we can not
realize this in Restlet without building a byte[]-buffer (or someting
like that), collect the data and after collecting finished we can start
to send the http headers and than the collected entity data.
The idea for JAX-RS is the following:
public void getData(StreamingOutput so) {
Response response = ...; // create status and headers
OuptutStream os = so.getOutputStream(response);
os.write(...)
os.write(...)
os.write(.. perhaps large data ..)
os.write(...)
os.write(.. more large data ..)
os.write(...)
os.write(...)
}
If I put the code beginning with the third line in an own runnable
object, than I could execute it later, but this way?
As said: I think the idea is good, but I don't see, how to realize it
with restlet in an efficient way.
best regards
Stephan
-------- Original-Nachricht --------
Betreff: Re: JSR311: Response isn't adequate
Datum: Mon, 03 Mar 2008 11:38:29 -0500
Von: Marc Hadley <[EMAIL PROTECTED]>
An: [EMAIL PROTECTED]
How does the following sound:
public interface StreamingOutput {
OutputStream getOutputStream(int status, MultivaluedMap<String,
Object> metadata);
}
A resource method can have a parameter of the above type but, if so,
it MUST have a void return type. You get an output stream by passing
in the desired status code and metadata which you can get from a
Response instance (or create yourself). I don't want
getOutputStream(Response) since that brings up questions about what to
do if the response contains an entity and I don't really like any of
the answers to that question. Calling getOutputStream more than once
isn't allowed.
An example of usage:
@GET
public void getData(StreamingOutput so) {
Response r = Response.created("someuri").type("sometype").build();
OuptutStream os = so.getOutputStream(r.getStatus(), r.getMetadata());
os.write(...)
}
We'd still use @ProduceMime to choose a method to call and to default
the content type if not explicitly set.
I had a failure of imagination when coming up with the interface and
method names, if you have better ideas I'd like to hear them.
Marc