13 Replies Latest reply on Dec 3, 2007 10:36 AM by Stan Silvert

    Extension Filter

    Manfred Maelzer Newbie

      As soon as i activate the myfaces extension filter, the test returns an Internal Error (ErrorCode 500)

      org.apache.cactus.internal.client.ServletExceptionWrapper: Error on HTTP request: 500 Internal Error [http://localhost:8080/warranty/jsp/main.jsf?doAction=start&fakecwsid=kingnm]
      com.meterware.httpunit.HttpInternalErrorException: Error on HTTP request: 500 Internal Error [http://localhost:8080/warranty/jsp/main.jsf?doAction=start&fakecwsid=kingnm]
       at com.meterware.httpunit.WebClient.validateHeaders(WebClient.java:573)
       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.WebClient.getResponse(WebClient.java:113)
       at org.jboss.jsfunit.facade.JSFClientSession.doWebRequest(JSFClientSession.java:184)
       at org.jboss.jsfunit.facade.JSFClientSession.doInitialRequest(JSFClientSession.java:122)
       at org.jboss.jsfunit.facade.JSFClientSession.<init>(JSFClientSession.java:75)
       at de.docware.warranty.unittests.EngineWarrantyUnitTest.setUp(EngineWarrantyUnitTest.java:41)
       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:689)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:123)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
       at java.lang.Thread.run(Thread.java:534)
       at java.lang.Thread.run(Thread.java:534)
      


      This is the section in the web.xml
       <filter>
       <filter-name>900_MyFacesExtensionsFilter</filter-name>
       <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
       <init-param>
       <param-name>maxFileSize</param-name>
       <param-value>20m</param-value>
       <description>Set the size limit for uploaded files.
       Format: 10 - 10 bytes
       10k - 10 KB
       10m - 10 MB
       1g - 1 GB</description>
       </init-param>
       </filter>
      


      I'm using myfaces 1.1.5 and tomahawk 1.1.6

      In addition to this issue, is the position of the JSFUnit Filter of importance? (first filter, last filter, ..)?

        • 1. Re: Extension Filter
          Stan Silvert Master

          A 500 error indicates that there was an error processing the request on the server side. So this is not a problem with JSFUnit/HttpUnit per se. Is there another error in a log somewhere indicating what the actual problem was? If you are using JBoss AS then by default the error would show up in the console and in server.log.

          What happens when you do http://localhost:8080/warranty/jsp/main.jsf?doAction=start&fakecwsid=kingnm from a browser?

          To answer your second question, since the JSFUnitFilter should only be mapped to the ServletTestRunner and the ServletRedirector, it should not come into play during a request from the JSFClientSession. It is only activated when you startup the test.

          Stan

          • 2. Re: Extension Filter
            Manfred Maelzer Newbie

            Calling the URL directly works without any errors. The page is shown properly. Using the same URL for the JSFUnit Test causes the Error 500.

            That's why i see a relation to the JSFUnit.

            Currently we run 5 filters. JSFUnit is the 6th.

            Two of those filters (myfaces extension filter and a custom filter) cause troubles in combine with JSFUnit - in means that when trying to perform the test case, it would return a Error Code 500 - no matter which URL has to be shown.

            If I comment those two filters, the above URL will work in JSFUnit too.

            There is only one exception shown in the error log file - which aswell is being raised in the case that JSFUnit runs (without the given 2 filters) :
            FacesContext already released (see other topic)


            • 3. Re: Extension Filter
              Stan Silvert Master

              I think the "FacesContext already released" error is the root of your problem. This error causes the 500 error on the client (JSFClientSession). What this error means is that the PhaseListener is somehow getting a reference to a stale FacesContext. Because the FacesContext instance is held in a ThreadLocal, management of the ThreadLocal is very important. But retroweaver seems to have trouble with ThreadLocals.

              Is there any way you can try this with JDK 1.5 and the original ThreadLocal.remove() code? If it works under JDK 1.5 then we will know that it is a problem with retroweaver. Then we can see how to get around it.

              Stan

              • 4. Re: Extension Filter
                Manfred Maelzer Newbie

                I set up the system with a fresh tomcat, the original jar files (running under java5)... yet I still recieve the Error Code 500.

                This time however the tomcat gave an additional line - don't know though if that's the actual reason:

                java.lang.IllegalStateException: No JSF request has been made for this session.
                at org.jboss.jsfunit.framework.JSFTimer.getTimer(JSFTimer.java:104) ...

                I think the ThreadLocal.set(null) works about as the remove() would do. As according to the remove(), the removed value will be set to the initialvalue if its requested again - and the initial value is set to "null" currently.

                I noticed too that this only occurs when calling the "jsp" methods that redirect to a jsf page.

                The frameset.jsf consists of a "refresh.jsf" and a "main.jsf" - both of type jsp. The main.jsf calls the requestprocessor, reading some parameters, setting up the necessary environment, and redirects to the /jsp/empty.jsf" - which is of type jsf.

                If the frameset is not called (that is the startactions), no other URL will be allowed in that session (due to filters).

                I tested by removing this security filter, and creating a testcase that starts with simply jsf form (two input fields + button) - which loaded fine according to the testcase results. (with the extension filter active).

                I exchanged the initial url for the testcase to the frameset.jsf URL again, and it brought up errors once more.

                If I enter the frameset URL directly in the Browser, the page loads without errors.


                When I tried to run a simple FooTest in the deployed application (via "http://localhost:8080/warranty/ServletTestRunner?suite=foo.FooTest") it would give me the following error (though running the testcase within the IDE worked)

                <testsuites>
                - <testsuite name="foo.FooTest" tests="1" failures="0" errors="1" time="0.034">
                - <testcase name="testInitialPage" time="0.034">
                 <error message="org.w3c.tidy.DOMDocumentImpl.getXmlStandalone()Z" type="org.apache.cactus.internal.client.ServletExceptionWrapper">java.lang.AbstractMethodError: org.w3c.tidy.DOMDocumentImpl.getXmlStandalone()Z at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(DOM2TO.java:373) at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:127) at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:94) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:663) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:709) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313) at org.jboss.jsfunit.facade.DOMUtil.convertToDomLevel2(DOMUtil.java:143) at org.jboss.jsfunit.facade.JSFClientSession.doWebRequest(JSFClientSession.java:189) at org.jboss.jsfunit.facade.JSFClientSession.doInitialRequest(JSFClientSession.java:122) at org.jboss.jsfunit.facade.JSFClientSession.<init>(JSFClientSession.java:75) at foo.FooTest.setUp(FooTest.java:43) 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:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:123) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685) at java.lang.Thread.run(Thread.java:619)</error>
                 </testcase>
                 </testsuite>
                 </testsuites>
                




                • 5. Re: Extension Filter
                  Stan Silvert Master

                  Yes, the IllegalStateException will cause the 500 error. Are you using the JSFTimer in your tests? I don't see any other way that the IllegalStateException could be thrown. That exception is thrown when there is no FacesContext available. Please post the full stack trace for that one so I can see where it came from. I might need to add a way to disable the timer.

                  For the AbstractMethodError, it looks like a bug in Xalan. The JTidy document is DOM level 1 and Xalan should know not to call getXmlStandalone, which is DOM level 3. However, you should be able to work around this error by replacing the JTidy jar with the latest snapshot available here:
                  http://jtidy.sourceforge.net/snapshots/jtidy/jtidy/8.0-SNAPSHOT/

                  This snapshot contains a default implementation for getXmlStandalone.

                  Stan

                  • 6. Re: Extension Filter
                    Manfred Maelzer Newbie

                    Here's the full stacktrace of the timer exception

                    INFO: Starting up Tomahawk on the MyFaces-JSF-Implementation
                    28.11.2007 14:07:47 org.apache.myfaces.lifecycle.PhaseListenerManager informPhaseListenersAfter
                    SCHWERWIEGEND: Exception in PhaseListener RENDER_RESPONSE(6) afterPhase
                    java.lang.IllegalStateException: No JSF request has been made for this session.
                     at org.jboss.jsfunit.framework.JSFTimer.getTimer(JSFTimer.java:104)
                     at org.jboss.jsfunit.framework.JSFTimerPhaseListener.afterPhase(JSFTimerPhaseListener.java:53)
                     at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersAfter(PhaseListenerManager.java:92)
                     at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:134)
                     at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
                     at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
                     at de.docware.util.j2eeimpl.filter.OmitDoubleRequestsFilter.showNewPageWithoutSession(OmitDoubleRequestsFilter.java:155)
                     at de.docware.util.j2eeimpl.filter.OmitDoubleRequestsFilter.doFilter(OmitDoubleRequestsFilter.java:99)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
                     at de.docware.util.j2eeimpl.filter.SerializeRequestsFilter.doFilter(SerializeRequestsFilter.java:76)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
                     at de.docware.util.j2eeimpl.filter.SessionSerializerFilter.doFilter(SessionSerializerFilter.java:21)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
                     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
                     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
                     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
                     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
                     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
                     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
                     at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
                     at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
                     at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
                     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
                     at java.lang.Thread.run(Thread.java:619)
                    28.11.2007 14:23:08 org.apache.coyote.http11.Http11BaseProtocol pause
                    INFO: Pausing Coyote HTTP/1.1 on http-8080
                    28.11.2007 14:23:09 org.apache.catalina.core.StandardService stop
                    INFO: Stopping service Catalina
                    



                    • 7. Re: Extension Filter
                      Stan Silvert Master

                      That's very strange. Your stack trace is showing that this error occurs while still inside the JSF lifecycle. Here is the JSFUnit code that fails:

                      FacesContext facesContext = FacesContext.getCurrentInstance();
                      
                      try
                      {
                       if (facesContext == null) facesContext = FacesContextBridge.getCurrentInstance();
                      }
                      catch (NullPointerException e)
                      {
                       throw new IllegalStateException("No JSF request has been made for this session.");
                      }


                      Since you are inside the JSF lifecycle, FacesContext.getCurrentInstance() should not return null. Therefore, the if condition should be false and you can't get the IllegalStateException.

                      Are you still using retroweaver for this?

                      The only other possibilities I can think of are that you are running multiple threads in your test or there is a different FacesContext implementation from some other JSF add-on package.

                      Stan

                      • 8. Re: Extension Filter
                        Manfred Maelzer Newbie

                        The exception occured while I deployed the application on a blank tomcat. I used the original JSFUnit files in this case, with no retroweaver / retrotranslator

                        As Add-on I use tomahawk 1.16. We dont use Trinidad/Icefaces/...

                        And we dont have threads in our application code. It's simply session based.

                        • 9. Re: Extension Filter
                          Stan Silvert Master

                          Thanks for the info.

                          I don't yet know how to reproduce this problem, but I'm going to add a way to disable the JSFTimer so you won't have this exception any more. Please let me know if you come up with an easy way for me to reproduce the problem on my end.

                          Stan

                          • 10. Re: Extension Filter
                            Stan Silvert Master

                            This is done now. The JSFTimer is disabled by default. So if you do a svn update and rebuild, the exception should go away.

                            Stan

                            • 11. Re: Extension Filter
                              Manfred Maelzer Newbie

                              Thanks for the help.

                              We found out finally what the issue behind the scenes was.

                              getServletConfig().getServletContext().getRequestDispatcher(nextPage).forward(request, response);


                              The above statement caused the issue. The following statement fixed it
                              response.sendRedirect(nextPage);




                              • 12. Re: Extension Filter
                                Raja sekhar v Newbie

                                I too have the similar problem that i sent today.
                                I think multiple threads are getting executed.
                                I can see the first test case throwing null pointer exception and the second testcase is executing some portion of code.
                                is this how it works?
                                one thread for each test case?

                                • 13. Re: Extension Filter
                                  Stan Silvert Master

                                  I think your problem is different. I just wrote a wiki article on HttpSession and Threads. Maybe it will help.

                                  http://wiki.jboss.org/wiki/JSFUnitSessionAndThreads

                                  If not, please start a new discussion with details of your problem.

                                  Thanks,

                                  Stan