You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michele Fuortes <mf...@med.cornell.edu> on 2008/08/07 20:18:28 UTC

Problem with POST to servlet: 16384 bytes maximum?

Hi,

I have a problem with POSTing an XML file to a servlet which writes  
the XML to disk. If the XML file is less than 16384 bytes all goes  
well. If it's bigger the first 16384 bytes are written correctly, the  
rest all all 00s. The lenght of the file is the correct one as in the  
Content-Length: http header.

The servlet is very simple (I did not write it), the relevant parts are:

		File file;
		FileOutputStream out2;
		DataOutputStream out3;
......
		file = new File(req.getRealPath(filePath));
		out2 = new FileOutputStream(file);
		out3 = new DataOutputStream(out2);
......
		bytesAvailable=req.getContentLength();
		byte[] theBytes=new byte[bytesAvailable];
		in.read(theBytes);
		out3.write(theBytes,0,bytesAvailable);
		out3.flush();
....

Can anyone help? Is there a buffer limit somewhere that I have to  
change.
I'm using Apache 2.063/Tomcat/4.1.29-LE-jdk14 on MacOS 10.5.3

Thanks

Michele Fuortes


--
Michele Fuortes, M.D., Ph.D.
Assistant Professor
Department of Cell and Developmental Biology
Cornell University  - Weill Medical College
E-mail: mfuortes@med.cornell.edu





---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem with POST to servlet: 16384 bytes maximum?

Posted by Warren Killian <wa...@gmail.com>.
Hi,

If you can't get past this limitation, you might look into the Apache
Commons "file upload" utility.  It is an API specifically for allowing
(large) file uploads to a server.  It works great, has a simple API and some
decent documentation as well.  Hope this helps.

On Thu, Aug 7, 2008 at 2:18 PM, Michele Fuortes <mf...@med.cornell.edu>wrote:

> Hi,
>
> I have a problem with POSTing an XML file to a servlet which writes the XML
> to disk. If the XML file is less than 16384 bytes all goes well. If it's
> bigger the first 16384 bytes are written correctly, the rest all all 00s.
> The lenght of the file is the correct one as in the Content-Length: http
> header.
>
> The servlet is very simple (I did not write it), the relevant parts are:
>
>                File file;
>                FileOutputStream out2;
>                DataOutputStream out3;
> ......
>                file = new File(req.getRealPath(filePath));
>                out2 = new FileOutputStream(file);
>                out3 = new DataOutputStream(out2);
> ......
>                bytesAvailable=req.getContentLength();
>                byte[] theBytes=new byte[bytesAvailable];
>                in.read(theBytes);
>                out3.write(theBytes,0,bytesAvailable);
>                out3.flush();
> ....
>
> Can anyone help? Is there a buffer limit somewhere that I have to change.
> I'm using Apache 2.063/Tomcat/4.1.29-LE-jdk14 on MacOS 10.5.3
>
> Thanks
>
> Michele Fuortes
>
>
> --
> Michele Fuortes, M.D., Ph.D.
> Assistant Professor
> Department of Cell and Developmental Biology
> Cornell University  - Weill Medical College
> E-mail: mfuortes@med.cornell.edu
>
>
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Problem with POST to servlet: 16384 bytes maximum?

Posted by Konstantin Kolinko <kn...@gmail.com>.
2008/8/7 Michele Fuortes <mf...@med.cornell.edu>:
> Hi,
>
> I have a problem with POSTing an XML file to a servlet which writes the XML
> to disk. If the XML file is less than 16384 bytes all goes well. If it's
> bigger the first 16384 bytes are written correctly, the rest all all 00s.
> The lenght of the file is the correct one as in the Content-Length: http
> header.
>
> The servlet is very simple (I did not write it), the relevant parts are:
>
>                File file;
>                FileOutputStream out2;
>                DataOutputStream out3;
> ......
>                file = new File(req.getRealPath(filePath));
>                out2 = new FileOutputStream(file);
>                out3 = new DataOutputStream(out2);
> ......
>                bytesAvailable=req.getContentLength();
>                byte[] theBytes=new byte[bytesAvailable];
>                in.read(theBytes);
>                out3.write(theBytes,0,bytesAvailable);
>                out3.flush();
> ....
>
> Can anyone help?

The problem with the above code is that you (or the author of that code,
if you are not the one) do ignore the return value of InputStream.read()
call.

That value will be the exact count of bytes that were read into your
buffer in that call of InputStream.read().

You have just demonstrated that one cannot read all contentLength
bytes of data in one call.

The easiest fix here will be to use a loop, see Christopher Schultz's
message for an example.


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem with POST to servlet: 16384 bytes maximum?

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
----- Original Message ----- 
From: "Michele Fuortes" <mf...@med.cornell.edu>
To: <us...@tomcat.apache.org>
Sent: Thursday, August 07, 2008 8:18 PM
Subject: Problem with POST to servlet: 16384 bytes maximum?


> Hi,
>
> I have a problem with POSTing an XML file to a servlet which writes  the 
> XML to disk. If the XML file is less than 16384 bytes all goes  well. If 
> it's bigger the first 16384 bytes are written correctly, the  rest all all 
> 00s. The lenght of the file is the correct one as in the  Content-Length: 
> http header.
>
> The servlet is very simple (I did not write it), the relevant parts are:
>
> File file;
> FileOutputStream out2;
> DataOutputStream out3;
> ......
> file = new File(req.getRealPath(filePath));
> out2 = new FileOutputStream(file);
> out3 = new DataOutputStream(out2);
> ......
> bytesAvailable=req.getContentLength();
> byte[] theBytes=new byte[bytesAvailable];
> in.read(theBytes);
> out3.write(theBytes,0,bytesAvailable);
> out3.flush();
> ....
>
> Can anyone help? Is there a buffer limit somewhere that I have to  change.
> I'm using Apache 2.063/Tomcat/4.1.29-LE-jdk14 on MacOS 10.5.3
>
> Thanks
>
> Michele Fuortes
>
>
> --
> Michele Fuortes, M.D., Ph.D.
> Assistant Professor
> Department of Cell and Developmental Biology
> Cornell University  - Weill Medical College
> E-mail: mfuortes@med.cornell.edu

Michele... check this out... the default POST size is actually much 
larger...
I suspect it may be an encoding problem.... whatever is sending that file 
must also encode it correctly...
If you try a diff XML file and this size changes.... its the issue.
Long time since I messed with this stuff... but I dont think a raw XML file 
will post...
XML is full of little gremlins that mean something to a url decoder if not 
encoded ;)

http://tomcat.apache.org/tomcat-5.5-doc/config/http.html

Other possibility is theres a funny with the https... try do a normal http 
just to elim that as well..

Good luck...

---------------------------------------------------------------------------
HARBOR : http://www.kewlstuff.co.za/index.htm
The most powerful application server on earth.
The only real POJO Application Server.
See it in Action : http://www.kewlstuff.co.za/cd_tut_swf/whatisejb1.htm
--------------------------------------------------------------------------- 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem with POST to servlet: 16384 bytes maximum?

Posted by André Warnier <aw...@ice-sa.com>.
Michele Fuortes wrote:
> Hi,
> 
> I have a problem with POSTing an XML file to a servlet which writes the 
> XML to disk. If the XML file is less than 16384 bytes all goes well. If 
> it's bigger the first 16384 bytes are written correctly, the rest all 
> all 00s. The lenght of the file is the correct one as in the 
> Content-Length: http header.
> 
1) How do you POST the data ? I mean what is the client-side application 
which composes and sends the POST ?
2) this may help :
http://forums.sun.com/thread.jspa?messageID=2344227

André

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem with POST to servlet: 16384 bytes maximum?

Posted by Mark Thomas <ma...@apache.org>.
Sam Wun wrote:
> Hi,
> 
> I am wondering how to fix the following attached error (mvn command run)?
> I tried to follow the instruction shown in the following website, but got error.
> http://struts.apache.org/2.x/docs/developing-a-portlet-using-eclipse.html

1. Don't hijack threads.
2. Read the FAQ, particularly http://wiki.apache.org/tomcat/FAQ/Tomcat_User
3. Try asking on the right list.

Mark


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem with POST to servlet: 16384 bytes maximum?

Posted by Sam Wun <sw...@gmail.com>.
Hi,

I am wondering how to fix the following attached error (mvn command run)?
I tried to follow the instruction shown in the following website, but got error.
http://struts.apache.org/2.x/docs/developing-a-portlet-using-eclipse.html


=========== attached mvn command run ===========
Maven version: 2.0.9
Java version: 1.6.0_10-beta
OS name: "windows vista" version: "6.0" arch: "x86" Family: "windows"

D:\workspace\samples\portlet>mvn archetype:create -DgroupId=com.mycompany.mypor
let \
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Invalid task '\': you must specify a valid lifecycle phase, or a goal in
the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Fri Aug 08 17:32:51 EST 2008
[INFO] Final Memory: 2M/4M
[INFO] ------------------------------------------------------------------------

D:\workspace\samples\portlet>mvn archetype:create -DgroupId=com.mycompany.mypor
let  -DartifactId=myportlet -DarchetypeGroupId=org.apache.struts  -DarchetypeAr
ifactId=struts2-archetype-portlet  -DarchetypeVersion=2.0.9-SNAPSHOT   -Dremote
epositories=http://people.apache.org/repo/m2-snapshot-repository
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetype:create] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexu
.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:create]
[WARNING] This goal is deprecated. Please use mvn archetype:generate instead
[INFO] Defaulting package to group ID: com.mycompany.myportlet
[INFO] We are using command line specified remote repositories: http://people.a
ache.org/repo/m2-snapshot-repository
[INFO] snapshot org.apache.struts:struts2-archetype-portlet:2.0.9-SNAPSHOT: che
king for updates from id0
Downloading: http://people.apache.org/repo/m2-snapshot-repository/org/apache/st
uts/struts2-archetype-portlet/2.0.9-SNAPSHOT/struts2-archetype-portlet-2.0.9-SN
PSHOT.jar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error creating from archetype

Embedded error: OldArchetype does not exist.
Unable to download the artifact from any repository
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10 seconds
[INFO] Finished at: Fri Aug 08 17:33:37 EST 2008
[INFO] Final Memory: 8M/15M
[INFO] ------------------------------------------------------------------------
Reply

Forward

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org