7 Replies Latest reply on Feb 28, 2008 10:59 AM by juli.med

    ajaxSubmit always throws java.net.MalformedURLException

    juli.med

      Hi,

      I'm a newbie in JSFUnit tests and I´m having a problem with richFaces components tests. Everytime I try to do a ajaxSubmit on a RichFacesClient object, it throws an exception (java.net.MalformedURLException).
      I was debbuging the code and could figure out that the exception is thrown at the method doWebRequest(WebRequest request) - JSFClientSession class. Actually, it happens when it reaches getDOM() - WebResponse class (httpunit 1.6.1.jar).
      I really don't know what's going on, 'cause the application works fine.
      Thank you all in advance and sorry for my English !

        • 1. Re: ajaxSubmit always throws java.net.MalformedURLException
          ssilvert

          Hi,

          Are you using the beta version or did you build from svn?

          Can you post the full stack trace?

          Thanks,

          Stan

          • 2. Re: ajaxSubmit always throws java.net.MalformedURLException
            juli.med

            Hi,

            First of all, thank you for the answer !

            I'm using the beta version (jboss-jsfunit-core-1.0-beta-1.jar, jboss-jsfunit-richfaces-1.0-beta-1.jar).
            With the same project, I was able to execute others jsfunit testcases, but only for JSF Standard Components. And I didn't have any problem with static analysis also.

            I have in my jsp:

            <h:inputText id="txtTel" maxlength="9" size="16" value="#{clienteRichBean.telefono}">
            <a4j:support event="onblur"
            actionListener="#{clienteRichBean.cargarNombre}"
            id="a4jcargarCli" reRender="tabPanel, pestListaCliente, listaCliente, scrollerCliente">
            </a4j:support>
            </h:inputText>

            In the back bean, in the method "cargarNombre", I search for a user for this phone number and activate de second tab in my jsp.

            My testcase:

            public void testAjaxSupport() throws IOException, SAXException
            {

            JSFClientSession client = new JSFClientSession("/paginaRich.faces");
            RichFacesClient ajaxClient = new RichFacesClient(client);
            JSFServerSession server = new JSFServerSession(client);

            client.setParameter("txtTel", "321000022");
            ajaxClient.ajaxSubmit("a4jcargarCli");
            Object userBeanValue = server.getManagedBeanValue
            ("#{clienteRichBean.telefono}");
            assertTrue(userBeanValue.equals("321000022"));
            Object pest = server.getManagedBeanValue
            ("#{clienteRichBean.activeTab}");
            assertTrue(pest.equals("pestListaCliente"));
            }

            The full trace is:

            java.net.MalformedURLException
            at com.meterware.httpunit.WebResponse.getDOM(WebResponse.java:543)
            at org.jboss.jsfunit.facade.JSFClientSession.doWebRequest(JSFClientSession.java:189)
            at org.jboss.jsfunit.richfaces.Ajax4jsfClient.doAjaxRequest(Ajax4jsfClient.java:187)
            at org.jboss.jsfunit.richfaces.Ajax4jsfClient.ajaxSubmit(Ajax4jsfClient.java:180)
            at org.jboss.jsfunit.richfaces.Ajax4jsfClient.ajaxSubmit(Ajax4jsfClient.java:152)
            at es.gpm.app.testmodule.test.PruebaRichFaces.testAjaxSupport(PruebaRichFaces.java:116)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:585)
            at junit.framework.TestCase.runTest(TestCase.java:154)
            at junit.framework.TestCase.runBare(TestCase.java:127)
            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:868)
            at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
            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:595)



            Thank you !

            • 3. Re: ajaxSubmit always throws java.net.MalformedURLException
              ssilvert

              This is a problem in HttpUnit that is hard for me to pin down. HttpUnit is trying to parse the HTML response into a DOM and it is unable to do so. The code in WebResponse is:

              public Document getDOM() throws SAXException {
               if (isHTML()) {
               return (Document) getReceivedPage().getDOM();
               } else {
               try {
               return HttpUnitUtils.newParser().parse( new InputSource( new StringReader( getText() ) ) );
               } catch (IOException e) {
               throw new SAXException( e );
               }
               }
               }


              This part is failing:
              HttpUnitUtils.newParser().parse( new InputSource( new StringReader( getText() ) ) );


              If you can get the HTML response you might be able to figure out why it can't be parsed. Do any of your URLs in the HTML contain non-UTF-8 characters? Maybe it is a problem similar to this one?
              http://www.jboss.com/index.html?module=bb&op=viewtopic&t=130409

              Stan

              • 4. Re: ajaxSubmit always throws java.net.MalformedURLException
                juli.med

                Hi, Stan

                Thanks for helping me. I looked for a non-UTF-8 character in the HTML and I didn't found anything. I tried to get the html response at this point of the code ( return HttpUnitUtils.newParser().parse( new InputSource( new StringReader( getText() ) ) ); ) and the value is something like this:

                <?xml version="1.0"?>
                <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                "http://www.w3.org/TR/html4/strict.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml"><head>
                <link type="text/css" rel="stylesheet" href="/practica.JSFUnit/a4j_3_1_2.GAcss/tabPanel.xcss/DATB/eAFbJzi9DwAEqwHl.faces" />
                <link type="text/css" rel="stylesheet" href="/practica.JSFUnit/a4j_3_1_2.GAcss/panel.xcss/DATB/eAFbJzi9DwAEqwHl.faces" />
                <link type="text/css" rel="stylesheet" href="/practica.JSFUnit/a4j_3_1_2.GAcss/spacer.xcss/DATB/eAFbJzi9DwAEqwHl.faces" />
                <link type="text/css" rel="stylesheet" href="/practica.JSFUnit/a4j_3_1_2.GAorg/richfaces/renderkit/html/css/calendar.xcss/DATB/eAFbJzi9DwAEqwHl.faces" />
                <link type="text/css" rel="stylesheet" href="/practica.JSFUnit/a4j_3_1_2.GAcss/spinner.xcss/DATB/eAFbJzi9DwAEqwHl.faces" />
                <script type="text/javascript" src="/practica.JSFUnit/a4j_3_1_2.GAorg.ajax4jsf.javascript.AjaxScript.faces">
                </script><script type="text/javascript" src="/practica.JSFUnit/a4j_3_1_2.GAorg.ajax4jsf.javascript.PrototypeScript.faces">
                </script><script type="text/javascript" src="/practica.JSFUnit/a4j_3_1_2.GAorg.ajax4jsf.javascript.ImageCacheScript.faces">
                </script><script type="text/javascript" src="/practica.JSFUnit/a4j_3_1_2.GAorg/richfaces/renderkit/html/scripts/browser_info.js.faces">
                </script><script type="text/javascript" src="/practica.JSFUnit/a4j_3_1_2.GAorg/ajax4jsf/javascript/scripts/form.js.faces">
                </script><script type="text/javascript" src="/practica.JSFUnit/a4j_3_1_2.GAscripts/tabPanel.js.faces">
                </script><script type="text/javascript" src="/practica.JSFUnit/a4j_3_1_2.GAorg/richfaces/renderkit/html/scripts/events.js.faces">
                </script><script type="text/javascript" src="/practica.JSFUnit/a4j_3_1_2.GAorg/richfaces/renderkit/html/scripts/utils.js.faces">
                </script><script type="text/javascript" src="/practica.JSFUnit/a4j_3_1_2.GAorg/richfaces/renderkit/html/scripts/json/json-dom.js.faces">
                </script><script type="text/javascript" src="/practica.JSFUnit/a4j_3_1_2.GAorg/richfaces/renderkit/html/scripts/scriptaculous/effects.js.faces">
                </script><script type="text/javascript" src="/practica.JSFUnit/a4j_3_1_2.GAorg/richfaces/renderkit/html/scripts/calendar.js.faces">
                </script><script type="text/javascript" src="/practica.JSFUnit/a4j_3_1_2.GAscript/SpinnerScript.js.faces">
                </script><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title>
                <link rel="STYLESHEET" href="./css/styles.css" type="text/css" /><style type="text/css">/*<![CDATA[*/
                 .bodyConScroll {
                 overflow:auto;
                 }
                 .bodyConScrollLista {
                 overflow-x:auto;
                 overflow-y:auto;
                 height: 200px;
                 width: 900px;
                 }
                 .bodyConScroll2 {
                 overflow-x:auto;
                 overflow-y:auto;
                 width: 900px;
                 height: 250px;
                 }
                 .arial11boldazul{
                 font-family: Arial, Helvetica, sans-serif;
                 font-size: 11px;
                 font-weight: bold;
                 color: #1D1157;
                 text-decoration: none;
                 }
                 a { color: black; text-decoration: none; border-bottom-width: 0px;
                 font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;}
                 a:link { border-bottom-color: blue }
                 a:visited { border-bottom-color: purple }
                 a:hover { border-bottom-color: green }
                 a:active { border-bottom-color: red }
                
                 /*]]>*/
                </style></head><body><span id="formulario:outTel"></span><meta name="Ajax-Update-Ids" content="formulario:outTel" />
                <span id="ajax-view-state"><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState"
                value="rO0ABXVyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAANzcgA6b3JnLmFqYXg0anNmLmFwcGxpY2F0aW9uLkFqYXhTdGF0ZU1hbmFnZXIkVHJlZVN0cnV0dXJlTm9kZYKP75jDZiMJDAAAeHB6AAAEAAAjb3JnLmFqYXg0anNmLmNvbXBvbmVudC5BamF4Vmlld1Jvb3QACV92aWV3Um9vdAAAAAAAAAABACRvcmcuYWpheDRqc2YuY29tcG9uZW50Lmh0bWwuSHRtbFBhZ2UAB19pZEpzcDAAAAAAAAAAAQAoamF2YXguZmFjZXMuY29tcG9uZW50Lmh0bWwuSHRtbFBhbmVsR3JpZAAHX2lkSnNwMQAAAAAAAAABACNqYXZheC5mYWNlcy5jb21wb25lbnQuaHRtbC5IdG1sRm9ybQAKZm9ybXVsYXJpbwAAAAAAAAABAClvcmcucmljaGZhY2VzLmNvbXBvbmVudC5odG1sLkh0bWxUYWJQYW5lbAAIdGFiUGFuZWwAAAAAAAAAAQAkb3JnLnJpY2hmYWNlcy5jb21wb25lbnQuaHRtbC5IdG1sVGFiAAtwZXN0Q2xpZW50ZQAAAAAAAAABACZvcmcucmljaGZhY2VzLmNvbXBvbmVudC5odG1sLkh0bWxQYW5lbAAHX2lkSnNwMgAAAAEABmhlYWRlcgApamF2YXguZmFjZXMuY29tcG9uZW50Lmh0bWwuSHRtbE91dHB1dFRleHQAB19pZEpzcDMAAAAAAAAAAAAAAAEAKGphdmF4LmZhY2VzLmNvbXBvbmVudC5odG1sLkh0bWxQYW5lbEdyaWQAB19pZEpzcDQAAAAAAAAABQAoamF2YXguZmFjZXMuY29tcG9uZW50Lmh0bWwuSHRtbFBhbmVsR3JpZAAHX2lkSnNwNQAAAAAAAAAGAClqYXZheC5mYWNlcy5jb21wb25lbnQuaHRtbC5IdG1sUGFuZWxHcm91cAAHX2lkSnNwNgAAAAAAAAABAChqYXZheC5mYWNlcy5jb21wb25lbnQuaHRtbC5IdG1sUGFuZWxHcmlkAAdfaWRKc3A3AAAAAAAAAAIAKmphdmF4LmZhY2VzLmNvbXBvbmVudC5odG1sLkh0bWxPdXRwdXRMYWJlbAAKbGJsQ2xpZW50ZQAAAAAAAAAAAChqYXZheC5mYWNlcy5jb21wb25lbnQuaHRtbC5IdG1sSW5wdXRUZXh0AAp0eHRDbGllbnRlAAAAAAAAAAAAJ29yZy5yaWNoZmFjZXMuY29tcG9uZW50Lmh0bWwuSHRtbFNwYWNlcgAHX2lkSnNwOAAAAAAAAAAAAClqYXZheC5mYWNlcy5jb21wb25lbnQuaHRtbC5IdG1sUGFuZWxHcm91cAAHX2lkSnNwOQAAAAAAAAABAChqYXZheC5mYWNlcy5jb21wb25lbnQuaHRtbC5IdG1sUGFuZWxHcmlkAAhfaWRKc3AxMAAAAAAAAAACACpqYXZheC5mYWN6AAAD7GVzLmNvbXBvbmVudC5odG1sLkh0bWxPdXRwdXRMYWJlbAAIbGJsRmVjaGEAAAAAAAAAAAApb3JnLnJpY2hmYWNlcy5jb21wb25lbnQuaHRtbC5IdG1sQ2FsZW5kYXIACHR4dEZlY2hhAAAAAAAA...
                


                In my jsp, I have:
                <h:inputText id="txtTel" maxlength="9" size="16" value="#{clienteRichBean.telefono}">
                 <a4j:support event="onblur" actionListener="#{clienteRichBean.cargarTel}" immediate="true"
                 id="a4jcargarCli" reRender="outTel">
                 </a4j:support>
                </h:inputText>
                
                <h:outputText id="outTel" value="#{clienteRichBean.telefono}"/>
                
                


                The method "cargarTel" only updates the clienteRichBean.telefono's value.
                I really don't get it.

                Thanks!


                • 5. Re: ajaxSubmit always throws java.net.MalformedURLException
                  ssilvert

                  The response you posted is from ajax4jsf/RichFaces. It is an HTML fragment that is inserted in the DOM on the client side. Can you try this with server-side state saving? I'm wondering if it's choking on the serialized ViewState.

                  Stan

                  • 6. Re: ajaxSubmit always throws java.net.MalformedURLException
                    ssilvert

                    Also, since you now have the HTML fragment that is causing HttpUnit to throw the error you should be able to manually execute the HttpUnit code against that fragment and find out exactly what is causing the MalformedURLException.

                    Stan

                    • 7. Re: ajaxSubmit always throws java.net.MalformedURLException
                      juli.med

                      Hi, Stan
                      You were absolutely right !! With the HTML response I could figure out where my mistake was !

                      Well, well ...I found what was going wrong. I forgot to mention that all my html were inside a a4j:page tag. And it was placed badly !!
                      Shame on me ... :((

                      I had something like this:

                      !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
                      <HTML>
                      <f:view>
                      <a4j:page pageTitle="Practica JSFUnit Richfaces">
                      <HEAD>
                       <meta http-equiv="Content-Type"
                       content="text/html; charset=utf-8">
                      .
                      .
                      .
                      </a4j:page>
                      </f:view>
                      </HTML>
                      


                      Once I placed this tag where it should be, it worked perfectly !
                      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
                      <a4j:page pageTitle="Practica JSFUnit Richfaces">
                      <HTML>
                      <f:view>
                      .
                      .
                      .
                      
                      </f:view>
                      </HTML>
                      </a4j:page>
                      


                      My mistake ...although it runs perfectly on http://localhost:8080/PracticaJSFUnit ...

                      Sorry for all the trouble and thanks for all the help !