1

I have a doGet(String url, final AsyncCallback callback) method for retrieving a JSON from a server with REST function, but i don't know how to call it in the onModuleLoad(). The code is:

public void doGet(String url, final AsyncCallback<JavaScriptObject> callback) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);

    try {
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable caught) {
                callback.onFailure(caught);
            }
            public void onResponseReceived(Request request, Response response) {
                if(response.getStatusCode() == STATUS_CODE_OK) {
                    try {
                        callback.onSuccess(JsonUtils.safeEval(response.getText()));
                    } catch(IllegalArgumentException iax) {
                        callback.onFailure(iax);
                    }
                }
                else {
                    callback.onFailure(new Exception("Bad return code..."));
                }
            }
        });
    } catch(RequestException e) {
        callback.onFailure(e);
    }
}

I know this is a stupid question (I'm a beginner) but how can i call doGet? For example:

doGet("http://192.168.1.10:8080/ProvaRpi/raspberry/sample/artisti", what here?);

I need the AsyncCallback because i want to show the JSON from the database in another page or in a TextBox. Every code improvement is welcome! Thank you!

NicolaT
  • 11
  • 3
  • Here the detail answer for all your questions :) http://stackoverflow.com/questions/15717089/how-to-make-an-gwt-server-callgwt-rpc/15717130#15717130 – Suresh Atta Aug 06 '15 at 10:03
  • So I need to create several class :( There is no "easy and rapid method" to do a connection between a server and a client with GUI right? – NicolaT Aug 06 '15 at 13:29

1 Answers1

0

You can make the call like this:

doGet("your url", new AsyncCallback<JavaScriptObject>() {

    @Override
    public void onSuccess(JavaScriptObject result) {
        // process the result
    }

    @Override
    public void onFailure(Throwable caught) {
        // process when error
    }
});
Philippe Gonday
  • 1,747
  • 5
  • 21
  • 32