Reputation: 101
Is it possible perform cross domain requests in the GWT version of Restlet Client?
I need to consume Rest resources (GET, POST, PUT, DELETE) from an external API with JSON Data.
I know about Same Origin Policy (SOP) of GWT, but maybe a workaround exists for this restriction...
Restlet documentation with GWT examples is no longer available. This links for example:
http://wiki.restlet.org/docs_2.1/13-restlet/27-restlet/46-restlet/112-restlet.html
http://wiki.restlet.org/docs_2.1/13-restlet/275-restlet/144-restlet/189-restlet.html
Upvotes: 0
Views: 2518
Reputation: 9741
I have never used Restlet
, but it seems that it relays in GWT RequestBuilder
. In consequence, since RequestBuilder
supports CORS, gwt-restlet should do.
You can use any GWT ajax technique (RPC, RF or RequestBuilder) with CORS without problem. Think that GWT have the same restrictions of any other html/javascript application, and CORS will work if the browser is compatible with CORS (IE9 is not) and the server is correctly configured.
Said that, I encourage you to give a try to gwtquery which gives you an easy way to deal with ajax. Normally, I use gwtquery ajax to consume 3party services because of its syntax and simplicity.
The goal of gQuery syntax is that you can take almost jQuery examples and port them to without so much effort.
This is a simple example:
ajax(Ajax.createSettings()
.setUrl("miservice.php")
.setDataType("json") // txt, json, jsonp, xml
.setType("get") // post, get
.setData($$("param1: 1, param2: 2")) // parameters in json, $$() creates json from string
.setSuccess(new Function(){ // callback to be run if the request succeeds
public void f() {
// The response when dataType=json is a javascript object (Properties)
Properties json = getDataProperties();
}
})
);
In the case of JSON (or XML) I use gQuery databinding to map the response with java objects.
For instance:
interface Site extends JsonBuilder {
long getId();
String getUrl();
Site setId(long id);
Site setUrl(String url);
}
...
Site site = GWT.create(Site.class);
site.load(getDataProperties();
Window.alert(site.getUrl();
...
Upvotes: 0
Reputation: 121998
If you need to call services on another domain ,using the standard GWT RequestBuilder.
Refer for example :GWT RequestBuilder - Cross Site Requests.
Still you want to use RestyGwt. here is the Example
And have a look on JsonpRequestBuilder
Upvotes: 1