Hello,

I am trying to access an XML feed via a URL request of an external
server, but of course am restricted by the browser SOP. So I tried to
follow the example given in the Getting Started guide for getting
around SOP on a JSON request, "Get JSON via HTTP", hoping to adapt it
for XML. But it's not working. The JSNI procedure getXml will return
to handleXmlResponse, as it is supposed to, but the JavaScriptObject
param xml is always null. It seems as though the request is timing
out, as increasing the timeout delay in the JSNI procedure seems to
have an effect. I have increased it all the way to 30 seconds hoping
for a response, but it's just not coming.

Obviously the procedure for XML is different enough that I need
further modifications. Can anyone help me out? Thanks!

Ryan

**********************
package farmapp.client.weather;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Window;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.XMLParser;

public class WeatherService {

        private int xmlRequestId = 0;

        public void getReport(final Integer zipCode, final
WeatherReportCallback reportCallback){
                String url = 
URL.encode("http://www.google.com/ig/api?weather=";) +
zipCode.toString() + "&callback=";
                getXml(xmlRequestId++, url, this, reportCallback);
        }

        public WeatherReport XmlToReport(String xml){
                WeatherReport result = new WeatherReport();
                Document doc = XMLParser.parse(xml);
                // convert doc to WeatherReport object
                return result;
        }

        public void handleXmlResponse(JavaScriptObject xml,
WeatherReportCallback reportCallback) {
                if (xml == null) {
                        Window.alert("Couldn't retrieve XML");
                }

                WeatherReport report = XmlToReport(xml.toString());
                reportCallback.onSuccess(report);
        }


        private native static void getXml(int requestId, String url,
WeatherService handler, WeatherReportCallback reportCallback) /*-{
                var callback = "callback" + requestId;
                var script = document.createElement("script");
                script.setAttribute("src", url+callback);
                script.setAttribute("type", "text/javascript");

                window[callback] = function(xmlObj) {
                        [EMAIL PROTECTED]::handleXmlResponse
(Lcom/google/gwt/core/client/JavaScriptObject;Lfarmapp/client/weather/
WeatherReportCallback;)(xmlObj, reportCallback);
                        window[callback + "done"] = true;
                }

                // set 10-second timeout
                setTimeout(function() {
                        if (!window[callback + "done"]) {
                                [EMAIL PROTECTED]::handleXmlResponse
(Lcom/google/gwt/core/client/JavaScriptObject;Lfarmapp/client/weather/
WeatherReportCallback;)(null, reportCallback);
                        }
                        // cleanup
                         document.body.removeChild(script);
                         delete window[callback];
                         delete window[callback + "done"];
                }, 10000);

                document.body.appendChild(script);
        }-*/;
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to