sách gpt4 ai đã đi

Làm thế nào để gửi lại yêu cầu RPC GWT nếu nó không thành công (hoặc làm thế nào để tạo yêu cầu RPC liên tục)?

In lại 作者:行者123 更新时间:2023-12-04 13:54:59 38 4
mua khóa gpt4 Nike

如果失败(除 HTTP 200 之外的任何响应代码),我需要重试发送 GWT RPC 请求。原因很复杂,所以我不会详细说明。到目前为止,我在同一个地方处理所有请求响应,如下所示:

    // We override the RpcRequestBuilder.doSetCallback method and force your service to use it
// With this we can read the response headers if we need to.
((ServiceDefTarget)serviceRPC).setRpcRequestBuilder(new RpcRequestBuilder() {

@Ghi đè
protected void doSetCallback(RequestBuilder rb, final RequestCallback callback) {
super.doSetCallback(rb, new RequestCallback() {

@Ghi đè
public void onResponseReceived(Request request,
Response response) {
httpResponseOkHandler(callback, request, response);
}

@Ghi đè
public void onError(Request request, Throwable exception) {
httpResponseErrorHandler(callback, request, exception);
}
});
}
});

因此,使用 httpResponseOkHandler 方法,我可以捕获 HTTP 故障。但是,有没有办法“重新抛出”请求,即再试一次?我不想存储 RPC 请求的高级参数,我更愿意使用已经流式传输并准备重新发送的请求内容。

有任何想法吗?

1 Câu trả lời

嗯,自己找到了答案。所以它毕竟很整洁。在负载重的医院环境中工作,网络往往不可靠。所以这就是为什么我需要在放弃之前重新发送 rpc 请求几次。这是解决方案:

1- 设置您的特殊请求构建器以捕获所有请求响应,但保留请求构建器。

    ((ServiceDefTarget)serviceRPC).setRpcRequestBuilder(new RpcRequestBuilder() {

@Ghi đè
protected void doSetCallback(RequestBuilder rb, final RequestCallback callback) {
final RequestBuilder requestBuilder = rb;
super.doSetCallback(rb, new RequestCallback() {

@Ghi đè
public void onResponseReceived(Request request,
Response response) {
httpResponseOkHandler(requestBuilder, callback, request, response);
}

@Ghi đè
public void onError(Request request, Throwable exception) {
httpResponseErrorHandler(requestBuilder, callback, request, exception);
}
});
}
});

2- 现在使用请求构建器根据需要多次发送请求。一件很棒的事情是请求构建器已经设置并且数据被序列化,这避免了必须存储 POJO 未序列化的数据。
    // We had some server HTTP error response (we only expect code 200 from server when using RPC)
if (response.getStatusCode() != Response.SC_OK) {
Integer requestTry = requestValidation.get(requestBuilder.getRequestData());
if (requestTry == null) {
requestValidation.put(requestBuilder.getRequestData(), 1);
sendRequest(requestBuilder, callback, request);
}
else if (requestTry < MAX_RESEND_RETRY) {
requestTry += 1;
requestValidation.put(requestBuilder.getRequestData(), requestTry);
sendRequest(requestBuilder, callback, request);
} khác {
InvocationException iex = new InvocationException("Unable to initiate the asynchronous service invocation -- check the network connection", null);
callback.onError(request, iex);
}
} khác {
callback.onResponseReceived(request, response);
}

这对我来说很好用,请自行承担风险!

关于gwt - 如果失败,如何重新发送 GWT RPC 请求(或如何创建持久的 RPC 请求)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11056324/

38 4 0
Bài viết được đề xuất: winapi - FS在Win32中注册
Bài viết được đề xuất: sql - 如何在 T-SQL 中的位字段上创建三元条件
Bài viết được đề xuất: file - Erlang 从文件中读取前 5 行
Bài viết được đề xuất: ado.net - 如何在传递给 DataTable Select() 的字符串中包含撇号?
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com