如果失败(除 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() {
@Override
protected void doSetCallback(RequestBuilder rb, final RequestCallback callback) {
super.doSetCallback(rb, new RequestCallback() {
@Override
public void onResponseReceived(Request request,
Response response) {
httpResponseOkHandler(callback, request, response);
}
@Override
public void onError(Request request, Throwable exception) {
httpResponseErrorHandler(callback, request, exception);
}
});
}
});
因此,使用httpResponseOkHandler方法,我可以捕获 HTTP 故障。但是,有没有办法“重新抛出”请求,即再试一次?我不想存储 RPC 请求的高级参数,我更愿意使用已经流式传输并准备重新发送的请求内容。
有任何想法吗?