2 Replies Latest reply on Jun 10, 2008 9:34 PM by Brian Gregory

    Strange NPE when re-making the WebConversation

    Brian Gregory Newbie

      Ok, I have a form login for CMS (Container managed security) and I'm attempting to write a test that logs in with a certain user account, and then later in the test it will log in as a different user.

      Here is some example code:

      public class BugTestCase extends ServletTestCase {
      
       private String LOGIN_PAGE_URL = "/session/login.jsp";
      
       private WebConversation wc;
       private JSFClientSession client;
       private JSFServerSession server;
       private RichFacesClient rfClient;
      
       protected WebConversation login(String userName, String password)
       throws MalformedURLException, IOException, SAXException {
      
       WebConversation wc = WebConversationFactory.makeWebConversation();
       WebResponse wr = wc.getResponse(WebConversationFactory.getWARURL() + LOGIN_PAGE_URL);
      
       WebForm loginform = wr.getFormWithID("loginForm");
       loginform.setParameter("j_username", userName);
       loginform.setParameter("j_password", password);
       wr = loginform.submit();
      
       return wc;
       }
      
       protected void doLogin( String userName, String password, String url) throws MalformedURLException, IOException, SAXException {
      
       // Perform CMS login
       this.wc = login( userName, password);
       // Create JSFUnit support classes
       this.client = new JSFClientSession(wc, url);
       this.server = new JSFServerSession(client);
       this.rfClient = new RichFacesClient(client);
      
       }
      
       public void testDoubleLoginTest() throws MalformedURLException, IOException, SAXException {
      
       // Login the first time
       this.doLogin("login1", "passw1", "/session/welcome.faces");
      
       // Some other test code here
      
       // This one will fail, why?
       this.doLogin("login2", "passw2", "/session/welcome.faces");
       }
      }
      


      It uses the WebConversationFactory and getResponse() to load the JSP login form, submit it with the proper credentials, and then create the JSFClientSession, etc. from that WebResponse.

      For some reason, on the second attempt, I get the following NPE:

      Error on HTTP request: 404 /webapp/session/j_security_check [http://localhost:8080/webapp/session/j_security_check]
      
      com.meterware.httpunit.HttpNotFoundException: Error on HTTP request: 404 /webapp/session/j_security_check [http://localhost:8080/webapp/session/j_security_check]
      at com.meterware.httpunit.WebClient.validateHeaders(WebClient.java:575)
      at com.meterware.httpunit.WebClient.updateClient(WebClient.java:464)
      at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:139)
      at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:130)
      at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
      at com.meterware.httpunit.WebWindow.sendRequest(WebWindow.java:110)
      at com.meterware.httpunit.WebRequestSource.submitRequest(WebRequestSource.java:253)
      at com.meterware.httpunit.WebRequestSource.submitRequest(WebRequestSource.java:232)
      at com.meterware.httpunit.WebForm.submitRequest(WebForm.java:96)
      at com.meterware.httpunit.WebForm.doFormSubmit(WebForm.java:107)
      at com.meterware.httpunit.WebForm.submit(WebForm.java:69)
      at com.meterware.httpunit.WebForm.submit(WebForm.java:58)
      at my.package.BugTestCase.login(BugTestCase.java:35)
      at my.package.BugTestCase.doLogin(BugTestCase.java:43)
      at my.package.BugTestCase.testDoubleLoginTest(BugTestCase.java:56)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
      at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224)
      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
      at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
      at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
      at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
      at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
      at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
      at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:122)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
      at java.lang.Thread.run(Thread.java:595)
      




        • 1. Re: Strange NPE when re-making the WebConversation
          Stan Silvert Master

          Well, it's not an NPE, but rather a 404 on j_security_check. Why you get a 404 on that page is probably container-dependent.

          But I think the problem is that JSFUnit continues to use the same session for each WebConversation created with the WebConversationFactory. When you create a new WebConversation with the factory, it only clears the session but doesn't create a new one. I won't go into why, but I've thought about ways to deal with the problem so that you can have more than one user logged in during a JSFUnit test.

          For your test to run correctly, I think you will just need to make sure that the first user is logged out before the second one logs in.

          Right now, the only way to log in more than one user at a time is to have only one be the "JSFUnit" user.

          The other users would be logged in using a plain WebConversation that is not created using the WebConversationFactory. You would just say "new WebConversation()" for those secondary users. And, you would need to use the plain HttpUnit API for them.

          Stan

          • 2. Re: Strange NPE when re-making the WebConversation
            Brian Gregory Newbie

            Sorry, I was thinking one thing while typing another (NPE reference in the title). Actually, I only need to make sure the 2nd users can log in, not actually use those users for testing (good call) so I think I can use your workaround. TX

            Brian