Well, you should keep reading up on Filters and how they can replace the
request/response objects, they are very useful.
You'll want to create your own Request object ( extending
HttpServletRequestWrapper ). In its constructor you absorb the
inputstream into a byte[]. Then you create another instance variable to
hold the ByteArrayInputStream you will wrap the byte[] with. Then you
implement the getInputStream method to return that ByteArrayInputStream.
You should review all of the methods of the Http/ServletRequest
interfaces to make sure you don't need to expose the input stream in any
other different way.
That should do it.
fernando
Jean-Eric Cuendet wrote:
After some investigations, I understand that I should subclass
servlet.Filter and override doFilter() in it. Then put some config in my
Tomcat config to let it call MyFilter.doFilter()
Is that right?
Then, I can do request.getInputStream() and read the stream, put it in
a request.setParameter("RawData") but then how to let the request have
access to the InputStream? The data in it is already consumed by the
MyFiler class... I could create a ByteArrayInputStream but then how to
wire it to the Request object? There is no setInputStream() ...
Thanks for help.
-jec
Jean-Eric Cuendet wrote:
Yup, you can't, this is how webapps work in general, sorry. But you
can create a filter to get what you want, read on.
The problem is that if it's a POST request, someone (webapp
container, request object) has already digested the whole body of the
request and convert it into properties of the form. So someone else
has already gone through and gobbled up all of the data (simple
unbuffered stream), so you can't get a look at it. This is the most
efficient way, and most people don't complain.
That's exactly how I understand the thing. And you also exactly
understand my needs! :-) Thanks.
Now, the only way to do what you're trying to achieve is to
essentially copy the data before it's taken away. If I remember
correctly the process of converting the body into properties is
kicked off on the first getProperty command. So you have to create a
Filter that replaces the request object, with one that buffers or
copies the request body, while still making it available through
normal api calls. Then I would probably put that byte[] into a
request attribute ( request.setAttribute, or override
request.getAttribute ), and that's how you would get access to it.
Very well understand that. But no idea where to begin...
Is that filter a Tapestry Service thing? Or a Tomcat thing?
byte[] body = (byte[]) ...getRequest().getAttribute( "rawbody" );
cool? que sera, sera.
Yes, very!
So you have to create a request object that on construction absorbs
the body into a byte[], re-exposing it through a
ByteArrayInputStream, and putting it into a request.Attribute.
Again, this won't be the most efficient way of doing things, so just
map the filter against the urls that actually need the support. :)
OK, nice. That's exactly what I need. But if you could provide some
more help on how to do it, where to begin, which object to create,
where to put it, ...
Thanks a lot.
-jec
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]