3

Assume that I've following GWT service:

@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
    String greetServer(String name) throws IllegalArgumentException;
}

I build & deploy client code on myserver1.com, but my servlets are located on myserver2.com (eg. http://myserver2.com/gwt-module-base/greet) & server1 allows cross domain resource sharing for server2.
Now, here is the question: How can I send gwt-rpc calls for greet service to myserver2.com instead of myserver1.com ?

Ehsan Khodarahmi
  • 4,772
  • 10
  • 60
  • 87

1 Answers1

2

The only thing you need is to enable CORS in myserver2.com. I wrote a filter sometime ago for the gwtquery documentation. It works for RPC and RF as well.

https://code.google.com/p/gwtquery/wiki/Ajax#CORS_(Cross_Origin_Resource_Sharing)

[EDITED]

You have to configure your service transport in this way:

GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
((ServiceDefTarget)greetingService).setServiceEntryPoint("myserver2.com/greet");
greetingService.greetServer(....)
Manolo Carrasco Moñino
  • 9,723
  • 1
  • 22
  • 27
  • 2
    I think you misunderstood my question, I mean how can I tell GWT to send request to server2 instead of server1. Anyway, I found the solution! it can be done when creating proxy object: `GreetingServiceAsync proxy = GWT.create(GreetingService.class); ((ServiceDefTarget)proxy).setServiceEntryPoint("http://myserver2.com/gwt-module-base/greet");` – Ehsan Khodarahmi Apr 13 '14 at 04:24
  • In setServiceEntryPoint argument, use GWT.getHostPageBaseURL() as your server url prefix, e.g., GWT.getHostPageBaseURL() + "gwt-module-‌​base/greet". – Patrick Apr 14 '14 at 05:47
  • 1
    Thank you for the CORSFilter implementation! Works great! – robert Dec 09 '14 at 13:59