Search code examples
javahttp-unit

Two form submissions in the same packet


I have the following code in my test:

WebResponse response = webConversation.getResponse(loginUrl);
System.err.println("Session ID:" + webConversation.getCookieValue("JSESSIONID"));
WebForm form = response.getFormWithID(loginFormId);
for(String parmName: form.getParameterNames()){
  if(loginDayName.equals(parmName)){
    form.setParameter(parmName, day);
  }
  else if(loginMonthName.equals(parmName)){
    form.setParameter(parmName, month);
  }
  else if(loginYearName.equals(parmName)){
    form.setParameter(parmName, year);
  }
  else if(loginPersonIdName.equals(parmName)){
    form.setParameter(parmName, person.getPersonId());
  }
}

response = form.submit();
System.err.println(response.getText());

So the first call to login URL should return the form. I then change the parameters and submit the form back to the same servlet from whence it came.

Debugs in the Controller indicate that I am getting the form data twice with two session IDs. The second one is the session ID that matches my webConversation and always fails because the first one actually logs that person in.

This is the only form.submit() in my test at the moment.

I am mystified. Am I using the tool wrong? Or is this a bug?


Solution

  • I ended up switching to html unit because problems like this appear to be normal for this older project.