cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Grzegorz Kossakowski <>
Subject Re: ServletSource#getInputStream()
Date Tue, 01 Jan 2008 22:34:51 GMT
Reinhard Poetz pisze:
> Can somebody explain the purpose of this code to me? What's the use case
> that makes a second request necessary?

Yes, sure. It has close relation to the fact that we use Conditional GETs/POSTs for implementing
caching of servlet source. For details see my explanations of the code

> public InputStream getInputStream() throws IOException,
>     SourceException {
>     try {
>         connect();

Let's assume we are making POST request to a servlet service.
When connect() is called this.servletConnection.requestBody contains serialized content coming
calling servlet that will be POSTed to the called servlet. Call of connect() method does actual
request to the servlet.

>         if (servletConnection.getResponseCode() !=
> HttpServletResponse.SC_OK) {
>           ... redo the request here ...

Here should testing is little bit weird because it should only test if SC_NOT_MODIFIED was
by called servlet. The situation is that called servlet responded that cached result of its
call is still valid. However, we are in getInputStream() so it means that calling servlet
does not
have cached response anymore and it asks for a fresh content. That means we need to make a
request, this time not a conditional one, asking for a content.

The problem is, that for POST requests when there is something to REPOST this code is broken
is what Vadim found a few months ago. I discussed this problem with Vadim and Leszek and I
we had not came to any strong conclusion how to fix it. :-(

My current preference would be to just store POST body in a ServletSource and just copy streams
*both* requests. This is in an obvious conflict with the goal to have streaming of SAX events
servlet calls are made. However, I'm starting to agree with Carsten's opinion that is should
not be
our high-priority goal anymore because streaming of SAX events brings a lot of complexity
to the
pipelining code.

>         }
>         return this.servletConnection.getInputStream();

Here we return response obtained from *second* request.

>     } catch (ServletException e) {
>         throw new CascadingIOException(e.getMessage(), e);
>     }
> }

I hope that helps you.

Grzegorz Kossakowski

View raw message