users@glassfish.java.net

Re: I want to test Max Post Size and want to see "Post too large

From: <forums_at_java.net>
Date: Tue, 5 Apr 2011 04:34:03 -0500 (CDT)

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


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