users@glassfish.java.net

Re: Problem when using Servlet filter in front of a web service

From: <glassfish_at_javadesktop.org>
Date: Wed, 05 Dec 2007 09:58:15 PST

The problem seems to me that you are consuming the inputstream, but the downstream servlet from your filter doesn't "know" that, and is not handling the error gracefully.

I'm guessing you're trying to echo the stream to see the contents? By doing so you corrupt the request for future consumers.

I would suggest using a tcp monitor (there's a nice one for netbeans) or some other proxy mechanism. If you want to continue using a filter, then you should consume the entire input stream in to a byte array or a file (don't know how big your requests are) so that you can create a new HttpServletRequestWrapper to do your own proxy.

The basic goal is that when your servlet/web server calls "getInputStream", it needs to see the same (or the equivalent) thing that you see in the filter. By reading the stream in the filter, it doesn't get that.

http://java.sun.com/products/servlet/Filters.html

That should give you a hint about this problem.
[Message sent by forum member 'whartung' (whartung)]

http://forums.java.net/jive/thread.jspa?messageID=248698