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.
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.
byte[] body = (byte[]) ...getRequest().getAttribute( "rawbody" );
cool? que sera, sera.
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. :)
fernando
Jean-Eric Cuendet wrote:
Thanks for that anser, but that part was the one I already knew! :-) It
was already answered 2-3 times on the list! :-)
My question is: I get the HttpRequest from Hivemind but when I get the
InputStream, it's empty... is.available() returns 0 bytes while I know
(ethreal sniffing) that data is there!
That arise only when th client send the data in Transfer-Encoding:
chunked mode, if it just sets the Content-Length: field, that's fine.
Any idea how to handle the chunked mode?
-jec
Raul Raja Martinez wrote:
Yes in fact it has been answered by me an other people like 5 or 6
times already.
I can write a howto for getting a hold of the response , request and
other services from pages, components and custom services if people
think it is a good idea.
James Carman wrote:
This should maybe go into an FAQ or on the Wiki somewhere. I've seen
this
same question 3 times since I joined this list (not too long ago).
-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Raul Raja Martinez
Sent: Saturday, March 18, 2006 6:32 PM
To: [email protected]
Subject: Re: Getting raw POST data
Just provide this:
private HttpServletRequest request;
public void setHttpServletRequest(HttpServletRequest request) {
this.request = request;
}
Hivemind will autowire the request to your service so that you can
use it like if you were dealing with a Servlet.
best regards.
Raul Raja.
Jean-Eric Cuendet wrote:
Hi,
I have a tapestry service but would like to access the raw data from
the POST http request. Is that possible?
If I do
getRequest().getInputStream() then inputStream.available() returns 0
...
I tried reset() on IS but it throw an exception saying it's not
supported...
Thanks for any info.
-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]
---------------------------------------------------------------------
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]