Access remote service using GWTP Rest Dispatch

200 views
Skip to first unread message

Arpit Tripathi

unread,
Dec 29, 2014, 2:11:56 PM12/29/14
to gwt-pl...@googlegroups.com
I want to separate packages for UI and backend development of my GWTP app. 
Currently my UI access the backend using Rest dispatch configured like this: 
bindConstant().annotatedWith(RestApplicationPath.class).to("/MyProject/api");
I want to access remote service using localhost UI (running GWT app using eclipse plugin). I changed the above line to:
bindConstant().annotatedWith(RestApplicationPath.class).to("http://my-app.appspot.com/MyProject/api");
Using this, call successfully reaches server ( I can see this in appengine logs) but UI  always gets back status code 0.

What is wrong with above setup? Do I have to do something else to access remote service using GWT ui ?

Thanks.

Arpit Tripathi

unread,
Dec 29, 2014, 2:14:52 PM12/29/14
to gwt-pl...@googlegroups.com

Richard Wallis

unread,
Dec 30, 2014, 12:56:05 AM12/30/14
to gwt-pl...@googlegroups.com
To make a request from a different domain you need to set CORS headers:

https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

--
You received this message because you are subscribed to the Google Groups "GWTP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gwt-platform...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Arpit Tripathi

unread,
Dec 30, 2014, 6:25:40 PM12/30/14
to gwt-pl...@googlegroups.com
Thanks Richard.

I added CORS filter in my Jersey app using following CORS filter:

 headers.add("Access-Control-Allow-Origin", "*");
 headers
.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
 headers
.add("Access-Control-Allow-Headers", "X-Requested-With,content-type,x-gwt-module-base");


Using this, I can login to remote server, and I can see that remote data is fetched (profile photo of user is updated and remote credentials are accepted). However, any other operation is still considered un-authorized on server. So this is not a GWTP issue anymore but what can I do to make it work?

Thanks again for helping out.

Arpit Tripathi

unread,
Dec 30, 2014, 6:34:15 PM12/30/14
to gwt-pl...@googlegroups.com
To clarify further, OPTIONS request (pre-flight) gets back 'unauthorized' message while actual request gets back status code 0.

Richard Wallis

unread,
Dec 31, 2014, 2:13:54 AM12/31/14
to gwt-pl...@googlegroups.com
I haven't yet switched over to REST-dispatch in my own projects so I don't know how to set it up.   Hopefully someone else can help you out.
Reply all
Reply to author
Forward
0 new messages