3 Replies Latest reply on Mar 18, 2009 8:48 PM by Tim Evers

    FacesContext is null

    Greg Cook Newbie

      Some of my JSFUnit test are failing do to the fact that my FacesContext is null. Has anyone faced this same problem?

      Environment:
      - GlassFish v2
      - Facelets 1.1.14
      - JSF 1.2 (GlassFish implementation)
      - RichFaces 3.3
      - Eclispe 3.4


      Daemon Thread [httpSSLWorkerThread-8080-0] (Suspended)
       Hashtable<K,V>.get(Object) line: 341
       StandardSession.getAttribute(String) line: 1174
       StandardSessionFacade.getAttribute(String) line: 143
       FacesContextBridge.getCurrentInstance() line: 56
       JSFServerSession.getFacesContext() line: 86
       JSFServerSession.getManagedBeanValue(String) line: 130
       RealTimePageTests.testBeans() line: 94
       NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
       NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
       DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
       Method.invoke(Object, Object...) line: 597
       RealTimePageTests(TestCase).runTest() line: 154
       RealTimePageTests(TestCase).runBare() line: 127
       RealTimePageTests(AbstractCactusTestCase).runBareServer() line: 153
       ServletTestCaller(AbstractWebTestCaller).doTest() line: 119
       AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController, ImplicitObjects, JoinPoint) line: 93
       AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController, ImplicitObjects, JoinPoint, LogAspect, AroundClosure, JoinPoint) line: 224
       ServletTestController(AbstractWebTestController).handleRequest(ImplicitObjects) line: not available
       ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector, HttpServletRequest, HttpServletResponse, JoinPoint) line: 101
       ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector, HttpServletRequest, HttpServletResponse, JoinPoint, LogAspect, AroundClosure, JoinPoint) line: 224
       JSFUnitServletRedirector(ServletTestRedirector).doPost(HttpServletRequest, HttpServletResponse) line: not available
       JSFUnitServletRedirector.doPost(HttpServletRequest, HttpServletResponse) line: 46
       ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector, HttpServletRequest, HttpServletResponse, JoinPoint) line: 72
       ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector, HttpServletRequest, HttpServletResponse, JoinPoint, LogAspect, AroundClosure, JoinPoint) line: 224
       JSFUnitServletRedirector(ServletTestRedirector).doGet(HttpServletRequest, HttpServletResponse) line: not available
       JSFUnitServletRedirector.doGet(HttpServletRequest, HttpServletResponse) line: 52
       JSFUnitServletRedirector(HttpServlet).service(HttpServletRequest, HttpServletResponse) line: 718
       JSFUnitServletRedirector(HttpServlet).service(ServletRequest, ServletResponse) line: 831
       ApplicationFilterChain.servletService(ServletRequest, ServletResponse, Servlet, InstanceSupport) line: 411
       ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 317
       ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 198
       JSFUnitFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 116
       ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 230
       ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 198
       StandardWrapperValve.invoke(Request, Response) line: 288
       StandardContextValve.invokeInternal(Wrapper, Request, Response) line: 271
       StandardContextValve.invoke(Request, Response) line: 202
       WebPipeline(StandardPipeline).doInvoke(Request, Response, boolean) line: 632
       WebPipeline(StandardPipeline).doInvoke(Request, Response) line: 577
       WebPipeline.invoke(Request, Response) line: 94
       StandardHostValve.invoke(Request, Response) line: 206
       StandardPipeline.doInvoke(Request, Response, boolean) line: 632
       StandardPipeline.doInvoke(Request, Response) line: 577
       StandardPipeline.invoke(Request, Response) line: 571
       VirtualServer(ContainerBase).invoke(Request, Response) line: 1080
       StandardEngineValve.invoke(Request, Response) line: 150
       StandardPipeline.doInvoke(Request, Response, boolean) line: 632
       StandardPipeline.doInvoke(Request, Response) line: 577
       StandardPipeline.invoke(Request, Response) line: 571
       EmbeddedWebContainer$WebEngine(ContainerBase).invoke(Request, Response) line: 1080
       CoyoteAdapter.service(Request, Response) line: 272
       DefaultProcessorTask.invokeAdapter() line: 637
       DefaultProcessorTask.doProcess(InputStream, OutputStream) line: 568
       DefaultProcessorTask.process(InputStream, OutputStream) line: 813
       DefaultReadTask.executeProcessorTask() line: 341
       DefaultReadTask.doTask(ByteBuffer) line: 263
       DefaultReadTask.doTask() line: 214
       PortUnificationPipeline$PUTask.doTask() line: 380
       PortUnificationPipeline$PUTask(TaskBase).run() line: 265
       SSLWorkerThread.run() line: 106
      


        • 1. Re: FacesContext is null
          Stan Silvert Master

          I think the stack trace you posted earlier is a little more clear, so I'll refer back to the other post for future reference:
          http://www.jboss.org/index.html?module=bb&op=viewtopic&t=152391

          The most common cause of this error is starting with a URL that is not a faces request (i.e. it doesn't map to the FacesServlet).

          So, this would not work:

          JSFSession session = new JSFSession("/index.xhtml");


          Instead, it should be something like:
          JSFSession session = new JSFSession("/index.jsf");


          If that doesn't help, please post your code and the matching stack trace.

          Regards,

          Stan

          • 2. Re: FacesContext is null
            Greg Cook Newbie

            Thanks for the quick reply. Do you see any errors in my web.xml file for the mapping of the map to the FacesServlet?

            web.xml

            <?xml version="1.0" encoding="UTF-8"?>
            <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
             id="WebApp_ID" version="2.5">
             <welcome-file-list>
             <welcome-file>index.html</welcome-file>
             </welcome-file-list>
             <servlet>
             <servlet-name>Faces Servlet</servlet-name>
             <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
             <load-on-startup>1</load-on-startup>
             </servlet>
             <servlet-mapping>
             <servlet-name>Faces Servlet</servlet-name>
             <url-pattern>*.jsf</url-pattern>
             </servlet-mapping>
             <context-param>
             <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
             <param-value>.xhtml</param-value>
             </context-param>
             <context-param>
             <param-name>facelets.DEVELOPMENT</param-name>
             <param-value>false</param-value>
             </context-param>
             <context-param>
             <param-name>org.richfaces.SKIN</param-name>
             <param-value>blueSky</param-value>
             </context-param>
             <context-param>
             <param-name>org.richfaces.CONTROL_SKINNING</param-name>
             <param-value>enable</param-value>
             </context-param>
             <filter>
             <display-name>RichFaces Filter</display-name>
             <filter-name>richfaces</filter-name>
             <filter-class>org.ajax4jsf.Filter</filter-class>
             </filter>
             <filter-mapping>
             <filter-name>richfaces</filter-name>
             <servlet-name>Faces Servlet</servlet-name>
             <dispatcher>REQUEST</dispatcher>
             <dispatcher>FORWARD</dispatcher>
             <dispatcher>INCLUDE</dispatcher>
             </filter-mapping>
             <filter>
             <filter-name>JSFUnitFilter</filter-name>
             <filter-class>org.jboss.jsfunit.framework.JSFUnitFilter</filter-class>
             </filter>
             <filter-mapping>
             <filter-name>JSFUnitFilter</filter-name>
             <servlet-name>ServletTestRunner</servlet-name>
             </filter-mapping>
             <filter-mapping>
             <filter-name>JSFUnitFilter</filter-name>
             <servlet-name>ServletRedirector</servlet-name>
             </filter-mapping>
             <servlet>
             <servlet-name>ServletRedirector</servlet-name>
             <servlet-class>org.jboss.jsfunit.framework.JSFUnitServletRedirector</servlet-class>
             </servlet>
             <servlet>
             <servlet-name>ServletTestRunner</servlet-name>
             <servlet-class>org.apache.cactus.server.runner.ServletTestRunner</servlet-class>
             </servlet>
             <servlet-mapping>
             <servlet-name>ServletRedirector</servlet-name>
             <url-pattern>/ServletRedirector</url-pattern>
             </servlet-mapping>
             <servlet-mapping>
             <servlet-name>ServletTestRunner</servlet-name>
             <url-pattern>/ServletTestRunner</url-pattern>
             </servlet-mapping>
            </web-app>


            • 3. Re: FacesContext is null
              Tim Evers Master

              Could you please post the source of your test.

              Without that it is difficult to see if it is a mapping issue or not.

              Thanks,
              Tim