You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jesse Klaasse <je...@indicia.nl> on 2008/09/02 10:19:10 UTC

Filter cuts response in Tomcat 5.5.20

For a few days, I have been breaking my head over this issue:

My goal is to create a filter which detects Ajax calls (using jQuery for
Ajax, which adds "X-Requested-With: XMLHttpRequest" to the request headers).
If some jsp is requested by an Ajax call, I want to process the jsp's output
with this filter (extract the body, correct some entities and stuff, but
this is not really important to know for this issue, especially since I
don't even get this far).

I have implemented the filter structure as outlined here:
http://download.oracle.com/docs/cd/B32110_01/web.1013/b28959/filters.htm

With one adaptation: in the Filter I check for the "X-Requested-With:
XMLHttpRequest" header, and when it is there, I do the pre-post thing
mentioned in the article. If it's not, it just continues the chain. I left
the rest of the files untouched.

However, it isn't working as it should be. I actually see the "PRE" and
"POST" lines in the Ajax output, however, most of the time there is nothing
between them. And when I print the response length, it's 0 most of the time.
This is all working fine using our old development platform (based on Resin
3.0.14), but it isn't working on the new one (based on Tomcat 5.5.20).

When I request the same url via a browser, all is working fine. Also, when I
disable the filter, all is working fine (however, without my desired
changes). So it has to be in the filter's code.

An idea, anyone?

I have attached the relevant java code for the filter to this message in one
tar file:
http://www.nabble.com/file/p19265999/AjaxPreparationFilter.tar
AjaxPreparationFilter.tar 
-- 
View this message in context: http://www.nabble.com/Filter-cuts-response-in-Tomcat-5.5.20-tp19265999p19265999.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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


Re: Filter cuts response in Tomcat 5.5.20

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jesse,

Jesse Klaasse wrote:
> However, it isn't working as it should be. I actually see the "PRE" and
> "POST" lines in the Ajax output, however, most of the time there is nothing
> between them. And when I print the response length, it's 0 most of the time.
> This is all working fine using our old development platform (based on Resin
> 3.0.14), but it isn't working on the new one (based on Tomcat 5.5.20).

I wonder about this method in GenericResponseWrapper.java:

	public PrintWriter getWriter() throws IOException {
		return new PrintWriter(getOutputStream(), true);
	}

I think you want to return the same object each time you call getWriter.
Perhaps you could cache the PrintWriter you create and return that each
time, instead of just creating a new one each time. If you don't you
could create a situation where flushing behavior might render the page
in odd ways.

Also, you are calling getOutputStream in this method, which is /not/
overridden in GenericResponseWrapper, which means that getWriter
actually avoids your ByteArrayOutputStream altogether (which is why you
have zero bytes in the output). I'm a little confused as to why no
output is generated, anyway, since getOutputStream should return the
same object being used by the Filter itself, so all the data should
eventually make it out of there.

Just to be sure: you are not using FilterServletOutputStream, right?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkjFoxkACgkQ9CaO5/Lv0PBsvACgk3xqG1OpmC9uieZz/qP5dkL6
wxcAnipq/+hs5qlm5uv8BjLwel2gAd4S
=a4dR
-----END PGP SIGNATURE-----

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