I have still difficulties with RPC call in a gadget. In hosted mode it
works again, but not in iGoogle.
Here is my Code:
package com.google.gwt.sample.cnsnews_rpc_gadget.client;
import java.io.Serializable;
import com.google.gwt.sample.cnsnews_rpc_gadget.client.FakeResponse;
import com.google.gwt.sample.cnsnews_rpc_gadget.client.GadgetResponse;
import com.google.gwt.core.client.GWT;
import com.google.gwt.gadgets.client.Gadget;
import com.google.gwt.gadgets.client.IntrinsicFeature;
import com.google.gwt.gadgets.client.NeedsIntrinsics;
import com.google.gwt.gadgets.client.Gadget.ModulePrefs;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
@ModulePrefs(title = "CADENAS News", author = "mr")
public class CADENASNews_RPC_Gadget extends Gadget<NewsPreferences>
implements NeedsIntrinsics, AsyncCallback<String>
{
IntrinsicFeature intrinsicMethods;
private final static GadgetServiceAsync gadgetService =
(GadgetServiceAsync) GWT.create(GadgetService.class);
static {
disableStats();
}
private static native void disableStats() /*-{
$wnd.$stats = null;
}-*/;
public void initializeFeature(IntrinsicFeature feature) {
this.intrinsicMethods=feature;
}
public void init(NewsPreferences preferences) {
ServiceDefTarget serviceDef = (ServiceDefTarget) gadgetService;
String rpcUrl = serviceDef.getServiceEntryPoint();
rpcUrl = intrinsicMethods.getCachedUrl(rpcUrl);
String protocol = rpcUrl.substring(0, rpcUrl.indexOf(':'));
String file = rpcUrl.substring(rpcUrl.indexOf('/', rpcUrl.indexOf
(':')+3));
serviceDef.setServiceEntryPoint(protocol+"://"+ getDomain() + file);
RequestBuilder requestBuilder = gadgetService.getXML
(CADENASNews_RPC_Gadget.this);
String url = requestBuilder.getUrl();
makeGetRequest(url, requestBuilder.getRequestData(),
requestBuilder.getCallback());
}
private static native String getDomain() /*-{
return $wnd.document.domain;
}-*/;
public void onFailure(Throwable caught) {
Label lbl2 = new HTML(caught.getLocalizedMessage());
RootPanel.get().add(lbl2);
}
public void onSuccess(String result) {
Label lbl = new HTML(result);
RootPanel.get().add(lbl);
}
private native void makeGetRequest(String url, String postdata,
RequestCallback callback) /*-{
var params = {};
params[$wnd.gadgets.io.RequestParameters.METHOD] =
$wnd.gadgets.io.MethodType.GET;
params[$wnd.gadgets.io.RequestParameters.POST_DATA]= postdata;
$wnd.gadgets.io.makeRequest(url, response, params);
function response(obj) {
@com.google.gwt.sample.cnsnews_rpc_gadget.client.CADENASNews_RPC_Gadget::onSuccessInternal
(Lcom/google/gwt/sample/cnsnews_rpc_gadget/client/GadgetResponse;Lcom/
google/gwt/http/client/RequestCallback;)(obj, callback);
};
}-*/;
static void onSuccessInternal(final GadgetResponse response,
RequestCallback callback) {
try {
String responseText = response.getText();
callback.onResponseReceived(null, new FakeResponse(response));
} catch (Exception e) {
callback.onError(null, e);
}
}
}
Does anyone know what's wrong here?
> > > > > - If I try it inhostedmodewith "onModuleLoad()" method and so on,