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 09:50:38 GMT
Ok, sorry, I didn't understand you but now it makes perfect sense.
Thanks for your advise!

Bart.

> -----Original Message-----
> From: Upayavira [mailto:uv@upaya.co.uk]
> Sent: Friday, February 18, 2005 10:37 AM
> To: dev@cocoon.apache.org
> Subject: Re: Write binary data to output stream from flow
> 
> Bart Molenkamp wrote:
> >
> >>-----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
> 
> That is exactly what I took from what you were saying. And, as it
> currently stands, there is no way to send data other than via a
> pipeline. So, what I would say is:
> 
> cocoon.sendPage("my-binary-url", {"stream": evidenceDataStream,
> "mimeType": mimeType});
> 
> <map:match pattern="my-binary-url">
>    <map:read src="evidence:"/>
> </map:match>
> 
> Then, in your source, you can use o.a.c.components.flow.FlowHelper to
> get the stream and mimetype business objects, and have your source use
> them. I'm not up on this enough to give you exact details, but if I
were
> to try to achieve this, this is probably how I would go about it.
> 
> Am I making sense now?
> 
> Regards, Upayavira

Mime
View raw message