4 Replies Latest reply on Oct 15, 2008 10:39 AM by ssilvert

    JSFServerSession is null.

    priyeshp

      I am trying to test my JSF/Icefaces based application. I am using Websphere 6.1 as my server. I want to test the navigation flow of the pages. I have read the article the JSFUnit on Websphere I have also followed the steps specified in the artcile but still no luck. JSFServerSession server = jsfSession.getJSFServerSession();
      System.out.println(server.getCurrentViewID()); I get nullPointer Exception.
      Below is my code please let me know if this is a known Issue.

      import java.io.IOException;

      import javax.faces.component.UIComponent;

      import junit.framework.Test;
      import junit.framework.TestSuite;

      import org.apache.cactus.ServletTestCase;
      import org.jboss.jsfunit.framework.BasicAuthenticationStrategy;
      import org.jboss.jsfunit.framework.WebClientSpec;
      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 JSFUnitTest extends ServletTestCase {
      private JSFClientSession client;

      public static Test Suite() {
      return TestSuite(JSFUnit.class);
      }

      public void testInitialPage() throws IOException, SAXException {
      WebClientSpec wcSpec = new WebClientSpec("/index.iface");
      WebsphereRequestStrategy wrs = new WebSphereRequestStrategy();
      wcSpec.setInitialRequestStrategy(wrs);
      JSFSession jsfSession = new JSFSession(wcSpec);
      JSFClientSession client = jsfSession.getJSFClientSession();
      JSFServerSession server = jsfSession.getJSFServerSession();
      System.out.println(server.getCurrentViewID());
      assertEquals("/index.iface",server.getCurrentViewID());
      }
      }

      import java.io.IOException;

      import org.jboss.jsfunit.framework.WebClientSpec;

      import com.gargoylesoftware.htmlunit.Page;

      public class WebSphereRequestStrategy extends org.jboss.jsfunit.framework.SimpleInitialRequestStrategy {

      public Page doInitialRequest(WebClientSpec wcSpec) throws IOException {
      String jsessionId = wcSpec.removeCookie("JSESSIONID");
      wcSpec.addCookie("JSFSESSIONID", "0000" +jsessionid);

      return super.doInitialRequest(wcSpec);
      }
      }

      Please let me what steps I need to take to solve this error.

        • 1. Re: JSFServerSession is null.
          ssilvert

          Off hand, I don't see any problems in your code. You don't need to declare throws SAXException. Starting with Beta 3, it only throws IOException. You also have an unused private variable "private JSFClientSession client; "

          Can you post the full stack trace? That might give me a better clue.

          Stan

          • 2. Re: JSFServerSession is null.
            ssilvert

            I take that back. Here is your problem:

            wcSpec.addCookie("JSFSESSIONID", "0000" +jsessionid);


            It should be:

            wcSpec.addCookie("JSESSIONID", "0000" +jsessionid);


            Stan

            • 3. Re: JSFServerSession is null.
              priyeshp

              Sorry my bad. It was typo. I have JSESSIONID in my actual code. Here is the stack trace:

              java.lang.NullPointerException
              at org.jboss.jsfunit.jsfsession.JSFServerSession.getCurrentViewID(JSFServerSession.java:69)
              at com.web.JSFUnitTest.testInitialPage(JSFUnitTest.java:59)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:618)
              at junit.framework.TestCase.runTest(TestCase.java:168)
              at junit.framework.TestCase.runBare(TestCase.java:134)
              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:217)
              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.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost(JSFUnitServletRedirector.java:42)
              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 org.jboss.jsfunit.framework.JSFUnitServletRedirector.doGet(JSFUnitServletRedirector.java:48)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
              at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:990)
              at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:931)
              at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:145)
              at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:122)
              at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
              at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
              at com.highmark.base.user.UserContextFilter.doFilter(UserContextFilter.java:107)
              at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
              at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
              at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:112)
              at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
              at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
              at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
              at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
              at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:768)
              at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:676)
              at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:499)
              at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:473)
              at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3276)
              at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
              at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
              at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1455)
              at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:113)
              at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:454)
              at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:383)
              at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:263)
              at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
              at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
              at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
              at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
              at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
              at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
              at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
              at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
              at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
              at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)

              Please let me know if you need more information. Thanks for the quick response.

              • 4. Re: JSFServerSession is null.
                ssilvert

                I think the "0000" prefix (WebSphere cache ID) is probably wrong for your WebSphere server. See if you can find out what your JSESSIONID actually looks like. I don't know enough about WebSphere to say how this cache ID is determined. I know that the default is "0000", but I don't know how to change it.

                Stan