RE: first send headers, than create message body?

2008-03-06 Thread Jerome Louvel

Stephan,

I think this is the same design mistake that was made by the Servlet API.
Let me have a look at the related EG discussion.

Best regards,
Jerome  

> -Message d'origine-
> De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> Envoyé : jeudi 6 mars 2008 10:30
> À : discuss@restlet.tigris.org
> Objet : Re: first send headers, than create message body?
> 
> Hello Jerome,
> 
> yes, I know this way and using it.
> But for this case the JAX-RS proposal requires, that it is 
> possible to 
> create the http headers and the body in *the same* method.
> 
> public void methodname(StreamingOutput so, ...)
> {
> Response jaxRsResponse = ...
> // create response headers.
> OutputStream os = do.getOutputStream(response); // this 
> should send 
> the http headers from the jaxRsResponse.
> os.write(...);
> os.write(...);
> os.write(...);
> os.write(...);
> }
> 
> This should all happens in *one* method.
> 
> best regards
>Stephan
> >> 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?
> >> 
> > This is easily possible by creating a subclass of 
> OutputRepresentation.
> >
> > response.setEntity(new OutputRepresentation(){
> > public void write(OutputStream os){
> > os.write(...)
> > os.write(...)
> > os.write(.. perhaps large data ..)
> > os.write(...)
> > os.write(.. more large data ..)
> > os.write(...)
> > os.write(...)
> > };
> > });
> >   



Re: first send headers, than create message body?

2008-03-06 Thread Stephan Koops

Hello Jerome,

yes, I know this way and using it.
But for this case the JAX-RS proposal requires, that it is possible to 
create the http headers and the body in *the same* method.


public void methodname(StreamingOutput so, ...)
{
   Response jaxRsResponse = ...
   // create response headers.
   OutputStream os = do.getOutputStream(response); // this should send 
the http headers from the jaxRsResponse.

   os.write(...);
   os.write(...);
   os.write(...);
   os.write(...);
}

This should all happens in *one* method.

best regards
  Stephan
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?


This is easily possible by creating a subclass of OutputRepresentation.

response.setEntity(new OutputRepresentation(){
public void write(OutputStream os){
os.write(...)
os.write(...)
os.write(.. perhaps large data ..)
os.write(...)
os.write(.. more large data ..)
os.write(...)
os.write(...)
};
});
  


RE: first send headers, than create message body?

2008-03-06 Thread Jerome Louvel

Hi Stephan,

> 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?

This is easily possible by creating a subclass of OutputRepresentation.

response.setEntity(new OutputRepresentation(){
public void write(OutputStream os){
os.write(...)
os.write(...)
os.write(.. perhaps large data ..)
os.write(...)
os.write(.. more large data ..)
os.write(...)
os.write(...)
};
});
 
[...]

Best regards,
Jerome  



first send headers, than create message body?

2008-03-05 Thread Stephan Koops

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, MultivaluedMapObject> 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