5 Replies Latest reply on Sep 18, 2008 2:03 PM by Stan Silvert

    Seam Identity is null

    Scott Olcott Newbie

      When trying to run a jsf unit integration on a seam project I always get a NPE with the following stack trace:

      java.lang.NullPointerException
       at org.jboss.seam.web.IdentityRequestWrapper.getUserPrincipal(IdentityRequestWrapper.java:32)
       at org.jboss.seam.web.IdentityRequestWrapper.getRemoteUser(IdentityRequestWrapper.java:27)
       at com.sun.faces.context.ExternalContextImpl.getRemoteUser(ExternalContextImpl.java:440)
       at org.jboss.jsfunit.context.JSFUnitExternalContext.<init>(JSFUnitExternalContext.java:85)
       at org.jboss.jsfunit.context.JSFUnitFacesContext.release(JSFUnitFacesContext.java:190)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:262)
       at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
       at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1097)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
       at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:38)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
       at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
       at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
       at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
       at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
       at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
       at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
       at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
       at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
       at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
       at org.mortbay.jetty.Server.handle(Server.java:324)
       at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
       at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
       at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
       at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
       at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
       at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
       at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)


      This happens when I run it with maven and cargo using tomcat and when I access it through a browser.

      Here is my unit test.

      import java.io.IOException;
      
      import junit.framework.Assert;
      import junit.framework.TestSuite;
      
      import org.apache.cactus.ServletTestCase;
      import org.jboss.jsfunit.jsfsession.JSFClientSession;
      import org.jboss.jsfunit.jsfsession.JSFServerSession;
      import org.jboss.jsfunit.jsfsession.JSFSession;
      import org.xml.sax.SAXException;
      
      public class Test extends ServletTestCase {
      
       public static junit.framework.Test suite() {
       return new TestSuite(Test.class);
       }
      
       private JSFSession session;
       private JSFClientSession client;
       private JSFServerSession server;
      
       /**
       * Start a JSFUnit session by getting the /index.faces page. Note that
       * because setUp() is called before each test, a new HttpSession will be
       * created each time a test is run.
       */
       public void setUp() throws IOException, SAXException
       {
       session = new JSFSession("/home.seam");
       client = session.getJSFClientSession();
       server = session.getJSFServerSession();
       }
      
       public void testInitialPage() throws IOException, SAXException {
      
       System.out.println("--------------------------" + server.getCurrentViewID());
       Assert.assertEquals("/home.xhtml", server.getCurrentViewID());
       }
      
      }