NARU
NARU

Reputation: 2829

RequestBuilder returns empty response

I am using RequestBuilder on the front end of GWT to send a HTTP GET request to a Restlet Web Service. However, the request can get into the web service and the web service return a String (in the format of JSON). The problem is no response is returned when I monitor the process through fireBug. Anybody knows why?

Here is the code:

String url = "http://localhost:8080/Books";

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);

try {
  builder.sendRequest(null, new RequestCallback() {

    public void onError(Request request, Throwable exception) 
    {
      exception.printStackTrace();

      Window.alert("fail - " + exception.getMessage());
    }

    public void onResponseReceived(Request request, Response response) 
    {

      Window.alert("success - " + response.getText());
    }
  });
} catch (RequestException e) 
{
  e.printStackTrace();
}

response.getText() always return empty.

Thanks in advance!

Ike

Upvotes: 3

Views: 3442

Answers (2)

Irfy
Irfy

Reputation: 9587

Your problem is the Same Origin Policy. The protocol, domain and port in all your requests must be the same as those where your GWT app is being served. If you're serving in Eclipse at port 8888 and your custom server is at port 8080, this won't be trivial.

Try configuring an apache server to proxy e.g. requests to http://localhost/gwt-app.html to http://localhost:8888/gwt-app.html and everything else to your server at http://localhost:8080/*

Upvotes: 0

koma
koma

Reputation: 6566

Do you do your call to a Restlet server on the same host and port that served the webpage that makes the request ?

I am guessing you are running into http://en.wikipedia.org/wiki/Same_origin_policy

Upvotes: 2

Related Questions