Thanks for the clear explanation and the direction. I have started
implementing the situation in the manner you described (I think), but
am running into another problem. The procedure below is the server
side of a GWT RPC. The line

                Method method = RequestBuilder.GET;

raises the following Error:

ERROR: GWT.create() is only usable in client code!  It cannot be
called, for example, from server code.  If you are running a unit
test, check that your test case extends GWTTestCase and that GWT.create
() is not called from within an initializer or constructor.

Any further assistance anyone could give me would be greatly
appreciated.

Thanks, Ryan

        public WeatherReport getWeatherReport(Integer zipCode) throws
Exception {
                String url = "http://www.google.com/ig/api?weather="; +
zipCode.toString();
                try {
                        Method method = RequestBuilder.GET;
                        RequestBuilder builder = new RequestBuilder(method, 
URL.encode
(url));

                        try {
                                builder.sendRequest(null, new RequestCallback(){

                                        public void onError(Request request, 
Throwable exception) {
                                                //handle error
                                        }
                                        public void onResponseReceived(Request 
request, Response
response) {
                                                //handle response
                                        }

                                });
                        } catch (RequestException e){
                                String msg = e.getMessage();
                                //handle Exception
                        }

                } catch (Throwable t){
                        String msg = t.getMessage();
                        //handle Throwable
                }

                return new WeatherReport();

        }


On Dec 8, 11:23 pm, Adam T <[EMAIL PROTECTED]> wrote:
> This technique only works for JSON that is returned as a valid
> JavaScript function, it will not work for XML.  It relies on the fact
> that the returned JavaScript expression is evaluated by the browser
> and thus your handle function is called.  Without that, your handle
> function can never be called with a JavaScriptObject that contains
> data.
>
> Normally you can get Google APIs as JSON by adding alt=json as a
> parameter to the call, but it doesn't seem to work for the weather.
>
> To handle only XML you will have to go through a proxy server, i.e.
> your application makes a call to your server, your server makes a call
> to weather service and the returned data is fed back to your
> application by your server.
>
> For completeness, you get "null" because that is exactly what your
> code is telling it to send.  As you are not getting a valid JSON
> string wraped in JavaScript function then the browser never gets to
> call your handle function with data, and you will always execute the
> code in the timeout section.  That code in the timeout section always
> make this call:
>
> [EMAIL PROTECTED]::handleXmlResponse
> (Lcom/google/gwt/core/client/JavaScriptObject;Lfarmapp/client/weather/
> WeatherReportCallback;)(null, reportCallback);
>
> where the first parameter is "null", and hence your handle function is
> always trying to handle "null".
>
> Hope that goes someway to helping/explaining!
>
> //Adam
>
>  9 Dec, 05:55, Ryan <[EMAIL PROTECTED]> wrote:
>
> > 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
>
> > **********************
> > packagefarmapp.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 Google-Web-Toolkit@googlegroups.com
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