伪造 GWT 同步 RPC 调用 [英] Fake a GWT Synchronous RPC call

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

问题描述

首先,我知道做同步调用是错误的",也知道不可能".

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

但是,在非常复杂的情况下(我不知道如何解释),我需要等待来自服务器的响应,我正在使用 GWT-Platform 命令实现来进行 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 XMLHttpRequest.在 GWT 中有一个覆盖类型,称为 com.google.gwt.xhr.client.XMLHttpRequest.此类用于通过 HTTP 向服务器发送请求.每个 JS XMLHttpRequest 首先通过调用 open 方法进行初始化.这个方法的参数很少,但第三个参数指定请求是否应该是异步的.如果您将其更改为 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 使用它,而且这个类也不是直接使用 XMLHttpRequest,它使用 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 的自定义版本(它们将使用初始化为同步的 XMLHttpRequest).

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天全站免登陆