Skip to main content

I want to test Max Post Size and want to see "Post too large" related exception/error

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
12 replies [Last post]
babbarkrishan
Offline
Joined: 2007-01-18

Hi,
I am trying to understand the properties/configurations given under Network Config->Network Listners->http-listener-1->HTTP (Tab)
Like I am trying to see the affect of Max Post Size. What I did is change the value of Max Post Size to 1024 bytes and then try to upload files of 5 MB, 1 GB and so using form & multipart data. They all gets uploaded successfully. Then I created a textarea in the form and submit without multipart with a lot of text in textarea, it also get submitted.
Please let me know how can i test "Max Post Size"? What will be its affect?
Is there any relation between Max Post Size and size of file being uploaded?
Any reference where I can get the more details of properties/configurations?
What are the difference between following properties:
Timeout:
Connection Upload Timeout:
Request Timeout:
Best way to test all these properties?
Thanks
Krishan Babbar

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
oleksiys
Offline
Joined: 2006-01-25

Hi,

can you pls. send us HTTP request headers, which are getting sent to GF
when uploading files?

> Please let me know how can i test "Max Post Size"? What will be its
> affect?
> Is there any relation between Max Post Size and size of file being
> uploaded?
It's applied for posts with content-type
"application/x-www-form-urlencoded", which don't use chunked
transfer-encoding (use content-length).

> What are the difference between following properties:
>
> Timeout:
> Connection Upload Timeout:
This is used (if upload-timeout-enabled == true), to set max timeout
allowed when reading next chunk of uploaded data. This prevents server
from waiting too long for the next data chunk.

> Request Timeout:
This is used to limit time occupied by the single request processing.
Unlike the connection-upload-timeout, this timeout will be applied even
though client is actively sending data.

> Best way to test all these properties?
1) For upload-timeout-enabled, write a servlet which is saving client
post to the file.
On the client side send just part of data and then sleep... you should
see upload timeout occurred on the server.

2) For the request-timeout, call object.wait or thread.sleep with bigger
(let's say 1 year) parameter in the servlet code.
It will be interrupted after request-timeout expired.

WBR,
Alexey.

babbarkrishan
Offline
Joined: 2007-01-18

Hi Alexey,
I tried with following code for Max Post Size testing and it worked. When I tried to test Request timeout, it did not work. I changed the value of Request Timeout: to 30 seconds. Then using the same code below, I added Thread.sleep(120*1000) means sleep for 2 mins. Result was, it waits for 2 mins and then shows the success message in browser.
maxPostSizeTesting.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Max Post Size Testing</title>
</head>
<body>
<h2>Max Post Size Testing</h2>
<form method="post" action="maxPostSizeTesting">
<textarea name="myText">Test Data</textarea><br/>
<input type="submit" value="Test Now" />
</form>
</body>
</html>
MaxPostSizeTesting .java
package fileupload;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MaxPostSizeTesting extends HttpServlet {

/**
*
*/
private static final long serialVersionUID = 2182306580657399709L;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Here, we fetch the data in "myText" property which is a textarea.
// In case myText data is larger than the value of "Max Post Size" configuration of glassfish then it will throw IllegalStateException exception
PrintWriter out = null;
try {
System.out.println("Reading post data...");
System.out.println("My Text: " + request.getParameter("myText"));

Thread.sleep(120 * 1000); // added for Request Timeout testing
out = response.getWriter();
out.println("Data posted successfully...");
}
catch (InterruptedException ex) {
ex.printStackTrace();
System.out.println("InterruptedException Occurred");
}
catch (IllegalStateException ex) {
ex.printStackTrace();
System.out.println("IllegalStateException Occurred");
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("Exception Occurred");
}
finally {
if (out != null) {
out.close();
}
}
}
}

Also, I did not get the difference between "Timeout:" & "Connection Upload Timeout:" and testing method.
If possible then can you please refer and client code for posting some data and then sleep the thread for testing of Connection Upload Timeout.
Thanks
Krishan Babbar

oleksiys
Offline
Joined: 2006-01-25

Hi,

just tried your sample and i did see the request timeout appeared in 30
seconds (even though the response was 200OK, because you catch the
Exception), the GF server log contained this [1].

To reproduce upload-timeout, you can try to use something like telnet,
connect to the server post HTTP headers and then post just part of HTTP
POST content.

Thanks,

WBR,
Alexey.

[1]

[#|2011-04-06T11:17:51.070+0200|WARNING|glassfish3.1|com.sun.grizzly.config.GrizzlyServiceListener|_ThreadID=12;_ThreadName=Thread-1;|GRIZZLY0023:
Interrupting idle Thread: http-thread-pool-8080(3).|#]

[#|2011-04-06T11:17:51.074+0200|SEVERE|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=65;_ThreadName=Thread-1;|java.lang.InterruptedException:
sleep interrupted
at java.lang.Thread.sleep(Native Method)
at fileupload.MaxPostSizeTesting.doPost(MaxPostSizeTesting.java:26)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at
com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
|#]

[#|2011-04-06T11:17:51.076+0200|INFO|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=65;_ThreadName=Thread-1;|InterruptedException
Occurred|#]

babbarkrishan
Offline
Joined: 2007-01-18

Thanks Alexey,
Request timeout worked. I found that exception in the logs.
I was trying telnet for testing of connection-upload-timeout, but unable to test.
Can we connect telnet at localhost, as my web application is running on localhost for the time being?
I was trying something like given at http://fixunix.com/tcp-ip/66112-re-send-xml-request-server-telnet.html
Is it the right way?
If possible please provide some more details or steps for testing connection-upload-timeout.
Thanks
Krishan Babbar

oleksiys
Offline
Joined: 2006-01-25

Hi Krishan,

> I was trying telnet for testing of connection-upload-timeout, but
> unable to
> test.
>
> Can we connect telnet at localhost, as my web application is running on
> localhost for the time being?
>
> I was trying something like given at
> http://fixunix.com/tcp-ip/66112-re-send-xml-request-server-telnet.html
>
> Is it the right way?
>
> If possible please provide some more details or steps for testing
> connection-upload-timeout.
I've just checked, the upload-timeout forces servlet's InputStream to
return -1, after it expires. So it doesn't throw any Exception.
You can try this servlet code [1].
And do telnet [2] with content [3].

After upload-timeout milliseconds check the Glassfish server.log to see
how much time it took for servlet InputStream to return -1 (end of stream).

Thanks.

WBR,
Alexey.

[1]
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(request.getContentType());

final InputStream is = request.getInputStream();
final OutputStream os = response.getOutputStream();

final long t1 = System.currentTimeMillis();

byte[] buf = new byte[1024];
try {
int len;
while ((len = is.read(buf)) != -1) {
os.write(buf, 0, len);
os.flush();
}

System.out.println("-1 returned in" + ((int)
((System.currentTimeMillis() - t1) / 1000)) + " seconds");
} finally {

is.close();
os.close();
}
}

[2] telnet localhost 8080
[3]
POST /TestServlet/UploadTimeout HTTP/1.1
Host: localhost:8080
Content-length: 5000

AAAAAAAAA

>
> Thanks
>
> Krishan Babbar
>
>
> --
>
> [Message sent by forum member 'babbarkrishan']
>
> View Post: http://forums.java.net/node/788284
>
>

babbarkrishan
Offline
Joined: 2007-01-18

Thanks Alexey,
Below are given the Request Headers (taken from FireBug) for a file uploade.
Response Headersview source
X-Powered-By Servlet/3.0
Server GlassFish Server Open Source Edition 3.0.1
Content-Type text/html;charset=ISO-8859-1
Content-Length 165
Date Mon, 04 Apr 2011 05:55:09 GMT
Request Headersview source
Host localhost:9292
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:2.0) Gecko/20100101 Firefox/4.0
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Referer http://localhost:9292/FileUpload/uploadFilesTest.jsp
Cookie JSESSIONID=f13af1da6e1140e37b0155e1fd7b; __utma=111872281.882358747.1301335526.1301892901.1301895244.13; __utmz=111872281.1301335526.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
Thanks
Krishan Babbar

oleksiys
Offline
Joined: 2006-01-25

Hi,

as I mentioned max-post-size is only applied for content-type
"application/x-www-form-urlencoded", in the headers you sent it is
"text/html;charset=ISO-8859-1".

Thanks.

WBR,
Alexey.

babbarkrishan
Offline
Joined: 2007-01-18

Hi Alexey,
One more point, if Max Post Size is applied for content-type "application/x-www-form-urlencoded" only then why we can't upload file of 2GB or more than 2GB?
In case of file upload header showing content-type &quot;text/html;charset=ISO-8859-1".
Browser does not initiates the file upload in case of file size >= 2GB
I thought it was due to data type "int" for Max Post Size and hence its value can't be larger than 2147483647 bytes (1 less than 2 GB (2147483648 bytes)
Thanks
Krishan Babbar

oleksiys
Offline
Joined: 2006-01-25

> One more point, if Max Post Size is applied for content-type
> "application/x-www-form-urlencoded" only then why we can't upload file
> of 2GB
> or more than 2GB?
>
> In case of file upload header showing content-type
> "text/html;charset=ISO-8859-1".
>
> Browser does not initiates the file upload in case of file size >= 2GB
>
> I thought it was due to data type "int" for Max Post Size
You might be right, please try to get content-length like:
/Long.parseLong(request.getHeader("content-length"));/

instead of
/request.getContentLength();/

WBR,
Alexey.

> and hence its value
> can't be larger than Normal 0 false false false EN-US X-NONE X-NONE /*
> Style
> Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal";
> mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0;
> mso-style-noshow:yes;
> mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:"";
> mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in;
> mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt;
> mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan;
> font-size:11.0pt; font-family:"Cambria","serif";
> mso-ascii-font-family:Cambria; mso-ascii-theme-font:minor-latin;
> mso-fareast-font-family:"Times New Roman";
> mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Cambria;
> mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman";
> mso-bidi-theme-font:minor-bidi;} 2147483647 bytes Normal 0 false false
> false
> EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable
> {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0;
> mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99;
> mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in
> 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in;
> mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in;
> line-height:115%;
> mso-pagination:widow-orphan; font-size:11.0pt;
> font-family:"Cambria","serif";
> mso-ascii-font-family:Cambria; mso-ascii-theme-font:minor-latin;
> mso-fareast-font-family:"Times New Roman";
> mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Cambria;
> mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman";
> mso-bidi-theme-font:minor-bidi;} (1 less than 2 GB (2147483648 bytes)
>
> Thanks
>
> Krishan Babbar
>
>
> --
>
> [Message sent by forum member 'babbarkrishan']
>
> View Post: http://forums.java.net/node/788284
>
>

babbarkrishan
Offline
Joined: 2007-01-18

Yes Alexey!
Max Post Size tested successfully. Need to test timeout settings. Please see comment #2. Looking forward for your reply.
Thanks
Krishan Babbar

anilmsc
Offline
Joined: 2012-01-09

Dear Krishan,

In one of my web application, I need to limit the file size to 4MB. So I configured maxPostSize in tomcat/conf/server.xml as below:

<Connector port="10080" maxHttpHeaderSize="8192"
protocol="HTTP/1.1" URIEncoding="UTF-8"
connectionTimeout="20000"
redirectPort="8443" maxPostSize="4194304" />

Even after this change, I am able to upload the file more than 4MB. Tried the same using textarea, but I am not getting any exception. Can you pls. help me to resolve this issue. Very urgent for me.

I have set the response content type as follows in my servet:

response.setContentType("application/x-www-form-urlencoded");

Tomcat version is 6

Jdk is 1.6

IE is 7

Thanks & Regards

Anil

babbarkrishan
Offline
Joined: 2007-01-18

Dear Anil,

Please paste your code of servlet and server.xml.

I will test at my end and will let you know if I could debug that.

Thanks

Krishan Babbar