Newbie -> why my servlet is being invoked twice?

Mustafa Cayci <[email protected]> Wed, 4 May 2011 08:31:30 -0700 (PDT)
Newsgroups gmane.comp.web.httpunit.devel
Message-ID <[email protected]>
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