During GWT debugging, if you are making a RequestBuilder on a different domain without using JSONP, you may have this problem.
To fix it you must configure Header in order to accept requests from other domains. In Apache HTTP Server you can set them in the VirtualHost configuration of bar.com using the directive Header set.
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "X-Requested-With"
Or better filtering by your origin – see also https://developer.mozilla.org/En/HTTP_access_control#Access-Control-Allow-Origin
Header set Access-Control-Allow-Origin "http://foo.com"
Header set Access-Control-Allow-Headers "X-Requested-With"
In GWT 2.x you can do a JSON-P request for CORS using JsonpRequestBuilder. That’s is really useful! But if you have a service that don’t support JSON-P or you want to use JSON with Access-Control-Allow-Origin header for CORS you have to use JSNI eval in GWT.
public void getJson(String url, final AsyncCallback asyncCallback) {
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
try {
builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
asyncCallback.onFailure(exception);
}
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
String json = response.getText();
asyncCallback.onSuccess(evalJson(json));
} else {
asyncCallback.onFailure(new Throwable());
}
}
});
} catch (RequestException e) {
}
}
private final native MyJson evalJson(String json) /*-{
return eval(json);
}-*/;
throws an exception
com.google.gwt.core.client.JavaScriptException: (SyntaxError): Unexpected token :
arguments: :
type: unexpected_token
stack: SyntaxError: Unexpected token :
at eval (native)
to solve this issue simply assign a variable to your json string into the eval
private final native MyJson evalJson(String json) /*-{
eval('var res = ' + json);
return res;
}-*/;
that’s it
GWT is a very useful programming framework but sometime it’s very difficult to find out how to solve some problems.
One of the is related to GWT-RPC Serialization. GWT-RPC is the canonical way to make AJAX call from GWT Client to GWT Server passing Serializable beans (more details on GWT web site - http://code.google.com/webtoolkit/doc/latest/tutorial/RPC.html).
To pass a bean you have to fulfill the following requirements (from GWT site):
Even if you fulfill these requirements may happen that GWT compiler say:
<class name> was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = <class instance>@<id>
The problem may have different causes. Here his a complete check list to use for solving the problem:
I hope that this help. Please let me know if I miss some check or I wrote something no more valid. This check list is updated for GWT 2.2.

I’m working on Open Source project gwt-spring-jpa-lucene. The aim is to explain with concrete examples how to create a GWT project that manages more than one databases at the same time using Spring and JPA.
Actually I’ve posted the source code and the Wiki page for the main configuration.
Please have a look! If you need help don’t hesitate to contact me!
Recent Comments