You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Fischereit, Jana" <ja...@classix.de> on 2011/04/19 12:14:56 UTC

Setting the maxHTTPHeaderSize to 'infinity'

Hi,

I would like to send xml-files by using the http-post request-body. But I read that the default maxHTTPHeaderSize is 8kb (http://tomcat.apache.org/tomcat-6.0-doc/config/http.html#Standard_Implementation). So I cannot transfer files of arbitrary size.

Why is there a limit? May problems occur by increasing that size to for example 20 mb?

And if there are no problems, how can I set this parameter to 'infinity'? I tried to use "-1" in the server.xml file, but recieved a java.lang.NegativeArraySizeException:

<port="8080" protocol="HTTP/1.1" maxHttpHeaderSize="-1" redirectPort="8443"/>


I am using Tomcat 6.0.32, Windows XP Professional SP3, Sun Java 1.6.0 Update 24.



Thanks and Regards,


Jana

Re: AW: AW: Setting the maxHTTPHeaderSize to 'infinity'

Posted by André Warnier <aw...@ice-sa.com>.
Fischereit, Jana wrote:
> Hi,
> 
> I resolved my problem. The problem was that the method request.getInputStream().read() just finish reading the in the server.xml file defined maxHTTPHeaderSize of the inputStream. So I wrote my own method to read the inputsteam and everything works fine. 
> 
> Besides I changed my client-side to multipartFileUpload (like the example from the previous posted link: http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/MultipartFileUploadApp.java?view=markup)
> 
That sounds very bizarre.
If you use a multipart file upload, and you read the request body yourself on the server 
side, then you should be getting funny things in the uploaded file.
Have you checked it ?


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


AW: AW: Setting the maxHTTPHeaderSize to 'infinity'

Posted by "Fischereit, Jana" <ja...@classix.de>.
Hi,

I resolved my problem. The problem was that the method request.getInputStream().read() just finish reading the in the server.xml file defined maxHTTPHeaderSize of the inputStream. So I wrote my own method to read the inputsteam and everything works fine. 

Besides I changed my client-side to multipartFileUpload (like the example from the previous posted link: http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/MultipartFileUploadApp.java?view=markup)

Thank you for your help!

Jana

-----Ursprüngliche Nachricht-----
Von: André Warnier [mailto:aw@ice-sa.com] 
Gesendet: Dienstag, 19. April 2011 16:10
An: Tomcat Users List
Betreff: Re: AW: Setting the maxHTTPHeaderSize to 'infinity'

Pid wrote:
> On 4/19/11 12:20 PM, André Warnier wrote:
>> Hi.
>>
>> I will let someone else comment on your code.
> 
> I can say that doesn't look like i'd expect it to, per the example code
> from the Commons HTTP 3.x or HTTP Client 4.x versions.
> 
> 
> 
>> (But remember, this is a help forum for Tomcat, which is the server
>> side.  It is not really a forum to help people write Java HTTP cients).
>>
>> It looks like this is your first try at sending a file to a server.
>> So let me recommend something :
>>
>> I would start by creating a simple HTML form with an <input type="file"
>> ..>, and then make sure that it works using the form.
>> (Because, to upload a file, you also need to have some special code on
>> the server to receive it, and you had better make sure that that side is
>> working first).
> 
> +1
> 
>> You can find an example here :
>> http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/tomcat/util/http/fileupload/package-summary.html
>>
>> and maybe someone else can suggest more examples somewhere.
> 
> http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/MultipartFileUploadApp.java?view=markup
> 
> 

Lest Jana would get confused :
The first link above points to an example for the server code needed (the servlet which 
receives the file upload POST).
The second example is one for the client side : the workstation Java program which uploads 
a file to a server, via a POST request.


> p
> 
>> Then, once it is working with the form, attack the client side.
>> If you search a bit on Google, you will find several examples of how to
>> do this right.
>> No need to re-invent the wheel.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> 
> 


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

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


Re: AW: Setting the maxHTTPHeaderSize to 'infinity'

Posted by André Warnier <aw...@ice-sa.com>.
Pid wrote:
> On 4/19/11 12:20 PM, André Warnier wrote:
>> Hi.
>>
>> I will let someone else comment on your code.
> 
> I can say that doesn't look like i'd expect it to, per the example code
> from the Commons HTTP 3.x or HTTP Client 4.x versions.
> 
> 
> 
>> (But remember, this is a help forum for Tomcat, which is the server
>> side.  It is not really a forum to help people write Java HTTP cients).
>>
>> It looks like this is your first try at sending a file to a server.
>> So let me recommend something :
>>
>> I would start by creating a simple HTML form with an <input type="file"
>> ..>, and then make sure that it works using the form.
>> (Because, to upload a file, you also need to have some special code on
>> the server to receive it, and you had better make sure that that side is
>> working first).
> 
> +1
> 
>> You can find an example here :
>> http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/tomcat/util/http/fileupload/package-summary.html
>>
>> and maybe someone else can suggest more examples somewhere.
> 
> http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/MultipartFileUploadApp.java?view=markup
> 
> 

Lest Jana would get confused :
The first link above points to an example for the server code needed (the servlet which 
receives the file upload POST).
The second example is one for the client side : the workstation Java program which uploads 
a file to a server, via a POST request.


> p
> 
>> Then, once it is working with the form, attack the client side.
>> If you search a bit on Google, you will find several examples of how to
>> do this right.
>> No need to re-invent the wheel.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> 
> 


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


Re: AW: Setting the maxHTTPHeaderSize to 'infinity'

Posted by Pid <pi...@pidster.com>.
On 4/19/11 12:20 PM, André Warnier wrote:
> Hi.
> 
> I will let someone else comment on your code.

I can say that doesn't look like i'd expect it to, per the example code
from the Commons HTTP 3.x or HTTP Client 4.x versions.



> (But remember, this is a help forum for Tomcat, which is the server
> side.  It is not really a forum to help people write Java HTTP cients).
> 
> It looks like this is your first try at sending a file to a server.
> So let me recommend something :
> 
> I would start by creating a simple HTML form with an <input type="file"
> ..>, and then make sure that it works using the form.
> (Because, to upload a file, you also need to have some special code on
> the server to receive it, and you had better make sure that that side is
> working first).

+1

> 
> You can find an example here :
> http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/tomcat/util/http/fileupload/package-summary.html
> 
> and maybe someone else can suggest more examples somewhere.

http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/MultipartFileUploadApp.java?view=markup


p

> Then, once it is working with the form, attack the client side.
> If you search a bit on Google, you will find several examples of how to
> do this right.
> No need to re-invent the wheel.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 



Re: AW: Setting the maxHTTPHeaderSize to 'infinity'

Posted by André Warnier <aw...@ice-sa.com>.
Hi.

I will let someone else comment on your code.
(But remember, this is a help forum for Tomcat, which is the server side.  It is not 
really a forum to help people write Java HTTP cients).

It looks like this is your first try at sending a file to a server.
So let me recommend something :

I would start by creating a simple HTML form with an <input type="file" ..>, and then make 
sure that it works using the form.
(Because, to upload a file, you also need to have some special code on the server to 
receive it, and you had better make sure that that side is working first).

You can find an example here :
http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/tomcat/util/http/fileupload/package-summary.html
and maybe someone else can suggest more examples somewhere.

Then, once it is working with the form, attack the client side.
If you search a bit on Google, you will find several examples of how to do this right.
No need to re-invent the wheel.


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


AW: Setting the maxHTTPHeaderSize to 'infinity'

Posted by "Fischereit, Jana" <ja...@classix.de>.
Thank you for your answer!

First I also thought that they have nothing to do with one another. But when I tried to transfer a xml-file (size 9kb) it did not work. Afterwards I increased the maxHTTPHeaderSize to 10 kb. So I concluded that the xml-stream is contained in the body of the request-header. 

Here is my java-code I am using to transfer the file to the server:

public static void main(String[] args) {

		OutputStream os = null;
		InputStream is = null;

		try {

			URL url = new URL(args[0]);
			String urlString = url.toString();
			String reportFile = args[1];
			String dataSourceFile = args[2];

			System.out.println("\nURL:  " + args[0]);
			System.out.println("ReportFile:  " + args[1]);
			System.out.println("DataSourceFile: " + args[2]);

			// Prepare HTTP post
			PostMethod post = new PostMethod(urlString);

			File file = new File(dataSourceFile);
			InputStreamRequestEntity requestEntity = new   InputStreamRequestEntity(
					new FileInputStream(dataSourceFile), file.length());
			post.setFollowRedirects(false);
			post.setRequestEntity(requestEntity);

			// Specify content type and encoding
			post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");

			post.addRequestHeader("reportFile=", reportFile);
			post.addRequestHeader("xmlFileSize=", file.length() + "");

			HttpClient httpclient = new HttpClient();

			// Execute request
			try {

				int result = httpclient.executeMethod(post);
				System.out.println("Is post-request sent?: " + post.isRequestSent());

				// Display status code
				System.out.println("Response status code: " + result);

				// Redirect by using a get-method
				URI uri = url.toURI();
				Desktop.getDesktop().browse(uri);

			} catch (Exception ex) {
				System.out.println("\nError: " + ex);
			} finally {
				post.releaseConnection();
			}

		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


The post.setRequestBody(body) is deprecated and post.setRequestEntity(requestEntity) should be used instead. I tried the deprecated method as well, but received the same results.

-----Ursprüngliche Nachricht-----
Von: André Warnier [mailto:aw@ice-sa.com] 
Gesendet: Dienstag, 19. April 2011 12:28
An: Tomcat Users List
Betreff: Re: Setting the maxHTTPHeaderSize to 'infinity'

Fischereit, Jana wrote:
> Hi,
> 
> I would like to send xml-files by using the http-post *request-body*. 

(emphasis added)


But I read that the default maxHTTPHeaderSize is 8kb

max HTTP *Header* Size  (emphasis added)

Nothing to do with one another.



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

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


Re: Setting the maxHTTPHeaderSize to 'infinity'

Posted by André Warnier <aw...@ice-sa.com>.
Fischereit, Jana wrote:
> Hi,
> 
> I would like to send xml-files by using the http-post *request-body*. 

(emphasis added)


But I read that the default maxHTTPHeaderSize is 8kb

max HTTP *Header* Size  (emphasis added)

Nothing to do with one another.



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