Fake GWT Synchronous RPC Call

First of all, I know that making a synchronous call is "wrong" and knows that it is "impossible."

But in a difficult situation (I don’t know how to explain), I need to wait for a response from the server, I use the implementation of the GWT-Platform command for RPC GWT calls.

I was looking for some kind of “hack” for this.

Thanks in advance.

+5
source share
3 answers

, (, , ). GWT JS XMLHttpRequest . GWT , com.google.gwt.xhr.client.XMLHttpRequest. HTTP. JS XMLHttpRequest open. , , . false, .

GWT-RPC , RpcRequestBuilder, XMLHttpRequest, RequestBuilder.

RpcRequestBuilder RequestBuilder ( XMLHttpRequest, ).

RPCRequest GWT-RPC, ServiceDefTarget.

GWT-RPC?

+5

, onSuccess() RPC, " ". , , ? JavaScript , , , .

, , :

    Timer checkRPCResponse = new Timer() {
        @Override
        public void run() {
            if (!serverResponseReceived) {
                this.schedule(100);
            } else {
                proceedWithProgram();
            }
        }
    };
    checkRPCResponse.schedule(100);

, this.schedule(100) , , , 100 . , serverResponseReceived = true onSuccess(). RPC.

+8

GWT XMLHttpRequest.open(), true , , . , :

private static native void fakeXMLHttpRequestOpen() /*-{
   var proxied = $wnd.XMLHttpRequest.prototype.open;

   (function() {
       $wnd.XMLHttpRequest.prototype.open =
           function() {
                arguments[2] = false;
                return proxied.apply(this, [].slice.call(arguments));
            };
        })();
}-*/;

fakeXMLHttpRequestOpen() XMLHttpRequest . :

remoteSvc.getResult(new AsyncCallback<String>() {
    @Override
    public void onSuccess(String result) {
        GWT.log("Service called!");
    }

    @Override
    public void onFailure(Throwable caught) {
        GWT.log("Service failed...");
    }
}

GWT.log("Last message");

:

Service called!
Last message

See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open for the XMLHttpRequest.open () specification.

0
source

All Articles