You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Robert J. Carr" <rj...@apl.washington.edu> on 2018/01/29 17:19:46 UTC

capturing response output in filter

I have a Filter that uses the output stream from the response of the
servlet in the chain.  In order to do this I create a custom response
wrapper that has a custom servlet output stream.

This works fine, but in moving to a newer Java EE API there have been a
couple new (abstract) methods added to servlet output stream, and my
application needs to (unfortunately) work in both Tomcat 7 and Tomcat 8+.

So, is there any other way to capture the response output stream that
doesn't rely on this?  If not, any recommendations on how to straddle these
tomcat/java versions?

The only thing I can think of, but haven't tried, is to compile against
Tomcat 7, but run that application in Tomcat 8+.

Thanks!

Re: capturing response output in filter

Posted by "Robert J. Carr" <rj...@gmail.com>.
On Mon, Jan 29, 2018 at 9:27 AM, Mark Thomas <ma...@apache.org> wrote:
>
> On 29/01/18 17:19, Robert J. Carr wrote:
> > I have a Filter that uses the output stream from the response of the
> > servlet in the chain.  In order to do this I create a custom response
> > wrapper that has a custom servlet output stream.
> >
> > This works fine, but in moving to a newer Java EE API there have been a
> > couple new (abstract) methods added to servlet output stream, and my
> > application needs to (unfortunately) work in both Tomcat 7 and Tomcat
8+.
> >
> > So, is there any other way to capture the response output stream that
> > doesn't rely on this?  If not, any recommendations on how to straddle
these
> > tomcat/java versions?
> >
> > The only thing I can think of, but haven't tried, is to compile against
> > Tomcat 7, but run that application in Tomcat 8+.
>
> Try the other way. Compile against Tomcat 8+, run on Tomcat 7. The
> additional methods should just be ignored on Tomcat 7.
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

Hi Mark-

Thanks for the quick response.  You're right, for a different method that
was added in a different situation this is what I do.  But for the
ServletOutputStream, they added this method:

    setWriteListener(WriteListener writeListener)

Which includes the WriteListener, that was also added.  So I don't think I
can use the technique you suggest, unless I want to do some sort of
conditional dependency injection.

Or maybe I'm missing something?

Thanks!

Re: capturing response output in filter

Posted by Mark Thomas <ma...@apache.org>.
On 29/01/18 17:19, Robert J. Carr wrote:
> I have a Filter that uses the output stream from the response of the
> servlet in the chain.  In order to do this I create a custom response
> wrapper that has a custom servlet output stream.
> 
> This works fine, but in moving to a newer Java EE API there have been a
> couple new (abstract) methods added to servlet output stream, and my
> application needs to (unfortunately) work in both Tomcat 7 and Tomcat 8+.
> 
> So, is there any other way to capture the response output stream that
> doesn't rely on this?  If not, any recommendations on how to straddle these
> tomcat/java versions?
> 
> The only thing I can think of, but haven't tried, is to compile against
> Tomcat 7, but run that application in Tomcat 8+.

Try the other way. Compile against Tomcat 8+, run on Tomcat 7. The
additional methods should just be ignored on Tomcat 7.

Mark

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