cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <Ralph.Go...@dslextreme.com>
Subject Re: Where do you access HttpResponse from ?
Date Thu, 22 Sep 2005 03:33:10 GMT
If you use the RequestListener interface you have access to the 
Environment. If you look at SampleRequestListener you will see it obtain 
the Request. A similar method can be used to get the response (i.e. - 
ObjectModelHelper.getResponse()).

Having said that, HttpResponse simply wraps 
javax.servlet.http.HttpServletResponse. The getBufferSize() method in 
HttpResponse consists of

    public int getBufferSize() {
        return this.res.getBufferSize();
    }

this.res is the HttpServletResponse.

Now getBufferSize() is defined in javax.servlet.ServletResponse as

Returns the actual buffer size used for the response. If no buffering is 
used, this method returns 0.

This leads me to believe that it is only the size of the buffer, not the 
size of the response data. 

Unfortunately, what you may have to do is to extend Cocoon's 
HttpResponse with your own and replace the HttpResponse in the 
Environment with yours in the RequestListener's onRequestStart() method 
and then put the real one back in the onRequestEnd() method after 
appropriately updating it.

Ralph




Laurent Perez wrote:

>>so you want to execute biz logic depending on the total size of the http
>>response ...
>>    
>>
>
>yep, exactly : I'm delivering content to poor browsers which, for
>example, will not accept more than 50KB from the http response, the
>biz logic is nothing too fancy, it only logs warnings about response
>being too rich.
>
>  
>
>>I don't think it is possible to retrieve response headers using the
>>servlet API - however check the api docs to be sure.
>>    
>>
>
>well, there is org.apache.cocoon.environment.http.HttpResponse which
>implements the Response interface, and offers int getBufferSize() and
>ServletOutputStream getOutputStream(). getBufferSize() sounds good,
>however it's not documented in 2.1.7 javadocs :/
>
>Or I could tell the Cocoon servlet itself to write into a
>java.io.ByteArrayOutputStream, then do a size() to get the content
>length, process my logic, then use
>writeTo(HttpResponse.getOutputStream) to deliver the stream to the
>client, however this sounds overkill.
>
>what I miss is : can I access
>org.apache.cocoon.environment.http.HttpResponse from a "proper" place,
>or should I have to hack its source directly ? Because this class uses
>setContentLength(), I could probably fit my logic call in this method.
>
>laurent
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message