EmmKay - 2010-06-09

Hi,

I am trying to render a html page which contains ajax requests to be completed. I am able to generate the page properly including the ajax responses, but an error / exception is spit out at the time of the ajax request. Can someone help me figure out the root cause of this problem?

Thanks in advance.

My code:

public static void rendercompleteHTMLWithCobra() {
    System.out.println( "start" );
    // cobra.jar, js.jar
    try {
        //String urlString = "http://www.fidelity.ca/cs/Satellite/en/public/home";
        String urlString = "http://www.fidelity.ca/cs/Satellite/en/public/products/mutual_funds/equity_funds/cdn_equity/de";
        URL url = new URL(urlString);
        HttpURLConnection con = (HttpURLConnection)url.openConnection();
        InputStream input = con.getInputStream();
        // Create user agent context
        SimpleUserAgentContext context = new SimpleUserAgentContextExt();
        context.setScriptingEnabled( true );
        context.setExternalCSSEnabled( true );
        DocumentBuilderImpl dbi = new DocumentBuilderImpl(context);
        HTMLDocumentImpl document = (HTMLDocumentImpl)dbi.createDocument( new InputSourceImpl( urlString ) );
        document.addDocumentNotificationListener( new DBListener() );
        HtmlParser parser = new HtmlParser(context, document); 
        parser.parse( input ); 
    }
    catch ( Exception e ) {
        e.printStackTrace();
    }
}

class SimpleUserAgentContextExt extends SimpleUserAgentContext {
    @Override
    public HttpRequest createHttpRequest() {
        System.out.println("Creating http request for agent");
        final HttpRequest httpRequest = new SimpleHttpRequest(this, this.getProxy());
        httpRequest.addReadyStateChangeListener(new ReadyStateChangeListener() {
            public void readyStateChanged() {
                if(httpRequest.getReadyState() == HttpRequest.STATE_COMPLETE) {
                    String resp = httpRequest.getResponseText();
                    System.out.println( "State complete " );
                }
            }
        });
        return httpRequest;
    }   
}
class DBListener implements DocumentNotificationListener {
    public void sizeInvalidated(NodeImpl node) {
        System.out.println( "Size invalidated " + node.getInnerHTML() );
    }

    public void lookInvalidated(NodeImpl node) { System.out.println( "lookInvalidated "  ); }
    public void positionInvalidated(NodeImpl node) { System.out.println( "positionInvalidated " ); }
    public void invalidated(NodeImpl node) { System.out.println( "invalidated " + node.getInnerHTML() ); }
    public void nodeLoaded(NodeImpl node) {}
    public void structureInvalidated(NodeImpl node) { System.out.println( "structureInvalidated " ); }
    public void externalScriptLoading(NodeImpl node) { System.out.println( "externalScriptLoading " ); }
    public void allInvalidated() { System.out.println( "allInvalidated " ); }
}

The exception:

9-Jun-2010 2:21:36 PM org.lobobrowser.html.js.Executor executeFunction
WARNING: executeFunction(): There was an error in Javascript code.
org.mozilla.javascript.EcmaError: TypeError: Cannot find function detachEvent. (http://www.fidelity.ca/cs/js/jquery.min.js#58)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3229)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3219)
at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3235)
at org.mozilla.javascript.ScriptRuntime.typeError1(ScriptRuntime.java:3247)
at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3307)
at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:1991)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:2932)
at script(http://www.fidelity.ca/cs/js/jquery.min.js:58)
at script(http://www.fidelity.ca/cs/js/jquery.min.js:52)
at script(http://www.fidelity.ca/cs/js/jquery.min.js:51)
at script(http://www.fidelity.ca/cs/js/jquery.min.js:65)
at script.Secondary_Nav(http://www.fidelity.ca/cs/js/main.js:183)
at script.initialize(http://www.fidelity.ca/cs/js/main.js:15)
at script.onload_27803692(body.onload:1)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2251)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:161)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:340)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2758)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:159)
at org.lobobrowser.html.js.Executor.executeFunction(Executor.java:71)
at org.lobobrowser.html.js.Executor.executeFunction(Executor.java:52)
at org.lobobrowser.html.domimpl.HTMLDocumentImpl.setUserData(HTMLDocumentImpl.java:1204)
at org.lobobrowser.html.parser.HtmlParser.parse(HtmlParser.java:542)
at org.lobobrowser.html.parser.HtmlParser.parse(HtmlParser.java:507)
at org.lobobrowser.html.parser.HtmlParser.parse(HtmlParser.java:491)
at org.lobobrowser.html.parser.HtmlParser.parse(HtmlParser.java:478)
at com.test.Test.rendercompleteHTMLWithCobra(Test.java:83)
at com.test.Test.main(Test.java:53)
State complete
9-Jun-2010 2:23:05 PM org.lobobrowser.js.JavaFunctionObject call
INFO: call(): Calling method getResponseHeader on object org.lobobrowser.html.js.XMLHttpRequest@d5276a of type org.lobobrowser.html.js.XMLHttpRequest
9-Jun-2010 2:23:05 PM org.lobobrowser.js.JavaFunctionObject call
INFO: call(): For method=getResponseHeader: Converted arg=content-type (type=java.lang.String) into actualArg=content-type. Type expected by method is java.lang.String.
9-Jun-2010 2:23:05 PM org.lobobrowser.js.JavaFunctionObject call
INFO: call(): Calling method getElementsByTagName on object div ] of type org.lobobrowser.html.domimpl.HTMLDivElementImpl
9-Jun-2010 2:23:05 PM org.lobobrowser.js.JavaFunctionObject call
INFO: call(): For method=getElementsByTagName: Converted arg=* (type=java.lang.String) into actualArg=*. Type expected by method is java.lang.String.