cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bart Molenkamp" <b.molenk...@bizzdesign.nl>
Subject RE: Write binary data to output stream from flow
Date Fri, 18 Feb 2005 08:15:08 GMT


> -----Original Message-----
> From: Upayavira [mailto:uv@upaya.co.uk]
> Sent: Thursday, February 17, 2005 5:19 PM
> To: dev@cocoon.apache.org
> Subject: Re: Write binary data to output stream from flow
> 
> Bart Molenkamp wrote:
> > Hi,
> >
> > Is it possible to write binary data to the HTTP response directly
from
> > the flow? I have an InputStream available in my flow, and I want to
> > serve data from that stream directly to the HTTP response. E.g.
> >
> > cocoon.sendBinaryData(inputStream, "application/octet-stream");
> >
> > Or something similar.
> >
> > I solved it now by creating a SourceFactory and Source
implementation,
> > so that I can use a plain reader, but this feels a bit like
overkill.
> > The SourceFactory has to lookup the data from the database (that is
> > where the data is for the input stream), and the URL contains the
> > primary key to get the data from the database.
> 
> To my knowledge there isn't a way to do this directly. But you could
> place the inputstream into a request attribute or some such, and pick
> that up from your source, rather than reading the database again.
> 
> Am I understanding your question right?
> 
> Regards, Upayavira

Hi Upayavira,

I don't know if I understood your answer. Maybe I'm not clear enough
about my question, so I'll try again.

In my flowscript, I get a java.io.InputStream instance, and the content
that I read from it can be sent to the user directly. The user thinks
that it is downloading a file (which he is) but the source comes from a
database (but the database is transparent due to OJB). In my case, I
have a review object which can hold 0 or more downloaded files (files
are evidence that support the result of the review):

...
review = ...; // get review from database trough OJB
cocoon.sendPageAndWait("list-evidence.xml", 
  {evidence: review.getEvidence()});

...
evidenceId = cocoon.request.get("evidenceId");
evidence = review.getEvidenceById(evidenceId);
evidenceDataStream = evidence.getInputStream();
mimeType = evidence.getMimeType();

// now I want to serve the input stream to the user
// e.g. something like
cocoon.sendBinaryData(evidenceDataStream, mimeType);

How can I now read this input stream, and pass it's data to the output
stream of a pipeline, in a simple way. Currently, I have an evidence
source that I can lookup. The URL contains the ID of the review, and the
ID of the evidence. Something like evidence://reviewid/evidenceid.txt

Hope this clarifies my question a little bit more.

Mime
View raw message