拦截 GWT RequestFactory 请求

发布于 2024-12-07 12:12:21 字数 249 浏览 0 评论 0原文

有没有办法在客户端拦截RequestFactory请求?

我想拦截这样的调用:

dummyRequest.dummyOperation().fire( new Receiver<String>() {
  @Override
  public void onSuccess(String response) {        
  }
});

这个想法是在与服务器通信时显示一些加载指示。

Is there a way to intercept RequestFactory requests on client side?

I want to intercept calls like this:

dummyRequest.dummyOperation().fire( new Receiver<String>() {
  @Override
  public void onSuccess(String response) {        
  }
});

The idea is to show some loading indication when communicating with server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听,心雨的声音 2024-12-14 12:12:21

您可以覆盖默认的传输实现并在 RF 初始化期间传递它:

SampleRequestFactory factory = GWT.create( SampleRequestFactory.class );
factory.initialize( new SimpleEventBus(), new DefaultRequestTransport() );

您可以继承 DefaultRequestTransport 并覆盖该方法

send(String payload, TransportReceiver receiver)

在调用超级实现之前进行一些处理并使用委托包装 TransportReceiver 来处理结果。

You can override the default transport implementation and pass it during RF initialization:

SampleRequestFactory factory = GWT.create( SampleRequestFactory.class );
factory.initialize( new SimpleEventBus(), new DefaultRequestTransport() );

You can inherit from DefaultRequestTransport and override the method

send(String payload, TransportReceiver receiver)

Do some processing before calling the super-implementation and wrap the TransportReceiver with a delegate to handle the result.

☆獨立☆ 2024-12-14 12:12:21
final DefaultRequestTransport requestTransport = new DefaultRequestTransport() {
        @Override
        public void send(final String payload, final TransportReceiver receiver) {
            GWT.log("making rpc");
            final TransportReceiver proxy = new TransportReceiver() {
                @Override
                public void onTransportFailure(final ServerFailure failure) {
                    GWT.log("rpc returned");
                    receiver.onTransportFailure(failure);
                }

                @Override
                public void onTransportSuccess(final String payload) {
                    GWT.log("rpc returned");
                    receiver.onTransportSuccess(payload);
                }
            };

            super.send(payload, proxy);

}
final DefaultRequestTransport requestTransport = new DefaultRequestTransport() {
        @Override
        public void send(final String payload, final TransportReceiver receiver) {
            GWT.log("making rpc");
            final TransportReceiver proxy = new TransportReceiver() {
                @Override
                public void onTransportFailure(final ServerFailure failure) {
                    GWT.log("rpc returned");
                    receiver.onTransportFailure(failure);
                }

                @Override
                public void onTransportSuccess(final String payload) {
                    GWT.log("rpc returned");
                    receiver.onTransportSuccess(payload);
                }
            };

            super.send(payload, proxy);

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文