假一GWT同步RPC调用 [英] Fake a GWT Synchronous RPC call

查看:298
本文介绍了假一GWT同步RPC调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我知道做一个同步调用是错误的,知道是不可能的。

First of all, I know that doing a synchronous call is "wrong", and know that "is not possible".

不过,在这种情况很多复杂的(我不知道该怎么解释),我需要用我'GWT的平台命令实现GWT的RPC调用等待来自服务器的响应。

But, in a situation a lot complex (i dont know how to explain), i need to wait the response from server, I'am using the GWT-Platform command implementation for the GWT RPC calls.

我一直在寻找某种形式的黑客的事情了。

I was looking for some kind of "hack" for doing this.

在此先感谢。

推荐答案

有一个解决方案,但它是不容易的(例如,你不能翻转一个单一的参数,使其工作)。 GWT使用的是引擎盖下正常JS XMLHtt prequest。在GWT有它叫做com.google.gwt.xhr.client.XMLHtt prequest覆盖类型。这个类是用来发送请求到服务器通过HTTP。各JS XMLHtt prequest是通过调用方法打开第一初始化。这种方法有几个参数,但是第三参数指定该请求是否应该是异步的。如果将其更改为false,请求将是同步的。

There is a solution but it is not easy (e.g. you cannot flip a single parameter to make it work). GWT is using normal JS XMLHttpRequest under the hood. In GWT there is an overlay type for it called com.google.gwt.xhr.client.XMLHttpRequest. This class is used to send requests to the server over HTTP. Each JS XMLHttpRequest is first initialized by calling method open. This method has few parameters, but the third parameter specifies if the request should be asynchronous. If you change it to false, request will be synchronous.

不过,GWT-RPC不直接使用这个类,它使用它通过RpcRequestBuilder,该类不使用XMLHtt prequest直接为好,它是使用RequestBuilder。

But GWT-RPC doesn't use this class directly, it using it via RpcRequestBuilder, and this class is not using XMLHttpRequest directly as well, it is using RequestBuilder.

那么,你需要做的是创造RpcRequestBuilder和RequestBuilder(将使用XMLHtt prequest初始化为同步)的定制版本。

So what you'll need to do is to create customized version of RpcRequestBuilder and RequestBuilder (which will use XMLHttpRequest initialized to be synchronous).

在你可以设置RPCRequest建设者为您的GWT-RPC服务实例,通过它铸造了ServiceDefTarget。

The you can set RPCRequest builder to your GWT-RPC service instance, by casting it to the ServiceDefTarget.

你还希望有同步GWT-RPC请求?

Do you still want to have synchronous GWT-RPC requests?

这篇关于假一GWT同步RPC调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆