cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lev Epshteyn <>
Subject Cocoon modification to give producers the access to HttpServletRe sponse
Date Wed, 12 Jul 2000 20:59:16 GMT
Hi, everyone.

I am sure many people involved in the developmnet of web applications using
Cocoon have run up against the inability to access an instance of an
HttpServletResponse object inside the producer code.

This is a severe limitation, one that prohibits setting HTTP cookies,
sending redirects, streaming out binary files, etc.

I know that this functionality is available through XSP, but to use XSP in
conjunction with producers is, in my opinion, a contrived and inefficient
solution. (In addition, we have not been able to get it to work at all)

I have come up with what I consider to be a pretty simple, yet effective
modification to Cocoon that will allow producers to access the Servler
Response object without breaking the backwards compatibility with existing
producers, or going against the general Cocoon design model.

In a nutshell, I propose extending the Producer interface, that has 
	getDocument(request)		and
with the ActiveProducer interface, which would also have the methods
	getDocument(request,response)     and

The Active producer would be able to "act" directly on the Response object
(hence the name).

A default implementation would be provided for ActiveProducer: 
	AbstractActiveProducer extends AbstractProducer implements

This class would provide default implementations for the interface's two new

	getDocument(request,response) would work just like it's counterpart
in AbstractProducer, except that it will make a call to
getStream(request,response) rather than getStream(request)

	getStream(request,response) would by default call getStream(request)
method, but this functionality could be re-implemented by a subclass.

I also propose adding the code to Cocoon's processing engine
( that would check if the producer is an
instanceof ActiveProducer. If it is, the getDocument(request,response)
method would be called instead of getDocument(request).

Finally, an Exception should be added to org.apache.cocoon.framework, called
ActiveProducerException. This would be thrown by an ActiveProducer's
implementation of getDocument(request,response) or
getStream(request,response) if any action is performed on the response
object that makes further Cocoon processing impossible or unneccessary. (For
example if the producer sends a redirect, or decides to output data to the
ServletOutputStream directly.) This exception would be caught by the Cocoon
processing engine, which at that point will know to not take any further
action (i.e. not to parse the document and merge it with XSL).

I believe that these changes will allow developers to continue using the old
versions of their producers where neccessary, and upgradte producers to
active producers when the need arises. Such modifications would be very
minor from the standpoint of the API, but will allow a great deal of
flexibility to be achieved for these producers.

I have implemented these changes, and have tested Cocooon with them (though
not extensively yet). I would be glad to submit my code to the project so
that it can become a part of the standard Cocoon distribution. Please let me
know how to go about that, or if you have any additional questions.

Thanks for your time.

-lev epshteyn, Java Developer @

View raw message