1 2 Previous Next 17 Replies Latest reply: Jul 29, 2008 3:33 PM by Wiktor Gworek RSS

    java.lang.ClassCastException: com.gargoylesoftware.htmlunit.

    Brian Gregory Newbie

      This exception happens when loading a page that contains a rich:panelMenu using BrowserVersion.INTERNET_EXPLORER_6_0.

      Here is my test code:

      WebClientSpec wcSpec = new WebClientSpec("/secure/refresh.faces", BrowserVersion.INTERNET_EXPLORER_6_0);
      JSFSession jsfSession = new JSFSession(wcSpec);
      JSFClientSession client = jsfSession.getJSFClientSession();
      


      Here is the page: (refresh.faces):

      <html>
      <f:view contentType="text/html">
      <head>
       <title>Default title</title>
      </head>
      <body>
      
      <h:form>
      <rich:panelMenu>
       <rich:panelMenuGroup label="Group 1">
       <rich:panelMenuItem label="Item 1"/>
       </rich:panelMenuGroup>
       <rich:panelMenuGroup label="Group 2">
       <rich:panelMenuItem label="Item 1"/>
       </rich:panelMenuGroup>
       <rich:panelMenuGroup label="Group 3">
       <rich:panelMenuItem label="Item 1"/>
       </rich:panelMenuGroup>
      </rich:panelMenu>
      </h:form>
      
      </body>
      </f:view>
      </html>
      


      And here is the exception generated:

      java.lang.ClassCastException: com.gargoylesoftware.htmlunit.html.HtmlScript
      at com.gargoylesoftware.htmlunit.html.HtmlScript.printChildrenAsXml(HtmlScript.java:406)
      at com.gargoylesoftware.htmlunit.html.HtmlElement.printXml(HtmlElement.java:842)
      at com.gargoylesoftware.htmlunit.html.DomNode.asXml(DomNode.java:732)
      at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:199)
      at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:496)
      at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
      at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:466)
      at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:210)
      at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:329)
      at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:971)
      at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:874)
      at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:2736)
      at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:1937)
      at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:877)
      at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:495)
      at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:448)
      at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
      at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:634)
      at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:235)
      at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:127)
      at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:101)
      at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:428)
      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:337)
      at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:360)
      at com.gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:167)
      at com.gargoylesoftware.htmlunit.html.HtmlSubmitInput.doClickAction(HtmlSubmitInput.java:78)
      at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:132)
      at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:93)
      at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:72)
      at org.jboss.jsfunit.framework.FormAuthenticationStrategy.clickSubmitComponent(FormAuthenticationStrategy.java:105)
      at org.jboss.jsfunit.framework.FormAuthenticationStrategy.doInitialRequest(FormAuthenticationStrategy.java:93)
      at org.jboss.jsfunit.framework.WebClientSpec.doInitialRequest(WebClientSpec.java:224)
      at org.jboss.jsfunit.jsfsession.JSFSession.<init>(JSFSession.java:78)
      at com.g_webdesign.NavTestCase.testLogin(NavTestCase.java:72)
      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)
       4.065
      
      


        • 1. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
          Brian Gregory Newbie

          I've confirmed this is a HtmlUnit issue. The following code causes the same exception.

          WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_6_0);
          HtmlPage page = (HtmlPage) webClient.getPage("http://localhost:8080/project/form.faces");
          


          • 3. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
            Stan Silvert Master

            Hmm. I tried this code against the RichFaces demo and it worked:

             public void testRichPanelMenu() throws IOException
             {
             final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_6_0);
             final HtmlPage page = (HtmlPage)webClient.getPage("http://livedemo.exadel.com/richfaces-demo/richfaces/panelMenu.jsf?c=panelMenu");
             }


            Stan

            • 4. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
              Brian Gregory Newbie

              I'm using richfaces 3.2.1. Which version is the demo using?
              I will try the earlier version.

              • 5. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
                Stan Silvert Master

                In the bottom right corner of the welcome page, it says that the demo is using 3.2.1:
                http://livedemo.exadel.com/richfaces-demo/welcome.jsf

                Stan

                • 6. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
                  Brian Gregory Newbie

                  Yeah, I've tried both versions with the same results.
                  What else is interesting is that loading the demo for me does have a problem.

                  final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_6_0);
                  final HtmlPage page = (HtmlPage) webClient.getPage("http://livedemo.exadel.com/richfaces-demo/richfaces/panelMenu.jsf?c=panelMenu");
                  


                  strange.

                  • 7. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
                    Brian Gregory Newbie

                    I've just built HtmlUnit + JSFUnit from SVN trunk. Do you have the latest HtmlUnit? Perhaps I have the wrong versions of some library?

                    I'm also using facelets, although I doubt that's the problem since its pretty clear the problem is on the client side.

                    • 8. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
                      Brian Gregory Newbie

                      This is becoming VERY frustrating.
                      This is what I've done:

                      1. I've built HtmlUnit + JSFUnit straight out of the current SVN trunks.
                      2. Created a blank "Dynamic Web" project in eclipse
                      3. Put these libraries in WEB-INF/lib

                      aspectjrt-1.2.1.jar
                      cactus-13-1.7.1.jar
                      commons-codec-1.3.jar
                      commons-collections-3.2.jar
                      commons-fileupload-1.2.1.jar
                      commons-httpclient-3.1.jar
                      commons-io-1.4.jar
                      commons-lang-2.4.jar
                      commons-logging-1.1.1.jar
                      cssparser-0.9.5.jar
                      gsbase-2.0.1.jar
                      htmlunit-2.2-SNAPSHOT.jar
                      jboss-jsfunit-core-1.0.0.GA-SNAPSHOT.jar
                      jetty-6.1.9.jar
                      jetty-util-6.1.9.jar
                      js-1.7R1.jar
                      jtidy-4aug2000r7-dev.jar
                      junit-3.8.1.jar
                      junitperf-1.8.jar
                      log4j-1.2.14.jar
                      nekohtml-1.9.7.jar
                      sac-1.3.jar
                      servlet-api-2.5-6.1.9.jar
                      slf4j-api-1.4.3.jar
                      slf4j-log4j12-1.4.3.jar
                      xalan-2.7.0.jar
                      xercesImpl-2.8.1.jar
                      xml-apis-1.0.b2.jar

                      4. Added this to the web.xml

                      <!-- JSFUnit configuration -->
                       <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.apache.cactus.server.ServletTestRedirector</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>
                      


                      5. Added cactus-report.xsl to the WebContent directory
                      6. Created this Test Case

                       public void testLoadRichfacesDemo() throws FailingHttpStatusCodeException, MalformedURLException, IOException {
                       final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_6_0);
                       final HtmlPage page = (HtmlPage) webClient.getPage("http://livedemo.exadel.com/richfaces-demo/richfaces/panelMenu.jsf?c=panelMenu");
                       }
                      


                      7. Published to JBoss and run

                      This is what happens:

                      java.lang.ClassCastException: com.gargoylesoftware.htmlunit.html.HtmlScript
                      at com.gargoylesoftware.htmlunit.html.HtmlScript.printChildrenAsXml(HtmlScript.java:406)
                      at com.gargoylesoftware.htmlunit.html.HtmlElement.printXml(HtmlElement.java:842)
                      at com.gargoylesoftware.htmlunit.html.DomNode.asXml(DomNode.java:732)
                      at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:199)
                      ...
                      


                      Perhaps I'm using a different version of JBoss? (jboss-4.2.2.GA)
                      What have I done that's different?

                      • 9. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
                        Stan Silvert Master

                        If you send me an email I can send you my simple Maven project that hits the RichFaces demo and works. Would that help?

                        Stan

                        • 10. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
                          Brian Gregory Newbie

                          Ok, Using the following libraries it seems to work:

                          aspectjrt-1.2.1.jar
                          cactus-13-1.7.1.jar
                          commons-codec-1.3.jar
                          commons-collections-3.2.jar
                          commons-httpclient-3.1.jar
                          commons-io-1.4.jar
                          commons-lang-2.4.jar
                          commons-logging-1.1.1.jar
                          cssparser-0.9.5.jar
                          htmlunit-2.2-SNAPSHOT.jar
                          htmlunit-core-js-0.1-SNAPSHOT.jar
                          jboss-jsfunit-core-1.0.0.GA-SNAPSHOT.jar
                          junit-3.8.2.jar
                          nekohtml-1.9.8-SNAPSHOT.jar
                          sac-1.3.jar
                          xalan-2.7.0.jar
                          xercesImpl-2.8.1.jar
                          xml-apis-1.0.b2.jar

                          • 11. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
                            Brian Gregory Newbie

                            If I use nekohtml-1.9.7.jar then I get the exception (as before):

                            java.lang.ClassCastException: com.gargoylesoftware.htmlunit.html.HtmlScript
                            at com.gargoylesoftware.htmlunit.html.HtmlScript.printChildrenAsXml(HtmlScript.java:406)
                            ...
                            


                            If I use the latest version (nekohtml-1.9.8-SNAPSHOT.jar - dated 6/19/2008 1:43pm) then I don't get the above, but I do get the following SOMETIMES when the page contains a selectItem with a name that starts with '!'. (Yeah this is truly a bizzare problem - I will try to nail this down and start a new thread)

                            thanks!

                            • 12. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
                              Brian Gregory Newbie

                              The exception (forgot to include):

                              java.lang.ArrayIndexOutOfBoundsException: -7
                              at org.cyberneko.html.HTMLScanner.read(HTMLScanner.java:1121)
                              at org.cyberneko.html.HTMLScanner$SpecialScanner.scan(HTMLScanner.java:2824)
                              at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:880)
                              at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:495)
                              at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:448)
                              at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
                              at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:634)
                              at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:235)
                              at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:127)
                              at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:101)
                              at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:428)
                              at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:337)
                              at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:360)
                              at com.gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:167)
                              at com.gargoylesoftware.htmlunit.html.HtmlSubmitInput.doClickAction(HtmlSubmitInput.java:78)
                              at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:132)
                              at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:93)
                              at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:72)
                              at org.jboss.jsfunit.framework.FormAuthenticationStrategy.clickSubmitComponent(FormAuthenticationStrategy.java:105)
                              at org.jboss.jsfunit.framework.FormAuthenticationStrategy.doInitialRequest(FormAuthenticationStrategy.java:93)
                              at org.jboss.jsfunit.framework.WebClientSpec.doInitialRequest(WebClientSpec.java:224)
                              at org.jboss.jsfunit.jsfsession.JSFSession.<init>(JSFSession.java:78)
                              


                              • 13. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
                                Brian Gregory Newbie

                                Rolled back the nekohtml jar to nekohtml-1.9.8-20080612.144011-4.jar and everything seems to work. (It looks like the htmlunit build automatically grabs the latest nekohtml - so something bad must've been checked in since 6/12/08)

                                • 14. Re: java.lang.ClassCastException: com.gargoylesoftware.htmlu
                                  Tim Evers Master

                                  Ok, so the solution is to grab the snapshot of Nekohtml for now?

                                  1 2 Previous Next