Re: Newbie -> why my servlet is being invoked twice?

Mustafa Cayci <[email protected]> Thu, 5 May 2011 02:13:31 -0700 (PDT)
Newsgroups gmane.comp.web.httpunit.devel
Message-ID <[email protected]>
Hello again,

I was going over the old posts on this issue.  One more person had the same 
problem.  The problem is to do with WebForm.submit() is invoking twice (or the 
user calls it "double").  And Wolfgang (sp?) said that it was a bug and fixed in 
the trunk in Subversion.  I cannot access to Subversion URL he posted because my 
customer network does not allow it.  Is there anyway to get the httpunit.jar 
emailed to us? It is not very big.

Thanks,
Mustafa



----- Original Message ----
From: Mustafa Cayci <[email protected]>
To: [email protected]
Sent: Wed, May 4, 2011 11:31:30 AM
Subject: Newbie -> why my servlet is being invoked twice?

Hello,

I am new to HttpUnit.  I wrote a simple servlet.  It is simply querying some 
records in a table. I put a print statement that prints if the session is new or 

not and time to take to retrieve information from database.  I put this code in 
doGet().  I have doPost() as follows:

  public void doPost(HttpServletRequest req, HttpServletResponse res) {
    doGet(req, res);
  }


I wrote a TestSuite as follows

public class RowSetsTest extends TestCase {
  public RowSetsTest(String string) {
    super(string);
  }

  public RowSetsTest() {
    super();
  }

  public static TestSuite suite() {
    TestSuite suite = new TestSuite();
    TestCase test = new RowSetsTest("testGetForm");
    suite.addTest(test);
    return suite;
  }

  public static void main(String[] args) {
    junit.textui.TestRunner.run(suite());
  }

  public void testGetForm() throws Exception {
    ServletRunner sr = new ServletRunner();
    sr.registerServlet("RowSetsServlet", RowSetsServlet.class.getName());
    WebConversation webConversation = new WebConversation();
    //for (int i = 0; i < 1; i++) {
      WebResponse loginResponse =
        webConversation.getResponse("http://localhost:7777/TestServlet/");
      assertEquals("Login Page for Examples", loginResponse.getTitle());
      loginResponse.getForms()[0].setParameter("j_username",
                                               "Test");
      loginResponse.getForms()[0].setParameter("j_password", "tes");
      WebResponse homePage = loginResponse.getForms()[0].submit();
      homePage.close();
    //}
  }
}


If I open a browser and invoke the above URL, I only see two print statements


Session is New
weblogic.servlet.jsp
Session is: false
Average Time: 3

If I run the above test code, I am seeing the following

Session is New
weblogic.servlet.jsp
Session is: false
Average Time: 3
Session is: false <--------
Average Time: 3  <---------

As you see I see two sets of print statements.  This tells me that the servlet 
(doGet()) is being invoked twice.  Is that correct?

Thanks in advance,
Mustafa


------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd