Click to See Complete Forum and Search --> : How to get something more than HttpServletRequest?


krzysieq
06-06-2006, 12:58 PM
Hi all. There's a thingy that bothers me. Is there any way to get the pure request code out of a HttpServletRequest object in a Java servlet? Or is it that all I can get is simply this and nothing more? I'm interested in getting my hands on xml that is, or least - might be -, inside that pure request. Please help.

Thanks a lot.
krzysieq

Khalid Ali
06-06-2006, 01:21 PM
confused....u can try to print the request and see whats in it...

krzysieq
06-06-2006, 01:28 PM
You mean trying "req.toString()" ?? Does no good - just gives some object information, but not the request itself. Or did You mean something else?

Khalid Ali
06-06-2006, 01:38 PM
I meant..get the input stream and print that out...

krzysieq
06-07-2006, 03:23 AM
I tried the following code:

ServletInputStream str = req.getInputStream();
StringBuffer sb = new StringBuffer();
byte b[] = new byte[LINE_LENGTH];
int offset = 0;
while (str.readLine(b,offset,LINE_LENGTH) != -1) {
l.debug("service(): stream read something.");
sb.append(b);
offset += LINE_LENGTH;
}
l.debug("service(): input stream: " + sb);

LINE_LENGTH is set to 80. The sb variable is empty, and the log message "stream read something" does not appear in the logfile. The other message does, but it contains nothing except "service(): input stream:" text. What am I doing wrong? I'm using Tomcat servlet api.

chazzy
06-07-2006, 12:58 PM
what exactly are you trying to accomplish though? do you want the response code of the request? ie 200 ok, 404 not found, 403 forbidden etc?

krzysieq
06-07-2006, 02:57 PM
I'm trying to get my hands on the pure code of the request. Nothing more. I don't give a damn about what's in it - error codes or anything.

Khalid Ali
06-07-2006, 05:29 PM
oh...my bad I guess u want to see what http headers are there ...for that u can use request.getHeaderNames(). Read the API...:-)

krzysieq
06-08-2006, 02:50 AM
Ok, I think I didn't express myself clearly enough - my fault, sorry. What I want is to get - basically what Khalid wrote (reading my mind, aren't You?) - the set of headers. The thing is I'm trying to implement the webdav extensions to html, which is an xml-based protocol. So I'm trying to figure out a way to get my hands on the xml, in which the requests should be encoded. If I'm heading the wrong way though, please, redirect me :)