This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a servlet filter that sits in front of a webservice servlet (AXIS) - what I want the filter to do is to look at the content of the ServletRequest and if a particular string is located in the request, I want to call another service. Everything works just fine except (isin't there always an execept) that when I execute the following code in the filter:
I know that you can only call the getReader or the getInputStream (not both) from ServletRequest. This makes me think that you can only call either of them once, which the container will do if and when you call any of the methods that require parsing the request. Since you've already called it, it blows up when the container tries.
Since my initial post I attempted to wrap the request and make a copy of the stream so that I don't hit the error.. It works the first time getReader is called, however when it's passed into the doFilter method and the request finally gets to AXIS we have a problem. AXIS calls the getInputStream method and perhaps I screwed something up.. Here is the code..
I realize this is a very old topic but it still shows up on Google and was very helpful in getting me pointed in the right direction.
I had the same problem of wanting to see the XML contents of the request in a Servlet Filter before the request went to Axis2. I started with the code sample in PJ Crump's last post but modified the getInputStream() method:
Hopefully this can help ease the next person's headache.