• Post Reply Bookmark Topic Watch Topic
  • New Topic

HTTP POST body gets truncated

 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a servlet which processes HTTP body in the doPost method. The body contains a XML file.

I am using a Java client to send the XML file in the HTTP Body. If the file is larger than 4KB the servlet is not able to receive the complete file in the HTTP body i.e. body is truncated.

The servlet is running in Tomcat v 5 web container. Is there any setting in the Tomcat container that I need to change so that the body is not truncated.
Thanks,
Pradip
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have doubts. Have you run a proxy (tunnelGUI or similar) in the middle to see if the request is being sent? Personally I think it sounds like you may not be reading it correctly (is your buffer big enough?) and only be reading that much.
 
Debashish Chakrabarty
Ranch Hand
Posts: 231
Firefox Browser Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure but this may also be related to HTTP chunking. I once had faced the problem during my stint on J2ME. See if this helps. I also blogged about the problem I faced, here. A solution that you may try is setting the content-length explicitly, as advised here. Do let us know if it worked.
[ December 13, 2005: Message edited by: Debashish Chakrabarty ]
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DOM,

I will try with tunnelGUI .TCPMon does not work in my m/c for some reason (may be because I am using Java5). I am reading the HTTP body completely and then parse the XML. Which buffer length are you talking about.


Debashish ,

I have tried setting content-length explicitly at the client side connection.setRequestProperty("Content-Length",xxx); It did not work.

Thanks.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the request reading part?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was finally able to setup tcpmon. I was able to see the complete XML being sent.

DOM,

Here is the code




Is something wrong with the content length?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote the HTTP Body string to a file from the servlet. All characters from position 4KB are logges as NULL(0)character.

In tcpmon I can clearly see all characters. The length of XML file is about 7KB.
[ December 13, 2005: Message edited by: Pradip Bhat ]
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved the problem.

The line req.getReader().read(cbuf); was not reading all characters in one go. I had ignored the int return value and assumed that all characters will be read.

Thanks guys.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was I was assuming, sorry I didn't get a chance to look closer, but I'm glad you worked it out and thanks for getting back to us


Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!