GWT: add-linker (cross-site) doens't work with Server code!

1.1k Views Asked by At

I am trying to do some cross-site in GWT.

According to GWT:Same Origin Policy I've added to the module xml file.

It is working okey as long as I am not calling any GWT remote service (using GWT-RPC), but when I try to call any remote service, I got no response!

Any one know how to fix cross-site issue in GWT with GWT remote services?

Thanks in advance!

2

There are 2 best solutions below

0
On

If you want to access some other server (example.com) from your GWT app, then you'll have to do an RPC to your server, and in your server-side code, you'll have to make another HTTP call to the example.com page you're looking for.

The page you linked to regarding cross-site linking outlines that adding <add-linker name="xs"/> to the module file allows you to split your hosting between 2 servers:

  • One server for static files (all GWT produced html and js files, and all images)
  • One server for dynamic calls (all your RPCs go here, and your index.html home page must be here)
0
On

Steve's answer is correct, however there is one other option you can consider which is the best approach if you want to require authentication for server interaction without using OAUTH. The main point is that the cross-site linker doesn't bypass the SOP, but allows you to host the index.html on a different site than the JS code so that you can have the JS code and servlets on one server and load them from another. To get around the SOP you can use a method called JSON with padding or JSONP. Essentially what it does is use a script tag to inject a foreign request into the environment by wrapping the requested data in a callback. To do this you can use one of many server-side implementations such as Jersey. GWT 2 includes a JsonpRequestBuilder object which does all the client-side work for you and can be used in the same way as RequestBuilder. See this article for a tutorial.