gwtgwt-rpcsame-origin-policy

Calling remote Servlet from GWT


I am trying to call remote servlet from GWT, actually the GWT-RPC doesn't seems to work, so I am trying to do it using the RequestBuilder.

Here's the code snippet:

    String url = "http://some-remote-host:8888/GWTJSTest/SomeServlet?name=" + textBox.getText();
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
//              requestBuilder.setHeader("Origin", "*");
//              requestBuilder.setHeader("Access-Control-Allow-Origin", "*");
    try
    {
        requestBuilder.sendRequest(null, new RequestCallback()
        {
            public void onResponseReceived(Request request, Response response)
            {
                if (response.getStatusCode() == 200)
                {
                    Window.alert(response.getText());
                }else
                {
                    Window.alert(response.getText() + " : " + response.getStatusCode() + response.getStatusText());
                }
            }

            public void onError(Request arg0, Throwable arg1)
            {
                Window.alert(arg1.toString());

            }
        });
    } catch (RequestException e)
    {
        Window.alert("CATCH BLOCK: " + e.getMessage());
        e.printStackTrace();
    }

Actually, IE8 returns the data but after a warning message, but Firefox doesn't! Why is this?

As you see, I am trying to set some request headers but no way.


Solution

  • I've added : <add-linker name="xs" /> to .gwt.xml

    And then replaces GWT-PRC by JsonpRequestBuilder (transforming JSONP between the server and the client)