Saturday, April 13, 2013

GWT cross-site request

Hi folks,

I have a webservice that returns a JSONP. The URL of the webservice is this:

http://user:password@localhost:8080/project/api/clientByEmail?email=user@domain.com&callback=callback1

The result of that URL is this:

callback1({"personId":"1","email":"user@domain.com","password":"5f4dcc3b5aa765d61d8327deb882cf99","personType":"1","documentNumber":"00000000191","fullName":"Name Middle Last","phone":"4130232076","mobile":"4191199614","active":"true"})

I'm writting a GWT form to retrieve this information from my webservice. I have the following function, copied from GWT Tutorial, to do that:

    public native static void getClientJson(String url, GwtTest handler) /*-{
        // [1] The script starts by setting up a <script> element. The src attribute points to the URL that will retrieve the JSON data wrapped in a callback function.
        script.setAttribute("src", url);
        script.setAttribute("type", "text/javascript");
   
        // [2] The callback function is defined on the browser's window object. It receives as an argument a JavaScript object which is the JSON data returned by the server.
        window[callback] = function(jsonObj) {
            // [3] The callback function passes the JSON data as a JavaScript object to the Java method, handleJsonResponse.
            handler.@com.google.gwt.gwttest.client.GwtTest::handleJsonResponse(Lcom/google/gwt/core/client/JavaScriptObject;)(jsonObj);
            window[callback + "done"] = true;
        }
   
        // [4] A timeout function is defined to check for an unresponsive server or network problem; it checks a flag to see if the JSON callback was ever called.
        setTimeout(function() {
            if (!window[callback + "done"]) {
                handler.@com.google.gwt.gwttest.client.GwtTest::handleJsonResponse(Lcom/google/gwt/core/client/JavaScriptObject;)(null);
            }
   
             // [5] Before the timeout function completes, it removes the new <script> element and the callback function from window.
             document.body.removeChild(script);
             delete window[callback];
             delete window[callback + "done"];
        }, 1000);
       
        // [6] Finally call appendChild() to attach the dynamically-loaded <script> element to the HTML document body. This causes the web browser to download the JavaScript referenced by the src attribute.
        document.body.appendChild(script);
    }-*/;

The problem is that when I execute this function, I always get this error message:

(ReferenceError) @com.google.gwt.gwttest.client.GwtTest::getClientJson(Ljava/lang/String;Lcom/google/gwt/gwttest/client/GwtTest;)([string: 'http://user:password@localhost:8080/project/api/clientByEmail?email=user@domain.com&callback=callback1', Java object: com.google.gwt.gwttest.client.GwtTest@8723626]): script is not defined

What am I doing wrong? When I past that URL on Chrome, or any other browser, it works just fine.

Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate